#!/bin/bash # Directory prefix=@prefix@ datarootdir=@datarootdir@ datadir=@datadir@ # Enable NLS export TEXTDOMAIN=update-from-skel export TEXTDOMAINDIR=@localedir@ . gettext.sh # output when differential is detected. detect_different() { echo echo "`eval_gettext "==================="`" echo "`eval_gettext "Detect differential"`" echo "`eval_gettext "==================="`" } # process different files. proc_different() { COLUMNS=$(tput cols) HALFCOL=$(expr $COLUMNS / 2 - 2) detect_different ok=0 while [ $ok -eq 0 ] do printf "%-${HALFCOL}s%-${HALFCOL}s\n" ${myfile} ${skel} echo diff --side-by-side -W ${COLUMNS} $myfile $skel # menu echo "`eval_gettext "C) use Current file"`" echo "`eval_gettext "T) use Template file"`" echo "`eval_gettext "E) Edit on diff mode of vim"`" echo "`eval_gettext "I) merge Intaractively by sdiff"`" echo "`eval_gettext "Q) Quit"`" echo -n "`eval_gettext "What do you do? > "`" read command case "$command" in c|C) ok=1 ;; t|T) echo "`eval_gettext "copy \\\$skel to \\\$myfile"`" cp -i $skel $myfile diff -q $skel $myfile >/dev/null 2>&1 if [ $? -eq 0 ]; then ok=1 fi ;; e|E) vim +r$myfile -d $myfile.new $skel if [ -e $myfile.new ];then mv $myfile.new $myfile fi diff -q $skel $myfile >/dev/null 2>&1 if [ $? -eq 0 ]; then ok=1 fi ;; i|I) sdiff -o $myfile.new -w ${COLUMNS} $myfile $skel mv $myfile.new $myfile ok=1 ;; q|Q) exit ;; *) echo "`eval_gettext "You inputed wrong character."`" echo ;; esac done echo } # process no exists file proc_no_exists() { detect_different echo "`eval_gettext "\\\$skel is exists, but \\\$myfile isn't exists."`" echo ok=0 while [ $ok -eq 0 ] do echo "`eval_gettext "C) Copy \\\$skel to \\\$myfile"`" echo "`eval_gettext "N) Nothing to do"`" echo "`eval_gettext "Q) Quit"`" echo -n "`eval_gettext "What do you do? > "`" read command case "$command" in c|C) mkdir -p `dirname $myfile` cp $skel $myfile ok=1 ;; n|N) ok=1 ;; q|Q) exit ;; *) echo "`eval_gettext "You inputed wrong character."`" echo ;; esac done } # process unexpected directory proc_dir() { detect_different echo "`eval_gettext "\\\$skel is file, but \\\$myfile is directory."`" echo ok=0 while [ $ok -eq 0 ] do echo "`eval_gettext "R) Remove directory (\\\$myfile) and copy \\\$skel to \\\$myfile"`" echo "`eval_gettext "L) List contents of \\\$myfile"`" echo "`eval_gettext "N) Nothing to do"`" echo "`eval_gettext "Q) Quit"`" echo -n "`eval_gettext "What do you do? > "`" read command case "$command" in r|R) rm -rf $myfile cp $skel $myfile ok=1 ;; l|L) ls $myfile ;; n|N) ok=1 ;; q|Q) exit ;; *) echo "`eval_gettext "You inputed wrong character."`" echo ;; esac done } # main loop for skel in `find /etc/skel -type f 2>/dev/null` do myfile=`echo $skel | sed -e "s|/etc/skel|$HOME|"` if [ -e $myfile -a -f $myfile ];then diff -q $myfile $skel >/dev/null 2>&1 case $? in 0) echo "`eval_gettext "There is no different beetween \\\$myfile and \\\$skel ."`" ;; 1) proc_different ;; 2) echo "`eval_gettext "Unknown error was occured when compare beetween \\\$myfile and \\\$skel ."`" ;; esac elif [ -d $myfile ]; then proc_dir else proc_no_exists fi done