rc.shutdown-UNIPUP 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/bin/sh
  2. #(c) Copyright bkauler 2008, puppylinux.com
  3. #2008 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  4. #v404 written from scratch for UniPup.
  5. #v411 run rc.alsa as it also unloads modules (if not done, prevents shutdown some systems).
  6. #v412 /etc/DISTRO_SPECS, renamed pup_xxx.sfs, pup_save.2fs etc.
  7. #v555 pup files renamed to woofr555.sfs, woofsave.tar.gz, woofu555.sfs.
  8. #w468 alsa shutdown now handled in /etc/init.d/alsa.
  9. . /etc/rc.d/PUPSTATE #created by rc.sysinit.
  10. . /etc/DISTRO_SPECS
  11. #PUPPYVERSION=`cat /etc/puppyversion`
  12. killzombies() {
  13. ZOMBIES="`ps -H -A | grep '<defunct>' | sed -e 's/ /|/g' | grep -v '|||' | cut -f 1 -d ' ' | tr '\n' ' '`"
  14. for ONEZOMBIE in $ZOMBIES
  15. do
  16. echo "Killing parentless zombie process $ONEZOMBIE"
  17. kill $ONEZOMBIE
  18. done
  19. }
  20. #some packages have a service script that requires stopping...
  21. for service_script in /etc/init.d/*
  22. do
  23. [ -x $service_script ] && $service_script stop
  24. done
  25. #unmount stray filesystems...
  26. USRPART=""
  27. [ "$USRSFS" ] && USRPART="/dev/`echo -n "$USRSFS" | cut -f 1 -d ','`"
  28. for ONESTRAY in `mount | grep -o '^/dev/[a-zA-Z0-9]*' | grep -v '/dev/loop[01]'`
  29. do
  30. [ "$USRPART" = "$ONESTRAY" ] && continue
  31. echo "Unmounting $ONESTRAY..."
  32. fuser -k -m $ONESTRAY
  33. killzombies
  34. sync
  35. umount -r $ONESTRAY
  36. done
  37. #save session...
  38. #add more files to exclusion list...
  39. echo '/etc/rc.d/rc.sysinit
  40. /sbin/pup_event_backend_d
  41. /sbin/pup_event_load_module' >> /tmp/init_startup_files
  42. #echo '/root/.thumbnails' >> /tmp/init_startup_files
  43. if [ "$PUPSAVE" ];then #see /etc/rc.d/PUPSTATE
  44. UNIPART="`echo -n "$PUPSAVE" | cut -f 1 -d ','`"
  45. UNIFS="`echo -n "$PUPSAVE" | cut -f 2 -d ','`"
  46. UNIPUP="`echo -n "$PUPSAVE" | cut -f 3 -d ','`"
  47. STATUS=0
  48. aPATTERN="/dev/${UNIPART} "
  49. if [ "`mount | grep "$aPATTERN"`" = "" ];then
  50. mount -t $UNIFS /dev/$UNIPART /mnt/$UNIPART
  51. STATUS=$?
  52. fi
  53. if [ $STATUS -eq 0 ];then
  54. echo "Saving session to '${DISTRO_FILE_PREFIX}save.tar.gz' in partition ${UNIPART}..."
  55. #save all except files that are in initrd.gz and ${DISTRO_FILE_PREFIX}uxxx.sfs...
  56. tar -c -z -l -f - -X /tmp/init_startup_files /dev /bin /sbin /etc /root /opt /lib /.mnt/tmpfs1 > /mnt/$UNIPART/${DISTRO_FILE_PREFIX}save.tar.gz
  57. sync
  58. umount /dev/$UNIPART
  59. else
  60. echo "Unable to save session, could not mount /dev/${UNIPART}"
  61. fi
  62. else
  63. echo
  64. echo "Early version of this script! Here are the partitions:"
  65. PROBEPART="`probepart -m | sed -e 's%^/dev/%%' | grep -E 'ext2|ext3|reiserfs|vfat|ntfs'`"
  66. echo "$PROBEPART"
  67. echo
  68. echo "Choose a partition, or press ENTER only not to save session."
  69. echo -n "Type the name of the partition you want to save to (ex: sda1): "
  70. read UNIPART
  71. if [ "$UNIPART" != "" ];then
  72. aPATTERN='^'"$UNIPART"'|'
  73. UNIFOUND="`echo "$PROBEPART" | grep "$aPATTERN"`"
  74. UNIPART="`echo -n "$UNIFOUND" | cut -f 1 -d '|'`"
  75. UNIFS="`echo -n "$UNIFOUND" | cut -f 2 -d '|'`"
  76. UNISIZE="`echo -n "$UNIFOUND" | cut -f 3 -d '|'`"
  77. mkdir -p /mnt/$UNIPART
  78. STATUS=0
  79. aPATTERN="/dev/${UNIPART} "
  80. if [ "`mount | grep "$aPATTERN"`" = "" ];then
  81. mount -t $UNIFS /dev/$UNIPART /mnt/$UNIPART
  82. STATUS=$?
  83. fi
  84. if [ $STATUS -eq 0 ];then
  85. echo "Saving session to '${DISTRO_FILE_PREFIX}save.tar.gz' in partition ${UNIPART}..."
  86. #save all except files that are in initrd.gz (see rc.sysinit) and ${DISTRO_FILE_PREFIX}uxxx.sfs...
  87. #/.mnt/tmpfs1 is top layer in /usr layered f.s. ...
  88. tar -c -z -l -f - -X /tmp/init_startup_files /dev /bin /sbin /etc /root /opt /lib /.mnt/tmpfs1 > /mnt/$UNIPART/${DISTRO_FILE_PREFIX}save.tar.gz
  89. sync
  90. #if ${DISTRO_FILE_PREFIX}uxxx.sfs on cd, copy it to same place as ${DISTRO_FILE_PREFIX}save...
  91. if [ "`echo -n "$USRSFS" | grep 'iso9660'`" != "" ];then
  92. USRPART="`echo -n "$USRSFS" | cut -f 1 -d ','`"
  93. USRFS="`echo -n "$USRSFS" | cut -f 2 -d ','`"
  94. USRNAME="`echo -n "$USRSFS" | cut -f 3 -d ','`"
  95. if [ -f /mnt/${USRPART}${USRNAME} -a ! -f /mnt/${UNIPART}${USRNAME} ];then #precaution, not necessary though.
  96. ###TODO check space###
  97. echo "Copying $USRNAME to $UNIPART so optical drive freed for other uses..."
  98. cp -a /mnt/${USRPART}${USRNAME} /mnt/${UNIPART}/
  99. sync
  100. fi
  101. fi
  102. umount /dev/$UNIPART
  103. fi
  104. fi
  105. fi
  106. #unmount swap partitions...
  107. for ONESTRAY in `cat /proc/swaps | grep '/dev/' | cut -f 1 -d ' '`
  108. do
  109. sync
  110. swapoff $ONESTRAY
  111. done
  112. #busybox umount -ar > /dev/null 2>&1
  113. ###END###