functions4puppy 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #Barry Kauler 2007 www.puppylinux.com
  2. #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  3. #created for v3.01, oct 2007.
  4. #v555 updated with DISTRO_FILE_PREFIX.
  5. #w478 update.
  6. #w482 use xorriso instead of cdrtools/cdrkit if installed,
  7. #w482 variables CDRECORD and MKISOFS are exportedby rc.shutdown and savesessio-dvd.
  8. #w482 replace -pad in cdrecord with padsize=300k.
  9. #100820 relocate /var/local so it will get saved.
  10. #100913 simplified puppy filenames.
  11. #100916 no longer have DISTRO_DEVXSFS in /etc/DISTRO_SPECS.(it was only there briefly)
  12. #120823 rerwin: multisession: screen out /.XLOADED when save.
  13. KERNELVER="`uname -r`" #w478
  14. DEVCONSOLE="/dev/console" #when X not running
  15. PSINFO="`ps`"
  16. [ "`echo "$PSINFO" | grep ' X :0'`" != "" ] && DEVCONSOLE="/dev/tty" #running in rxvt.
  17. #waittrayclosedfunc is used by /etc/rc.d/rc.shutdown and /usr/sbin/savesession-dvd.
  18. #v2.16...
  19. waittrayclosed_func() {
  20. CDDRV="$1"
  21. if [ "`cddetect -d${CDDRV} | grep '^tray open!'`" != "" ];then #v2.22
  22. echo -e "\\033[1;31mThe media tray appears to be open." >$DEVCONSOLE #31=red
  23. echo -en "Please close tray then press ENTER key:\\033[0;39m " >$DEVCONSOLE
  24. read waitaenter
  25. fi
  26. echo -e "\\033[1;34mIF STOPPED LONG TIME AT THIS MSG, MAKE SURE TRAY IS CLOSED THEN PRESS ENTER KEY:\\033[0;39m " >$DEVCONSOLE #34=blue
  27. }
  28. #multisavefunc is used by /etc/rc.d/rc.shutdown and /usr/sbin/savesession-dvd.
  29. #these variables must be preset before calling...
  30. #PUPSAVE=partition,filesystem,/${DISTRO_FILE_PREFIX}save.2fs where 1st 2 are the partition holding the file.
  31. #SAVEPART=filesystem which is same as above filesystem.
  32. #PUPPYVERSION=version example: 301.
  33. multisavefunc() {
  34. #save session to folder on multisession CD/DVD.
  35. [ "$CDRECORD" = "" ] && CDRECORD='cdrecord' #w482 precaution.
  36. [ "$MKISOFS" = "" ] && MKISOFS='mkisofs' #w482 precaution.
  37. export MKISOFS
  38. touch -c /.badfolders #update modifytime, so will get saved. badlist, see init script.
  39. MSPATTERN="/dev/$SAVEPART " #v2.22
  40. if [ "`mount | grep "$MSPATTERN"`" != "" ];then
  41. echo "/dev/$SAVEPART mounted, must unmount it..."
  42. fuser -k -m /dev/$SAVEPART
  43. sync
  44. umount /dev/$SAVEPART 2> /dev/null
  45. fi
  46. CDR="/dev/$SAVEPART"
  47. if [ "`mount | grep "$CDR"`" != "" ];then #v3.01
  48. dialog --msgbox "The drive $CDR could not be unmounted,
  49. so current session cannot be saved to it.
  50. This can happen if PC has insufficient RAM to
  51. copy all files off the CD, or an application
  52. is using the CD and cannot be killed.
  53. Press ENTER key..." 0 0 >$DEVCONSOLE
  54. clear >$DEVCONSOLE
  55. return
  56. fi
  57. ##v3.01 have restored this...
  58. HDRCDR="$CDR" #w482
  59. dialog --yes-label "SAVE" --no-label "NO SAVE" --yesno "Please insert the Puppy live-CD/DVD media that you booted from, into the same CD/DVD drive that you booted from -- this is /dev/$SAVEPART and it must be a burner drive!
  60. Insert CD/DVD media now, then press ENTER key to save session...
  61. Or, press TAB then ENTER to not save session..." 0 0 >$DEVCONSOLE
  62. if [ ! $? -eq 0 ];then
  63. eject $CDR
  64. dialog --msgbox "Have not saved session to live-CD/DVD.
  65. Remove CD/DVD media if you wish.
  66. Do not press close button on drive.
  67. Press ENTER key to close drive tray" 0 0 >$DEVCONSOLE
  68. eject -t $CDR
  69. sleep 1
  70. clear >$DEVCONSOLE
  71. waittrayclosed_func $CDR #v2.16
  72. return
  73. fi
  74. clear >$DEVCONSOLE
  75. if [ "`cddetect -d${CDR} | grep '^no disc!'`" != "" ];then #v2.22
  76. echo -e "\\033[1;31mIt seems that the media is not inserted." >$DEVCONSOLE #31=red
  77. echo -en "Please insert media then press ENTER key:\\033[0;39m " >$DEVCONSOLE
  78. read waitaenter
  79. fi
  80. MEDIATYPE="CD"
  81. waittrayclosed_func $CDR #v2.16
  82. DVDRWMEDIAINFO="`dvd+rw-mediainfo $CDR 2>&1`"
  83. [ "`echo -n "$DVDRWMEDIAINFO" | grep --extended-regexp "non\\-DVD|not a DVD unit|Input/Output error|Input/output error|Invalid argument"`" = "" ] && MEDIATYPE="DVD"
  84. #if new version iso inserted, need to save all files, not just changed/new...
  85. MSPATTERN="$CDR "
  86. DVDMNTPT="`mount | grep "$MSPATTERN" | tr -s " " | cut -f 3 -d " "`" #in case not unmounted.
  87. if [ "$DVDMNTPT" = "" ];then
  88. mkdir -p /tmp/dvdmntpt
  89. mount -t iso9660 $CDR /tmp/dvdmntpt
  90. [ $? -eq 0 ] && DVDMNTPT="/tmp/dvdmntpt"
  91. fi
  92. if [ "$DVDMNTPT" != "" ];then
  93. if [ $ORIGPUPMODE -eq 77 ];then #bypass first boot, PUPMODE=5. v2.22
  94. [ "`find $DVDMNTPT -maxdepth 1 -type d -name 20[0-9][0-9]*`" = "" ] && NEWISO="yes"
  95. fi
  96. umount $CDR 2>/dev/null
  97. fi
  98. #want to copy contents of /initrd/pup_rw to a new folder on /dev/$SAVEPART...
  99. MYDATE="`date "+%Y-%m-%d-%H-%M"`" #this will become the folder name on cd.
  100. SAVEABORT="" #v3.01
  101. while [ 1 ];do #WHILELOOP1
  102. #if have new live-cd, need a 'full save', not just what is in pup_rw. Maybe easiest
  103. #way is to save two tracks, pup_ro1, which has all prior saved folders read from cd
  104. #at bootup, then save latest session, pup_rw...
  105. if [ "$NEWISO" = "yes" ];then
  106. echo "Burning data from previous $MEDIATYPE to first track..." >$DEVCONSOLE
  107. #use last folder name from previous cd, to avoid name conflict with next folder...
  108. FOLDEROLD="`echo -n "$PUPSAVE" | cut -f 2 -d '/'`"
  109. #minimal error checking here, errors reported when save current session (below)...
  110. if [ "$MEDIATYPE" = "CD" ];then
  111. waittrayclosed_func $CDR #v2.16 v3.01 now HDRCDR...
  112. SECT=`$CDRECORD -msinfo dev=${HDRCDR} 2>/tmp/cdrerr.txt | grep '^[0-9]*.[0-9]'` #v3.01
  113. if [ "$SECT" = "" ];then
  114. SAVEABORT="$CDR" #v3.01
  115. break
  116. else
  117. waittrayclosed_func $CDR #v2.16
  118. #v2.02 added -pad ... v3.01 now HDRCDR...
  119. #v2.16 removed -pad from cdrecord as mkisofs has -pad by default... no, leave for now...
  120. $MKISOFS -D -R -C $SECT -M $CDR -quiet -new-dir-mode 0755 -graft-points ${FOLDEROLD}=/initrd/pup_ro1 | $CDRECORD -multi -data -tao -eject -v speed=4 gracetime=2 padsize=300k dev=${HDRCDR} -
  121. fi
  122. else #dvd
  123. waittrayclosed_func $CDR #v2.16
  124. #v2.16 removed '-speed=4' as got 'failed to change write speed' error on one drive...
  125. growisofs -M $CDR -D -R -quiet -new-dir-mode 0755 -graft-points ${FOLDEROLD}=/initrd/pup_ro1 2> /tmp/dvderr.txt
  126. fi
  127. fi
  128. #v2.22 NEWISO=""
  129. #normal session save of new/changed files...
  130. #exclude .sfs files... v3.97 no, allow to save...
  131. REMSFS=""
  132. #tack on this exclude as well... (samba network drives mount here)
  133. [ -d /initrd/pup_rw/root/mnt ] && REMSFS="$REMSFS -x /initrd/pup_rw/root/mnt"
  134. #if a new iso, do not want to save /.badfolders file...
  135. if [ "$NEWISO" = "yes" ];then
  136. [ -f /initrd/pup_rw/.badfolders ] && REMSFS="$REMSFS -x /initrd/pup_rw/.badfolders"
  137. fi
  138. #100820 relocate /var/local so it will get saved (see 'init' script at bootup)...
  139. if [ -d /initrd/pup_rw/var/local ];then
  140. rm -rf /initrd/pup_rw/root/.var_saved #precaution.
  141. mkdir -p /initrd/pup_rw/root/.var_saved
  142. cp -a /initrd/pup_rw/var/local /initrd/pup_rw/root/.var_saved/
  143. fi
  144. if [ "$MEDIATYPE" = "CD" ];then
  145. waittrayclosed_func $CDR #v2.16 v3.01 now HDRCDR...
  146. SECT=`$CDRECORD -msinfo dev=${HDRCDR} 2>/tmp/cdrerr.txt | grep '^[0-9]*.[0-9]'`
  147. if [ "$SECT" = "" ];then
  148. SAVEABORT="$CDR" #v3.01
  149. break #v3.01
  150. else
  151. waittrayclosed_func $CDR #v2.16
  152. #TSIZE="`$MKISOFS -print-size -D -R -C $SECT -M $CDR -quiet -new-dir-mode 0755 -graft-points -x /initrd/pup_rw/tmp $REMSFS -x /initrd/pup_rw/proc -x /initrd/pup_rw/sys -x /initrd/pup_rw/var -x /initrd/pup_rw/initrd -x /initrd/pup_rw/mnt ${MYDATE}=/initrd/pup_rw`"
  153. TSIZE="`$MKISOFS -print-size -D -R -C $SECT -M $CDR -quiet -new-dir-mode 0755 -graft-points -x /initrd/pup_rw/tmp $REMSFS -x /initrd/pup_rw/proc -x /initrd/pup_rw/sys -x /initrd/pup_rw/var -x /initrd/pup_rw/initrd -x /initrd/pup_rw/mnt -x /initrd/pup_rw/etc/.XLOADED ${MYDATE}=/initrd/pup_rw`" #120823
  154. #-J Joliet extension disabled, sometimes causes failure...
  155. #v2.02 added -pad ...
  156. waittrayclosed_func $CDR #v2.16 v3.01 now HDRCDR...
  157. #v2.16 removed -pad from cdrecord as mkisofs has -pad by default... no, leave for now...
  158. #$MKISOFS -D -R -C $SECT -M $CDR -quiet -new-dir-mode 0755 -graft-points -x /initrd/pup_rw/tmp $REMSFS -x /initrd/pup_rw/proc -x /initrd/pup_rw/sys -x /initrd/pup_rw/var -x /initrd/pup_rw/initrd -x /initrd/pup_rw/mnt ${MYDATE}=/initrd/pup_rw | $CDRECORD -multi -data -tao -eject -v speed=4 gracetime=2 padsize=300k tsize=${TSIZE}s dev=${HDRCDR} -
  159. $MKISOFS -D -R -C $SECT -M $CDR -quiet -new-dir-mode 0755 -graft-points -x /initrd/pup_rw/tmp $REMSFS -x /initrd/pup_rw/proc -x /initrd/pup_rw/sys -x /initrd/pup_rw/var -x /initrd/pup_rw/initrd -x /initrd/pup_rw/mnt -x /initrd/pup_rw/etc/.XLOADED ${MYDATE}=/initrd/pup_rw | $CDRECORD -multi -data -tao -eject -v speed=4 gracetime=2 padsize=300k tsize=${TSIZE}s dev=${HDRCDR} - #120823
  160. [ $? -eq 0 ] && break
  161. fi
  162. echo "Cannot write to CD" > /tmp/dvderr.txt
  163. else #dvd
  164. waittrayclosed_func $CDR #v2.16
  165. #-J Joliet extension disabled, sometimes causes failure...
  166. #v2.16 removed '-speed=4' as got 'failed to change write speed' error on one drive...
  167. growisofs -M $CDR -D -R -quiet -new-dir-mode 0755 -graft-points -x /initrd/pup_rw/tmp $REMSFS -x /initrd/pup_rw/proc -x /initrd/pup_rw/sys -x /initrd/pup_rw/var -x /initrd/pup_rw/initrd -x /initrd/pup_rw/mnt ${MYDATE}=/initrd/pup_rw 2> /tmp/dvderr.txt
  168. [ $? -eq 0 ] && break
  169. fi
  170. dialog --yes-label "BLANK ${MEDIATYPE}-R" --no-label "UPGRADE ${MEDIATYPE}-R" --yesno "ERROR MESSAGE:
  171. `cat /tmp/dvderr.txt | head -n 1`
  172. It seems to be time to migrate to a new live-${MEDIATYPE}.
  173. You can migrate to a new blank ${MEDIATYPE}-R, or upgrade
  174. to a new Puppy version iso file that has been previously
  175. burnt in multisession mode to a ${MEDIATYPE}-R.
  176. WARNING:
  177. If the PC shuts down without allowing the migration, try
  178. rebooting the current live-$MEDIATYPE and shutdown again.
  179. Have the new media ready, but do not insert it yet.
  180. Just select the appropriate button..." 0 0 >$DEVCONSOLE
  181. if [ $? -eq 0 ];then #new blank cd/dvd.
  182. DVDMNTPT="`mount | grep "$CDR" | tr -s " " | cut -f 3 -d " "`" #in case not unmounted.
  183. if [ "$DVDMNTPT" = "" ];then
  184. mkdir /tmp/dvdmntpt
  185. mount -t iso9660 $CDR /tmp/dvdmntpt
  186. [ ! $? -eq 0 ] && break
  187. DVDMNTPT="/tmp/dvdmntpt"
  188. fi
  189. #get vmlinuz etc off current dvd...
  190. echo "Copying some files off $CDR..." >$DEVCONSOLE
  191. mkdir /tmp/livecd
  192. cp $DVDMNTPT/isolinux.bin /tmp/livecd/
  193. cp $DVDMNTPT/isolinux.cfg /tmp/livecd/
  194. cp $DVDMNTPT/vmlinuz /tmp/livecd/
  195. cp $DVDMNTPT/initrd.gz /tmp/livecd/
  196. cp $DVDMNTPT/boot.msg /tmp/livecd/ 2> /dev/null
  197. cp $DVDMNTPT/goofy.16 /tmp/livecd/ 2> /dev/null
  198. cp $DVDMNTPT/logo.16 /tmp/livecd/ 2> /dev/null #w478
  199. cp $DVDMNTPT/help.msg /tmp/livecd/ 2> /dev/null #w478
  200. #cp $DVDMNTPT/${DISTRO_PUPPYSFS} /tmp/livecd/ 2> /dev/null
  201. cp $DVDMNTPT/${DISTRO_ZDRVSFS} /tmp/livecd/ 2> /dev/null #100913
  202. cp $DVDMNTPT/${DISTRO_ADRVSFS} /tmp/livecd/ 2> /dev/null
  203. cp $DVDMNTPT/${DISTRO_YDRVSFS} /tmp/livecd/ 2> /dev/null
  204. sync
  205. umount $CDR
  206. [ ! $? -eq 0 ] && break
  207. eject $CDR
  208. dialog --msgbox "Take out the old media and write completion date on it.
  209. NOTE: Do not press tray-close button on $MEDIATYPE drive.
  210. Please insert new media in tray then press ENTER key..." 0 0 >$DEVCONSOLE
  211. eject -t $CDR
  212. ##echo "/$PUPSFS" > /tmp/dvdextras.txt
  213. echo -n "/initrd/mnt/tmpfs/" > /tmp/dvdextras.txt #v3.01
  214. [ -f /initrd/mnt/tmpfs/${DISTRO_PUPPYSFS} ] && echo "/initrd/mnt/tmpfs/${DISTRO_PUPPYSFS}" >> /tmp/dvdextras.txt #100913
  215. #ls -1 /initrd/mnt/tmpfs | grep "${DISTRO_FILE_PREFIX}r" >> /tmp/dvdextras.txt
  216. ls -1 /initrd/mnt/tmpfs | grep "${DISTRO_FILE_PREFIX}\-" >> /tmp/dvdextras.txt #100913 superfluous now.
  217. #[ -f /initrd/mnt/tmpfs/${DISTRO_DEVXSFS} ] && echo "/initrd/mnt/tmpfs/${DISTRO_DEVXSFS}" > /tmp/dvdextras.txt #100913
  218. waittrayclosed_func $CDR #v2.16
  219. if [ "$MEDIATYPE" = "DVD" ];then
  220. #v2.16 removed '-speed=4' as got 'failed to change write speed' error on one drive...
  221. growisofs -Z $CDR -R -D -quiet -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -path-list /tmp/dvdextras.txt /tmp/livecd
  222. [ ! $? -eq 0 ] && break
  223. else
  224. #v2.02 added -pad ...
  225. #v2.16 removed -pad from cdrecord as mkisofs has -pad by default... no, leave for now...
  226. $MKISOFS -D -R -quiet -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -path-list /tmp/dvdextras.txt /tmp/livecd | $CDRECORD -multi -tao -data -v speed=4 gracetime=2 padsize=300k dev=$HDRCDR -
  227. [ ! $? -eq 0 ] && break
  228. fi
  229. fi
  230. #have new live-cd, and loops back up to save session, but need a 'full save', not just
  231. #what is in pup_rw. Maybe easiest way is to save two tracks, pup_ro1, which has all prior
  232. #saved folders read from cd at bootup, then save latest session, pup_rw...
  233. NEWISO="yes" #loop back up.
  234. done #end WHILELOOP1
  235. sync
  236. [ "`mount | grep "$CDR"`" != "" ] && STILLMNTD="yes" #v3.01
  237. if [ "$STILLMNTD" = "yes" ];then
  238. CLOSEMSG="Press ENTER key to complete the shutdown..."
  239. else
  240. CLOSEMSG="Remove $MEDIATYPE media if you wish.
  241. Do not press close button on drive.
  242. Press ENTER key to close drive tray
  243. (laptop drive, have to manually close)"
  244. eject $CDR
  245. fi
  246. if [ "$SAVEABORT" = "" ];then #v3.01
  247. dialog --msgbox "Have saved session to live-$MEDIATYPE
  248. (unless it has not, which is an error).
  249. ${CLOSEMSG}" 0 0 >$DEVCONSOLE
  250. else
  251. dialog --msgbox "A problem with the ${MEDIATYPE} drive ${SAVEABORT},
  252. unable to save to save to it. Sorry.
  253. ${CLOSEMSG}" 0 0 >$DEVCONSOLE
  254. fi
  255. [ "$STILLMNTD" != "yes" ] && eject -t $CDR #close tray.
  256. sleep 1
  257. #waittrayclosed_func $CDR #v2.16
  258. } #end multisavefunc
  259. ###END###