Advertisement
quark_zju

update_system_configure.sh

Jun 21st, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.18 KB | None | 0 0
  1. #!/usr/bin/sudo /bin/zsh
  2.  
  3. # Usage:
  4. #   - put system configure files (with path) at $PWD
  5. #     for example, $PWD/etc/mpd.conf ...
  6. #   - run this script
  7.  
  8. autoload colors
  9. colors
  10.  
  11. SELF_BASENAME=`basename $0`
  12.  
  13. for i in `find`; do
  14.   FILE_BASENAME=`basename $i`
  15.   if [[ -f $i ]] && [[ $FILE_BASENAME != $SELF_BASENAME ]] && [[ "$FILE_BASENAME[1]" != "." ]]; then
  16.     printf "$fg[white]$i: "
  17.     if [[ "/$i" -nt $i ]]; then
  18.       # system has newer file
  19.       print "$fg[red]System has newer version"
  20.     else
  21.       # system has older or different file
  22.       if [[ -f /$i ]]; then
  23.         if diff -q "/$i" $i &>/dev/null; then
  24.           # same file
  25.           print "$fg[green]Ok"
  26.         else
  27.           # need update
  28.           printf "$fg[blue]Updating... "
  29.           DEST_MOD=`stat -c %a /$i`
  30.           DEST_GROUP=`stat -c %g /$i`
  31.           DEST_USER=`stat -c %u /$i`
  32.           /bin/install -g $DEST_GROUP -o $DEST_USER -m $DEST_MOD -p -T $i /$i
  33.           print "Done"
  34.         fi
  35.       else
  36.         # need create
  37.         printf "$fg[blue]Creating... "
  38.         SRC_MOD=`stat -c %a $i`
  39.         /bin/install -m $SRC_MOD -p -T $i /$i
  40.         print "Done"
  41.       fi
  42.     fi
  43.   fi
  44. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement