home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / snapmergepuppy < prev    next >
Encoding:
Text File  |  2006-05-12  |  5.3 KB  |  159 lines

  1. #!/bin/sh
  2. #vim:filetype=sh
  3.  
  4. #derived from snapmerge script, in unionfs package
  5. #Barry Kauler www.puppylinux.com
  6. #usage:
  7. # snapmergepuppy /initrd/pup_ro1 /initrd/pup_rw
  8. #pup_rw is the writable tmpfs layer, pup_ro1 is the persistent storage layer.
  9. #thus, this script is saving current session.
  10.  
  11. #this script is called by /usr/sbin/savepuppyd (daemon to prevent tmpfs filling up
  12. # and to flush tmpfs to persistent storage periodically), and by
  13. #/etc/rc.d/rc.shutdown (shutdown script).
  14. #...um, except cannot do an actual "flush" yet.
  15.  
  16. PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin"
  17. #PUPSAVE=vfat,sda1,/pup_save.3fs (location & name of persistent storage file).
  18. SAVEPART="`cat /etc/rc.d/PUPSAVE 2> /dev/null | cut -f 2 -d ','`"
  19.  
  20. BASE=$1
  21.  
  22. shift
  23.  
  24. WD=`pwd`
  25. if [ ! `echo "$BASE" | cut -b1` = "/" ] ; then
  26.     BASE="$WD/$BASE"
  27. fi
  28.  
  29. #BK spaces can break some applications and scripts, including this one...
  30. #echo "Scanning for filenames with spaces (will convert to underscore)..."
  31. #spacereplace -r /initrd/pup_rw
  32. #...no, rethink, cannot modify pup_rw directly.
  33. #sync
  34.  
  35.  
  36. while [ ! -z "$1" ]
  37. do
  38.     SNAP=$1
  39.     if [ ! -d $SNAP ] ; then
  40.         echo "$0: $SNAP not a directory" 1>&2
  41.         exit 1
  42.     fi
  43.  
  44.     cd $SNAP || exit 1
  45.  
  46.     echo "Merging $SNAP onto $BASE."
  47.  
  48.     # Directories
  49. #BK    find . -type d | tail +2 |  sed -e 's/\.\///' |
  50.  #want to avoid anything else mounted on a subdirectory. for example, smbclient can mount network
  51.  #drives on /root/mnt. Instead of putting grep -v 'root/mnt', catch all with -mount ...
  52.     find . -mount -type d | tail +2 |  sed -e 's/\.\///' | grep -v '^mnt' | grep -v '^initrd' | grep -v '^var' | grep -v '^proc' | grep -v '^sys' | grep -v '^tmp' |
  53.     while read N
  54.     do
  55.         mkdir -p "$BASE/$N"
  56.         chmod "$BASE/$N" --reference="$N"
  57.         touch "$BASE/$N" --reference="$N"
  58.     done
  59.  
  60.     # Copy Files
  61.    echo >> /tmp/pupsafesaved.txt
  62.    date >> /tmp/pupsafesaved.txt
  63.    [ ! -f /tmp/pupsafebadlist.txt ] && touch /tmp/pupsafebadlist.txt
  64.  
  65. #BK    find . -not \( -regex '.*/\.wh\.[^/]*' -type f \) -not -type d |  sed -e 's/\.\///' |
  66.  #see note above about -mount ...
  67.     find . -mount -not \( -regex '.*/\.wh\.[^/]*' -type f \) -not -type d |  sed -e 's/\.\///' | grep -v '^mnt' | grep -v '^initrd' | grep -v '^var' | grep -v '^proc' | grep -v '^sys' | grep -v '^tmp' | grep -v '^pup_[0-9][0-9][0-9]\.sfs' | grep -v '\.thumbnails' | grep -vi 'trash'  |
  68.     while read N
  69.     do
  70.  
  71.    if [ "$SAVEPART" = "fd0" ];then
  72.     #not much space, so screen out more files...
  73.     [ ! "`echo -n "$N" | grep -v '^etc' | grep -v '^root'`" = "" ] && continue
  74.     [ "`echo -n "$N" | grep -v 'mozilla' | grep -v 'printjobs' | grep -v 'archive' | grep -v 'cache'`" = "" ] && continue
  75.    fi
  76.  
  77. #   #BK PupSafe security system...
  78. #   #ignore if file same size and modify date as already saved...
  79. #   SRCSTAT="`stat --format=%s,%Y "$N"`"
  80. #   if [ ! "`stat --format=%s,%Y "$BASE/$N" 2>/dev/null`" = "$SRCSTAT" ];then
  81. #    if [ "`cat /tmp/pupsafebadlist.txt | grep "$N"`" = "" ];then
  82. #     SNAPMERGE="ok"
  83. #     #if not a system file, jump down and save it...
  84. #     if [ ! "`echo -n "$N" | grep --extended-regexp '^bin|^sbin|^usr|^lib'`" = "" ];then
  85. #      if [ -f "$BASE/$N" ];then
  86. #       #file already exists in persistent storage.
  87. #       #note, we will allow new files to be created in system areas, without question.
  88. #       if [ ! "`file "$N" | grep --extended-regexp 'executable|shared'`" = "" ];then
  89. #        #query modifying executable|shared system files.
  90. #        if [ "`pidof X | tr "\n" "z"`" = "z" ];then
  91. #         dialog --title "PupSafe security system" --yesno "An attempt is being made to modify system file\n/${N}\nDo you want to allow this?" 0 0
  92. #        else
  93. #         Xdialog --display :0 --title "PupSafe security system" --left --icon "/usr/local/lib/X11/pixmaps/pupsafe80.xpm" --yesno "An attempt has being made to modify system file\n/${N}\nDo you want to allow this?" 0 0
  94. #        fi
  95. #        if [ ! $? -eq 0 ];then
  96. #         SNAPMERGE="bad"
  97. #         echo "$N" >> /tmp/pupsafebadlist.txt
  98. #        fi
  99. #       fi
  100. #      fi
  101. #     fi
  102. #     if [ "$SNAPMERGE" = "ok" ];then
  103. #      cp -a --remove-destination "$N" "$BASE/$N"
  104. #      echo "$N" >> /tmp/pupsafesaved.txt
  105. #     fi
  106. #    fi
  107. #   fi
  108.  
  109. #for now, above removed, just save it...
  110.    cp -a --remove-destination "$N" "$BASE/$N"
  111.  
  112.     done
  113.  
  114.     # Handle Whiteouts
  115.     # adding -mount here also...
  116.     find . -mount \( -regex '.*/\.wh\.[^/]*' -type f \) | sed -e 's/\.\///;s/\.wh\.//' |
  117.     while read N
  118.     do
  119.         rm -rf "$BASE/$N"
  120.     done
  121.  
  122.     cd $WD
  123.     shift
  124. done
  125.  
  126. #BK no, cannot figure out how to flush tmpfs...
  127. ##BK
  128. ##have merged pup_rw back to pup_ro1, however all the dirs and files are still in pup_rw.
  129. ##Probably the proper way to empty pup_rw would be to:
  130. ## 1. unattach pup_rw branch
  131. ##  ...but can only do this if all files in pup_rw are closed.
  132. ## 2. delete everything in pup_rw/
  133. ## 3. reattach pup_rw branch.
  134. ##Or, maybe this nasty way works...
  135. #sync
  136. ##need to be careful not to delete pup_xxx.sfs file...
  137. ##(which got loaded into ramdisk at bootup and must stay there)
  138. #rm -rf /initrd/pup_rw/bin
  139. #rm -rf /initrd/pup_rw/lib
  140. #rm -rf /initrd/pup_rw/root
  141. #rm -rf /initrd/pup_rw/sbin
  142. #rm -rf /initrd/pup_rw/tmp
  143. #rm -rf /initrd/pup_rw/var
  144. #rm -rf /initrd/pup_rw/usr
  145. #rm -rf /initrd/pup_rw/opt
  146. #for ONESFSR in `ls -1 /initrd/*_[0-9][0-9][0-9].sfs | grep -v '/pup_[0-9][0-9][0-9]\.sfs' | tr "\n" " "`
  147. #do
  148. # rm -f $ONESFSR
  149. #done
  150. #sync
  151. #uniondbg -g / #forced revalidation.
  152. ##...no, this hangs Puppy.
  153. sync
  154.  
  155.  
  156. cd $WD
  157.  
  158. exit 0
  159.