Advertisement
quark_zju

update_system_configure.sh

Jun 21st, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.49 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.  
  33.           # install
  34.           /bin/install -g $DEST_GROUP -o $DEST_USER -m $DEST_MOD -p -T $i /$i
  35.           print "Done"
  36.         fi
  37.       else
  38.         # need create
  39.         printf "$fg[blue]Creating... "
  40.         SRC_MOD=`stat -c %a $i`
  41.  
  42.         # check directory and create
  43.         DEST_DIR=`dirname /$i`
  44.         if [[ ! -d $DEST_DIR ]]; then
  45.           printf '(new dir) '
  46.           mkdir -p $DEST_DIR
  47.         fi
  48.  
  49.         if [[ -d $DEST_DIR ]]; then
  50.           /bin/install -m $SRC_MOD -p -T $i /$i
  51.           print "Done"
  52.         else
  53.           print "$fg[red]Failed"
  54.         fi
  55.       fi
  56.     fi
  57.   fi
  58. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement