updateconf (1189B)
1 #!/bin/sh 2 3 EDITOR=${EDITOR:-vi} 4 5 command -v $EDITOR >/dev/null || { 6 echo "Editor '$EDITOR' not exist. Append 'EDITOR=<your editor>' to ${0##*/}." 7 exit 2 8 } 9 10 [ "$(id -u)" = 0 ] || { 11 echo "This operation need root access. Exiting..." 12 exit 1 13 } 14 15 pkgnew=$(find /etc -type f -name "*.new" 2> /dev/null) 16 17 [ "$pkgnew" ] || { 18 echo "Nothing to do. Exiting..." 19 exit 0 20 } 21 22 for file in $pkgnew; do 23 currentfile=${file%.*} 24 if [ ! -e "$currentfile" ]; then 25 echo "Remove '$file', '$currentfile' not exist." 26 rm -f "$file" 27 sleep 0.5 28 continue 29 fi 30 while true; do 31 clear 32 diff -u $currentfile $file #--color=always 33 if [ $? = 0 ]; then 34 echo "Remove '$file', no diff found." 35 rm -f "$file" 36 sleep 1 37 break 38 fi 39 echo 40 echo "File: $currentfile" 41 echo 42 printf "[U]pdate [D]iscard [E]dit [K]eep ?: " 43 read ACTION 44 echo 45 case $ACTION in 46 U|u) echo "Replace '$currentfile' with '$file'." 47 mv -f "$file" "$currentfile" 48 break;; 49 D|d) echo "Remove '$file'." 50 rm -f "$file" 51 break;; 52 E|e) vim "$currentfile";; 53 K|k) echo "Keeping both." 54 break;; 55 esac 56 done 57 sleep 0.5 58 done 59 60 clear 61 62 echo "Done updating package's configuration files." 63 64 exit 0