shutdownconfig 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler sept. 2011 bkhome.org
  3. #2011 GPL licence v3 (/usr/share/doc/legal)
  4. #the idea of this script is that it is called when PUPMODE==5 by scripts
  5. #/usr/bin/wmreboot and /usr/bin/wmpoweroff (which are called via the Shutdown menu).
  6. #X is still running.
  7. #the normal shutdown sequence is:
  8. # /usr/bin/wmpoweroff ->(return to) /usr/bin/xwin -> /sbin/poweroff -> /etc/rc.d/rc.shutdown
  9. # /usr/bin/wmreboot ->(return to) /usr/bin/xwin -> /sbin/reboot -> /etc/rc.d/rc.shutdown
  10. #this script is putting up some GUI dialogs while X is still running, so when
  11. #rc.shutdown is reached, it won't have to put up text-mode dialogs.
  12. #to avoid code duplication, get this to work with and without X, and also call this
  13. #script from rc.shutdown. From the console, no X, type "poweroff" or "reboot" will
  14. #also (conditionally) run this script, via rc.shutdown.
  15. #110924 various tweaks. fix default partition highlight.
  16. #110925 L18L: i18n conversion, please see /usr/share/doc/nls/shutdownconfig. 110926 BK minor tweaks. 110928 missing \\\. 111003 syntax error.
  17. #111012 a pupdialog window had wrong text, needed different from non-X dialog.
  18. #111015 typo.
  19. #111110 need to export CRYPTO in /tmp/shutdownconfig_results, for rc.shutdown.
  20. #120323 replace 'xmessage' with 'pupmessage'.
  21. #120327 only show "*RECOMMENDED*" partition for savefile if >256MB free.
  22. #120327 expBOOTDRV needs to be exported to rc.shutdown.
  23. #120427 01micko: support ext4 in save-file. 120428
  24. #120512 Karl Godt: some parameters missing from lines 626, 630, 642.
  25. #120514 Karl Godt: precaution, save-file must be bigger than size used in ram.
  26. #120823 rerwin: avoid saving personal data if flag set in /etc (by remasterpup2, file /etc/personal_data_save_disabled).
  27. #130128 support udf f.s. (see also sfsget, puppyinstaller, pmount, pup_event_frontend_d, drive_all, probepart).
  28. #130216 support f2fs.
  29. #130221 the 240 sec timeout to shutdown without saving, actually aborts timeout. fixed. see also pupdialog, wmpoweroff, wmreboot.
  30. #130522 remove the "no need to click OK" from final dlg, if X running.
  31. #130525 remove OK button from "copy .sfs from cd" please wait window.
  32. #130525 extend duration of creating save file please wait window.
  33. #130712 fix 130522, 130525 dlgs showing in tray.
  34. #130721 improve some translations.
  35. DEFAULT_SAVE_SIZE=512 #MB
  36. TIMELIMIT=$(echo $TIMELIMIT | tr -dc '0-9')
  37. [ "$TIMELIMIT" ] || TIMELIMIT=60
  38. if [ ! $DISPLAY ];then
  39. export LANG=C #110928 console shutdown using 'dialog', disable i18n.
  40. else
  41. export OUTPUT_CHARSET=UTF-8
  42. fi
  43. . /usr/bin/gettext.sh # enables use of eval_gettext (several named variables) and ngettext (plurals)
  44. export TEXTDOMAIN=shutdownconfig
  45. T_title="$(gettext 'First shutdown: save session')" # used 8 times
  46. T_nosave="$(gettext 'No suitable partitions to save to. Shutting down without saving.')"
  47. T_continue="$(gettext 'Continue')"
  48. T_abort="$(gettext 'Abort')"
  49. T_no="$(gettext 'No')"
  50. T_notsave="$(gettext 'DO NOT SAVE')"
  51. #/etc/rc.d/rc.shutdown will call shutdownconfig if this file does not exist, then will read its contents...
  52. echo -n "" > /tmp/shutdownconfig_results
  53. . /etc/rc.d/PUPSTATE
  54. . /etc/DISTRO_SPECS
  55. #puppy.sfs is in a subdirectory, default to saving in it...
  56. PUPSFSFILE="`echo "$PUPSFS" | cut -f 3 -d ','`"
  57. PSUBDIR="`dirname "$PUPSFSFILE"`"
  58. [ "$PSUBDIR" = "/" ] && PSUBDIR=""
  59. [ $PUPMODE -eq 5 ] && [ "$DEV1FS" = "iso9660" ] && PSUBDIR="" #100920 booting off cd, always default have savefile at /.
  60. [ $PUPMODE -eq 5 ] && [ "$DEV1FS" = "udf" ] && PSUBDIR="" #130128 ditto, for udf f.s.
  61. [ "$DEV1FS" = "msdos" ] && DEV1FS="vfat"
  62. if [ $DISPLAY ];then
  63. export XDIALOG_HIGH_DIALOG_COMPAT=true #for Xdialog.
  64. DIALOGEXE="pupdialog"
  65. DIALOGEXE2="Xdialog"
  66. BACKGROUNDYELLOW='--background \#FFFF80' #110924 change to pale-yellow. yellow' #only works pupdialog.
  67. BACKGROUNDPINK='--background pink' #ditto.
  68. BACKGROUNDORANGE='--background \#FFDC32' #110924 change to pale-orange. orange' #ditto.
  69. TITLEPARAM='--backtitle'
  70. else
  71. DIALOGEXE="dialog"
  72. DIALOGEXE2="dialog"
  73. TITLEPARAM='--title'
  74. BACKGROUNDYELLOW=''
  75. BACKGROUNDPINK=''
  76. BACKGROUNDORANGE=''
  77. fi
  78. #120514 Karl Godt: precaution, save-file must be at least this big...
  79. DU_INITRD_PUP_RW=0
  80. [ "`mount | grep ' /initrd/pup_rw '`" != "" ] && DU_INITRD_PUP_RW=`du -B 1M -c /initrd/pup_rw |tail -n1 |awk '{print $1}'` #M=1024,MB=1000
  81. #130525 introduced 130522. moved up.
  82. ORANGEGTKRC="style \"windowstuff\"
  83. {
  84. bg[NORMAL] = \"#FFDC32\"
  85. fg[NORMAL] = \"#000000\"
  86. }
  87. class \"*\" style \"windowstuff\"
  88. "
  89. echo "$ORANGEGTKRC" > /tmp/orange_gtkrc${$}
  90. offerfido() {
  91. #offering non-root, ###PENDING### for now
  92. T_admin="$(gettext 'administrator')"
  93. T_fidomsg="`eval_gettext \"fido CURRENTLY EXPERIMENTAL STATUS, PLEASE CHOOSE \\\${T_admin}\"`"
  94. FIDOMSG2="\Zb\Z1${T_fidomsg}\Zn\ZB" #110926
  95. T_fidotitle="$(gettext 'First shutdown: ask fido')"
  96. T_yesno="$(eval_gettext "You are currently running Puppy as the \${T_admin} (also known as 'root') which is the preferred choice. However, for the paranoid, you may run Puppy as a less-privileged user 'fido'. Puppy boots up without requiring a password, whether as \${T_admin} or fido, but the latter will require jumping to \${T_admin} to perform some system-level tasks, which will require entry of the admin password -- this is viewed by many as an unnecessary hassle.")
  97. $(eval_gettext "Puppy is structured in such a way that we consider running as \${T_admin} to be completely safe, and is the choice of most users, however fido is theoretically more secure.")
  98. $(gettext "Note that Puppy only has one non-admin user, fido, as it is not a multi-user system in the normal sense -- instead, each person using Puppy on the same computer can have their own save-file (each one set to root or fido as the users wish).")
  99. $(eval_gettext "Note also, the LoginManager (System menu) enables you to switch back to \${T_admin} if you decide later that you don't want to run as fido.")
  100. ${FIDOMSG2}"
  101. #'geany fix
  102. #offer to save non-root...
  103. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_fidotitle" --colors --yes-label "$T_admin" --no-label "fido" --yesno "$T_yesno" 0 0
  104. SAVECHOICE=$?
  105. [ $SAVECHOICE -eq 1 ] && /usr/sbin/root2user
  106. }
  107. choosepartfunc() {
  108. offerfido
  109. #dialog to choose what partition to create ${DISTRO_FILE_PREFIX}save.2fs on...
  110. [ ! "$PMEDIA" ] && PCHOOSE="yes"
  111. [ "$PMEDIA" = "cd" ] && PCHOOSE="yes"
  112. [ "$PMEDIA" = "scsicd" ] && PCHOOSE="yes"
  113. [ "$PMEDIA" = "satacd" ] && PCHOOSE="yes"
  114. [ "$PMEDIA" = "idecd" ] && PCHOOSE="yes"
  115. [ "$PMEDIA" = "atacd" ] && PCHOOSE="yes"
  116. [ "$PMEDIA" = "usbcd" ] && PCHOOSE="yes"
  117. [ "$DEV1FS" = "ntfs" ] && PCHOOSE="yes"
  118. [ "$DEV1FS" = "msdos" ] && DEV1FS="vfat"
  119. [ "$DEV1FS" = "xxx" ] && PCHOOSE="yes"
  120. expBOOTDRV=''
  121. if [ "$PMEDIA" = "usbflash" ];then #may have a small boot partition and a big 2nd.
  122. expBOOTDRV="/dev/`echo ${PDEV1} | sed -e 's%[0-9]*$%%'`"
  123. PCHOOSE="yes"
  124. fi
  125. if [ "$xPSUBDIR" ];then #if pup installed in a sub-directory, allow save-file in another partition (in same drive)...
  126. expBOOTDRV="/dev/`echo ${PDEV1} | sed -e 's%[0-9]*$%%'`"
  127. PCHOOSE="yes"
  128. fi
  129. if [ "$PSAVEMARK" != "" ];then #see /etc/rc.d/PUPSTATE
  130. devnameonly="`echo -n "$PDEV1" | sed -e 's/[0-9]*$//'`"
  131. SAVEPART="${devnameonly}${PSAVEMARK}" #partition that will-have ${DISTRO_FILE_PREFIX}save.
  132. spPATTERN='/dev/'"$SAVEPART"'|'
  133. SAVEFS="`probepart -m | grep "$spPATTERN" | cut -f 2 -d '|'`"
  134. SAVEFILE="$PSUBDIR/${DISTRO_FILE_PREFIX}save.2fs"
  135. PUPSAVE="$SAVEPART,$SAVEFS,$SAVEFILE"
  136. return 0
  137. fi
  138. if [ "$PCHOOSE" != "yes" ];then
  139. SAVEFS="$DEV1FS"
  140. SAVEPART="$PDEV1"
  141. SAVEFILE="$PSUBDIR/${DISTRO_FILE_PREFIX}save.2fs"
  142. PUPSAVE="$PDEV1,$DEV1FS,$SAVEFILE"
  143. return 0
  144. fi
  145. if [ "$expBOOTDRV" = "" ];then
  146. T_fidotitle="$(gettext 'First shutdown: get ready')"
  147. T_yesno1="$(eval_gettext "WARNING: If you want to create a save-file (\${DISTRO_FILE_PREFIX}save.2fs) in a NTFS partition (Windows XP), it is strongly recommended that you defragment the partition first.")
  148. $(eval_gettext 'Choose \Zb${T_abort}\ZB button to abort this save, start Windows and choose Start->All Programs->Accessories->System Tools->Defragment.')"
  149. T_yesno2="$(gettext 'Make sure any required USB, floppy, etc. is PLUGGED IN NOW!')"
  150. T_yesno3="$(eval_gettext 'Choose \Zb${T_continue}\ZB button to search available storage...')"
  151. T_yesno="\Z1${T_yesno1}\Zn\n\n\Z5${T_yesno2}\Zn\n\n${T_yesno3}" #111003
  152. case $DEV1FS in
  153. iso9660|udf)
  154. T_iso="`eval_gettext \"You have booted off a live-CD or DVD, and you can now save your personal settings and files to a USB Flash drive or any hard drive partition.
  155. However, if you have burnt the CD/DVD as multisession (not closed), then sessions can be saved as additional tracks to the CD/DVD -- each saved session will appear on the CD/DVD as a directory with all the saved files in it, not as a single file. \Zb\Z1THIS IS STILL EXPERIMENTAL, AND DOES NOT WORK WITH LAPTOP OPTICAL DRIVES\Zn\ZB\"`"
  156. T_yesno="$T_iso\n\n$T_yesno
  157. $(eval_gettext "or \Zb${T_cd}\ZB button to save your session back to the CD/DVD..." )"
  158. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_fidotitle" --colors --extra-button --ok-label "$T_continue" --extra-label "$T_cd" --cancel-label "$T_abort" --yesno "$T_yesno" 0 0
  159. SAVECHOICE=$?
  160. [ "$SAVECHOICE" == "3" ] && PUPMODE=77 && SAVEPART="$PDEV1" && return 1 #save to cd/dvd.
  161. [ ! $SAVECHOICE -eq 0 ] && return 3 #skip.
  162. ;;
  163. *)
  164. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_fidotitle" --colors --yes-label "$T_continue" --no-label "$T_abort" --yesno "$T_yesno" 0 0
  165. SAVECHOICE=$?
  166. [ ! $SAVECHOICE -eq 0 ] && return 1 #abort.
  167. ;;
  168. esac
  169. fi
  170. #130216 add f2fs...
  171. PARTSLIST="`probepart -m 2> /dev/null | grep '^/dev/' | grep "$expBOOTDRV" | grep -E 'f2fs|ext2|ext3|ext4|reiserfs|msdos|vfat|minix|ntfs|btrfs' | cut -f 1-3 -d '|' | sed -e 's/msdos/vfat/g'`"
  172. #nothing to save to...
  173. if [ "$PARTSLIST" = "" ];then
  174. if [ $DISPLAY ];then
  175. /usr/lib/gtkdialog/box_splash -bg red -close box -fontsize large -timeout 10 -text "$T_nosave"
  176. else
  177. clear
  178. echo "T_nosave"
  179. sleep 5
  180. fi
  181. return 1
  182. fi
  183. T_waitprobing="$(gettext 'Please wait, probing partitions...')"
  184. if [ "$DISPLAY" ]; then
  185. /usr/lib/gtkdialog/box_splash -close never -fontsize large -text "$T_waitprobing" &
  186. ppPID=$!
  187. fi
  188. SCHOICES=""; DEFTAG=""
  189. rm -f /tmp/schoices.txt
  190. rm -f /tmp/shutdownconfig_deftag
  191. echo "$PARTSLIST" | grep -qw "$PDEV1" && INSTALLED="y" || INSTALLED=""
  192. echo "$PARTSLIST" |
  193. while read APART
  194. do
  195. ATAG="`echo -n "$APART" | cut -f 1 -d '|' | cut -f 3 -d '/'`"
  196. ASIZE="`echo -n "$APART" | cut -f 3 -d '|'`"
  197. AFS="`echo -n "$APART" | cut -f 2 -d '|'`"
  198. AFREE=`df -m | grep "/dev/${ATAG} " | tr -s " " | cut -f 4 -d " "`
  199. if [ ! $AFREE ];then
  200. mount -t $AFS /dev/$ATAG /mnt/data > /dev/null 2>&1
  201. #need to put in a check that it is not mounted ro. the
  202. #mount script will fallback to ro for ntfs if rw mnt fails...
  203. RETMNTVAL=$?
  204. if [ $RETMNTVAL -eq 0 ];then
  205. if [ "`mount | grep '(rw' | grep '/mnt/data'`" = "" ];then
  206. umount /mnt/data
  207. RETMNTVAL=1
  208. else
  209. #if the ntfs rw mount was forced (see /bin/mount script) it is unwise to use...
  210. ERRMSG1=""
  211. [ -s /tmp/ntfsmnterr.txt ] && ERRMSG1="`cat /tmp/ntfsmnterr.txt | grep 'Dirty volume mount'`"
  212. if [ "$ERRMSG1" != "" ];then
  213. T_ntfstitle="$(gettext 'First shutdown: NTFS warning')"
  214. T_WARNING="\Z1\Zb$(gettext 'WARNING:')\ZB"
  215. T_ntfs="$(eval_gettext "The ntfs-3g driver has determined that the NTFS filesystem in partition \${ATAG} is 'dirty'.")
  216. $(gettext 'It will display in the next dialog box in the list of partitions to save to, but it is recommended that you do not use it.')
  217. $(gettext "Instead, you should first run Microsoft Windows -- most often this problem is due to Windows not being shut down properly the last time it was used, leaving the filesystem in a 'dirty' state.")"
  218. T_continue="$(gettext 'Click button to continue...')"
  219. ${DIALOGEXE} ${BACKGROUNDPINK} ${TITLEPARAM} "$T_ntfstitle" --colors --msgbox "${T_WARNING}\n${T_ntfs}\Zn\n\n${T_continue}" 0 0
  220. fi
  221. fi
  222. fi
  223. [ -f /tmp/ntfsmnterr.txt ] && rm -f /tmp/ntfsmnterr.txt
  224. if [ $RETMNTVAL -eq 0 ];then
  225. if [ "$ATAG" = "fd0" ];then
  226. FFREE=`df -k | grep "/dev/$ATAG" | tr -s " " | cut -f 4 -d " "`
  227. AFREE=`dc $FFREE 1000 \/ p` #not 1024
  228. else
  229. #for ntfs cannot use /dev/$ATAG, use mnt point in grep...
  230. AFREE=`df -m | grep "/mnt/data" | tr -s " " | cut -f 4 -d " "`
  231. fi
  232. #umount /dev/$ATAG v2.02 must use mnt point for ntfs...
  233. umount /mnt/data
  234. fi
  235. fi
  236. if [ $AFREE -ne 0 ];then
  237. if [ -z "$INSTALLED" ] && [ $AFREE -gt 512 ] && [ ! -s /tmp/shutdownconfig_deftag ];then
  238. case $AFS in
  239. ext?|reiserfs|minix|btrfs|f2fs) echo -n " --default-item ${ATAG}" > /tmp/shutdownconfig_deftag;;
  240. esac
  241. fi
  242. if [ "$ATAG" = "$PDEV1" -a $AFREE -gt 256 ];then #120327
  243. echo -n " --default-item ${ATAG}" > /tmp/shutdownconfig_deftag
  244. echo "${ATAG} \"f.s.: $AFS `gettext 'Size:'` ${ASIZE}M `gettext 'Free:'` ${AFREE}M `gettext '*RECOMMENDED*'`\" " >> /tmp/schoices.txt
  245. else
  246. echo "${ATAG} \"`gettext 'Filesystem:'` $AFS `gettext 'Size:'` ${ASIZE}M `gettext 'Free:'` ${AFREE}M\" " >> /tmp/schoices.txt
  247. fi
  248. fi
  249. done
  250. kill $ppPID
  251. [ -s /tmp/shutdownconfig_deftag ] && DEFTAG="`cat /tmp/shutdownconfig_deftag`"
  252. [ -s /tmp/schoices.txt ] && SCHOICES="`cat /tmp/schoices.txt`"
  253. if [ "$SCHOICES" = "" ];then
  254. if [ $DISPLAY ];then
  255. /usr/lib/gtkdialog/box_splash -bg red -close box -fontsize large -timeout 10 -text "$T_nosave"
  256. else
  257. clear
  258. echo "$T_nosave"
  259. sleep 5
  260. fi
  261. return 1
  262. fi
  263. xSCHOICES="`cat /tmp/schoices.txt | tr '\n' ' '`"
  264. if [ `echo "$SCHOICES" | wc -l` -eq 1 ];then
  265. SAVEPART="`echo -n "$SCHOICES" | cut -f 1 -d ' '`" #no need for dlg.
  266. else
  267. T_partitiontitle="$(gettext 'First shutdown: choose partition')"
  268. T_menu="$(gettext 'Please choose a partition to create a pupsave on.')
  269. $(gettext 'For Windows partitions(ntfs/vfat), Puppy makes a file with a Linux filesystem image in it. The size is typically 512MB - 4GB (it can be made bigger later).')
  270. $(gettext 'On linux partitions(ext3 and etc.), Puppy makes a folder for pupsave. Unlike single file, the size is not predetermined but limited by the free space of the partition. A Linux partition is recommended, if available.')
  271. $(gettext 'Highlight desired choice, then click OK button...')"
  272. echo '#!/bin/sh' > /tmp/savedlg
  273. echo -n "${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} \"${T_partitiontitle}\" --no-collapse --no-cancel ${DEFTAG} --menu \"${T_menu}\" 0 0 0 " >> /tmp/savedlg
  274. echo -n "$xSCHOICES" >> /tmp/savedlg
  275. echo ' 2>/tmp/tag.txt' >> /tmp/savedlg
  276. chmod 755 /tmp/savedlg
  277. #seems some people have problem, do not select anything...
  278. T_notchosentitle="$(gettext 'First shutdown: Not chosen')"
  279. T_tryagain="$(gettext 'Try again')"
  280. T_yesno="$(gettext '\Zb\Z1ERROR:\Zn\ZB you did not choose any partition.')
  281. $(eval_gettext 'Choose \Zb${T_tryagain}\ZB button to try again...')
  282. $(eval_gettext 'Or, \Zb${T_abort}\ZB to shutdown without saving...')"
  283. while [ 1 ];do
  284. /tmp/savedlg
  285. SAVEPART="`cat /tmp/tag.txt | head -n 1`" #head is in case of errs in output.
  286. if [ "`echo -n "$SAVEPART" | grep --extended-regexp '^hd|^sd|^sc|^fd|^mmcblk'`" = "" ];then
  287. ${DIALOGEXE} ${BACKGROUNDPINK} ${TITLEPARAM} "$T_notchosentitle" --colors --yes-label "$T_tryagain" --no-label "${T_abort}" --yesno "$T_yesno" 0 0
  288. [ ! $? -eq 0 ] && return 1 #abort.
  289. continue
  290. fi
  291. break
  292. done
  293. fi
  294. SAVEFS="`echo "$SCHOICES" | grep "^${SAVEPART} " | tr -s " " | cut -f 2 -d ':' | cut -f 2 -d " "`"
  295. SAVEFILE="$PSUBDIR/${DISTRO_FILE_PREFIX}save.2fs"
  296. [ "$SAVEPART" = "fd0" ] && SAVEFILE="/${DISTRO_FILE_PREFIX}save.2fs"
  297. PUPSAVE="$SAVEPART,$SAVEFS,$SAVEFILE"
  298. echo "$PUPSAVE" #TEST
  299. return 0
  300. } #end choosepartfunc
  301. choosesizefunc(){
  302. local KFREE SIZELIST NUM CHOICES FLABEL SLABEL ACHOICE KSIZE VALUES VALIDS val
  303. KFREE=$1 ; SIZELIST="" ; NUM=1 ; CHOICES=""
  304. FLABEL="`expr $KFREE \/ 1024`MB"
  305. [ $KFREE -ge 1048576 ] && FLABEL="`dc $KFREE 1048576 \/ p`GB"
  306. VALUES='32 64 128 256 512 768 1024 1280 2048 4096'
  307. for val in $VALUES;do
  308. [ "$val" -gt "$DU_INITRD_PUP_RW" ] && VALIDS="$VALIDS $val"
  309. done
  310. #global: DEFAULT_SAVE_SIZE in MB
  311. [ $DEFAULT_SAVE_SIZE -gt 0 ] || DEFAULT_SAVE_SIZE=512
  312. local NDEFAULT=1
  313. for ACHOICE in $VALIDS
  314. do
  315. [ $ACHOICE -le $DEFAULT_SAVE_SIZE ] && NDEFAULT=$NUM
  316. KSIZE=`expr $ACHOICE \* 1024`
  317. SLABEL="${ACHOICE}MB"
  318. [ $ACHOICE -ge 1024 ] && SLABEL="`dc $ACHOICE 1024 \/ p`GB"
  319. if [ $KSIZE -lt $KFREE ];then
  320. SIZELIST="$SIZELIST$NUM $SLABEL "
  321. CHOICES="$CHOICES$KSIZE "
  322. else
  323. SIZELIST="$SIZELIST$NUM fill_partition(${FLABEL}) "
  324. CHOICES="$CHOICES$KFREE "
  325. break
  326. fi
  327. NUM=`expr $NUM + 1`
  328. done
  329. T_sizetitle="$(gettext 'First shutdown: size save-file')"
  330. T_sitemenu="$(gettext 'Please choose the size you would like for the personal save file.')
  331. $(gettext 'Note, 512M is a good choice, or highest if that not available.')
  332. $(gettext 'Select choice, then click OK button...')"
  333. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_sizetitle" --no-collapse --no-cancel --default-item "$NDEFAULT" --menu "$T_sitemenu" 0 0 0 $SIZELIST 2>/tmp/sizetag.txt
  334. NUM=`cat /tmp/sizetag.txt`
  335. ACHOICE=`echo -n "$CHOICES" | cut -f $NUM -d ' '`
  336. #return $ACHOICE
  337. SIZEPFILE=$ACHOICE #global variable.
  338. } # end of choosesizefunc()
  339. choosestyle() {
  340. #do not allow save to entire partition if pup installed in a subdirectory...
  341. #xPSUBDIR="`echo -n "$PUPSFS" | cut -f 3 -d ',' | sed -e 's%/[^/]*$%%'`" #ex: sda3,ext2,/pup220/puppy.sfs will return /pup220
  342. [ "$SAVEPART" = "$PDEV1" ] && [ -z "$xPSUBDIR" ] && OFFER_PARTITION="y" || OFFER_PARTITION=""
  343. T_fstitle="$(gettext 'First shutdown: choose saving style')"
  344. T_fsmenu="$(gettext "You can save the session in a 'folder(directory)' because you chose a Linux partition. Unlike single file, saving in a folder is not restricted to the fixed file size but by the free space on the partition. You can save multiple profiles by different name.")
  345. $(gettext "A \Zbfolder\ZB is recommended for this case, but you still have another option if you have some reason and you want it.")"
  346. T_folder="$(gettext 'Save in a folder.') $(gettext '*RECOMMENDED*')"
  347. T_partition=$(gettext "Save to the entire partition. Only one profile.")
  348. T_file=$(gettext 'Single file, ext2/3/4 filesystem image in it.')
  349. if [ "$OFFER_PARTITION" ]; then
  350. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_fstitle" --colors --no-cancel --default-item folder --menu "$T_fsmenu" 0 0 0 folder "$T_folder" partition "$T_partition" file "$T_file" 2>/tmp/rc.shutdown_pupsave_style
  351. else
  352. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_fstitle" --colors --no-cancel --default-item folder --menu "$T_fsmenu" 0 0 0 folder "$T_folder" file "$T_file" 2>/tmp/rc.shutdown_pupsave_style
  353. fi
  354. SAVESTYLE=$(cat /tmp/rc.shutdown_pupsave_style)
  355. [ "$SAVESTYLE" ]
  356. }
  357. choosesize() {
  358. #we should check to see that there is enough space on the partition...
  359. PARTFREE=`df | grep "$SMNTPT" | tr -s " " | head -n 1 | cut -f 4 -d " "`
  360. [ ! $PARTFREE ] && PARTFREE=0
  361. [ $PARTFREE -lt 32768 ] && PARTFREE=`expr $PARTFREE - 1024` #leave some slack space.
  362. [ $PARTFREE -gt 32768 ] && PARTFREE=`expr $PARTFREE - 8192` #leave some slack space.
  363. SIZEPFILE=524288 #512M = 524288K
  364. [ $SIZEPFILE -gt $PARTFREE ] && SIZEPFILE=$PARTFREE
  365. [ $PARTFREE -gt 32768 ] && choosesizefunc $PARTFREE #sets SIZEPFILE
  366. if [ "`echo -n $SAVEFILE | grep '\.[34]fs$'`" != "" ];then #ext3 f.s. needs minimum size.
  367. [ $SIZEPFILE -lt 5000 ] && return 1 #precaution. rerwin discovered this.
  368. fi
  369. }
  370. choosefs(){
  371. #choose f.s. of save-file... 100410 for now, leave out ext4, doesn't work...
  372. T_fstitle="$(gettext 'First shutdown: choose filesystem')"
  373. T_fsmenu="$(gettext 'Previously, Puppy has only used 'ext2', now there is a choice. Regarding power-failure, note that Puppy will do a f.s. check at next boot so ext2 can recover, however journalled filesystems can recover even without a f.s. check. If in doubt, choose 'ext2'. After making the choice, click OK button...')"
  374. T_ext2="$(gettext 'Maximum storage space, encrypted save-file must use ext2')"
  375. T_ext3="$(gettext 'Journalled f.s., safest if power failure etc.')"
  376. #120427 01micko: support ext4...
  377. T_ext4="$(gettext 'Journalled f.s., safest if power failure etc.')"
  378. if [ "`grep 'ext4$' /proc/filesystems`" != "" ];then #120428 technosaurus: simplify test.
  379. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_fstitle" --no-cancel --default-item ext4 --menu "$T_fsmenu" 0 0 0 ext2 "$T_ext2" ext3 "$T_ext3" ext4 "$T_ext4" 2>/tmp/rc.shutdown_pupsave_fs #120425 01micko
  380. else
  381. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_fstitle" --no-cancel --default-item ext3 --menu "$T_fsmenu" 0 0 0 ext2 "$T_ext2" ext3 "$T_ext3" 2>/tmp/rc.shutdown_pupsave_fs #110926
  382. fi
  383. SFFS="`cat /tmp/rc.shutdown_pupsave_fs`"
  384. [ "$SFFS" = "" ] && SFFS='ext2'
  385. SFEXTNUM="`echo -n "$SFFS" | cut -c 4`"
  386. SFEXT="${SFEXTNUM}fs" #ex: 2fs
  387. #sfPATTERN="s%[234]fs$%${SFEXTNUM}fs%"
  388. #SAVEFILE="`echo -n "$SAVEFILE" | sed -e "$sfPATTERN"`"
  389. #PUPSAVE="$SAVEPART,$SAVEFS,$SAVEFILE"
  390. #NAMEONLY="`basename $SAVEFILE`"
  391. }
  392. choosename() {
  393. #[ "${DENSITY}" ] && CRYPT_NAME="_crypt${DENSITY}" || CRYPT_NAME=""
  394. #customise the name of the ${DISTRO_FILE_PREFIX}save file...
  395. T_nametitle="$(gettext 'First shutdown: pupsave name')"
  396. T_nameinput="$(eval_gettext "Would you like to customise the name of the '\${DISTRO_FILE_PREFIX}save'?")
  397. $(eval_gettext "This is optional, but it is convenient to manage multiple profiles. If you have lots of '\${DISTRO_FILE_PREFIX}save' and you want to choose the right one at startup.")
  398. $(eval_gettext "For example, if you enter 'john' here, the file will become '\${DISTRO_FILE_PREFIX}save-john'.")
  399. $(gettext 'Type any alpha-numeric characters you wish, then click OK button:')"
  400. MYUSERNAME="`${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_nametitle" --stdout --nocancel --inputbox "$T_nameinput" 0 0 ""`"
  401. NAMEONLY="${DISTRO_FILE_PREFIX}save${CRYPT_NAME}"
  402. if [ "$MYUSERNAME" != "" ];then
  403. MYUSERNAME="`echo -n "$MYUSERNAME" | tr ' ' '_' | tr '-' '_' | sed -e 's/[^a-zA-Z0-9_.]//g'`"
  404. NAMEONLY="$NAMEONLY-${MYUSERNAME}"
  405. fi
  406. #[ "${SFEXT}" ] && NAMEONLY="$NAMEONLY.${SFEXT}"
  407. #SAVEFILE="$PSUBDIR/$NAMEONLY"
  408. #PUPSAVE="$SAVEPART,$SAVEFS,$SAVEFILE"
  409. }
  410. choosecrypt() {
  411. CRYPTO=""
  412. T_cryptotitle="$(gettext 'First shutdown: encryption')"
  413. T_cryptono="$(gettext 'NORMAL (no encryp.)')"
  414. T_cryptoheavy="$(gettext 'Heavy encrypted')"
  415. T_cryptolight="$(gettext 'Light encrypted')"
  416. T_yesno="$(eval_gettext "Do you want to encrypt the '\${DISTRO_FILE_PREFIX}save'?")
  417. $(eval_gettext "If the '\${DISTRO_FILE_PREFIX}save' is encrypted, then a password will have to be entered at every bootup. The reason for doing this is security, as no one else will be able to see what is inside the \${DISTRO_FILE_PREFIX}save. Encryption does slow \${DISTRO_NAME} down slightly, the 'heavy' encryption the most. Two scenarios:")
  418. \Zb$(gettext '1.')\ZB $(eval_gettext "If the \${DISTRO_FILE_PREFIX}save file is on a Flash drive, encryption is protection in case the drive is mislaid. Heavy encryption is recommended, as \${DISTRO_NAME} minimises writes to the save file (to prolong life of the Flash drive, but this also minimises encryption slowdown).")
  419. \Zb$(gettext '2.')\ZB $(eval_gettext "If the \${DISTRO_FILE_PREFIX}save file is on a hard drive, 'light' encryption is recommended to minimise slowdown, particularly on older PCs.")
  420. $(eval_gettext "Encrypted \${DISTRO_FILE_PREFIX}save files have another advantage, they allow multiple users. Recommended if spouse and kids are going to be using the same \${DISTRO_NAME} installation.")
  421. $(gettext 'Unless you have a good reason to use encryption, it is recommended not to, to avoid the overhead. Recommend choose \ZbNORMAL\ZB button...')"
  422. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_cryptotitle" --colors --extra-button --ok-label "$T_cryptono" --cancel-label "$T_cryptoheavy" --extra-label "$T_cryptolight" --yesno "$T_yesno" 0 0 #110926
  423. RETVAL=$?
  424. if [ $RETVAL -eq 1 -o $RETVAL -eq 3 ];then
  425. T_passtitle="$(gettext 'First shutdown: password')"
  426. T_passtext="$(gettext 'Please choose a password.
  427. This must be remembered and
  428. entered at every bootup.')"
  429. while [ 1 ];do
  430. MYPASSWORD="`${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_passtitle" --screen-center --stdout --no-cancel --inputbox "$T_passtext" 0 0 "puppyisgreat"`" #110926
  431. [ "$MYPASSWORD" ] && break
  432. done
  433. modprobe cryptoloop
  434. if [ $RETVAL -eq 1 ];then
  435. DENSITY="a" #heavy aes encryption
  436. CRYPTO='-e aes'
  437. modprobe aes_generic 2>/dev/null #builtin my recent kernels.
  438. #did not explicitly load these two before, but do so in init script...
  439. modprobe crypto_blkcipher 2>/dev/null #builtin my recent kernels.
  440. modprobe cbc 2>/dev/null #110926 builtin in my 2.6.32-smp-45 kernel.
  441. else
  442. DENSITY="x" #light xor encryption.
  443. CRYPTO='-E 1' #'-e xor' --bug, loads xor.ko which is something else.
  444. fi
  445. CRYPT_NAME=""
  446. [ "${DENSITY}" ] && CRYPT_NAME="_crypt${DENSITY}" && SFEXT="2fs"
  447. fi
  448. }
  449. nameclash() {
  450. #save with different name if clash...
  451. [ ! -e $SMNTPT$SAVEFILE ] && return 0
  452. NAMEONLY=$(basename "$SAVEFILE")
  453. NAMEROOT=${NAMEONLY%.*}
  454. MNAMEONLY=$NAMEROOT
  455. T_clashtitle="$(gettext 'First shutdown: name clash')"
  456. T_save="$(gettext 'SAVE')"
  457. T_yesno="$(eval_gettext "There already exists '\${NAMEONLY}' on the partition you chose.")
  458. $(eval_gettext 'To create another one, with a slightly different name (such as ${MNAMEONLY}-1.${SFEXT}), select \Zb${T_save}\ZB button...')
  459. $(eval_gettext 'To quit without saving, select \Zb${T_no}\ZB button...')"
  460. ${DIALOGEXE} ${BACKGROUNDPINK} ${TITLEPARAM} "$T_clashtitle" --colors --yes-label "$T_save" --yesno "$T_yesno" 0 0
  461. [ ! $? -eq 0 ] && return 1
  462. local BLA=1 #; local SFFIX=`echo "$SAVEFILE" | tail -c 5`
  463. while [ -e $SMNTPT$SAVEFILE ]; do
  464. SAVEFILE="$PSUBDIR/${NAMEROOT}-${BLA}"
  465. [ "${SFEXT}" ] && SAVEFILE="$SAVEFILE.${SFEXT}"
  466. BLA=`expr $BLA + 1`
  467. done
  468. #PUPSAVE="$SAVEPART,$SAVEFS,$SAVEFILE"
  469. #NAMEONLY="`basename $SAVEFILE`"
  470. }
  471. enmount() {
  472. sPTN="/dev/${SAVEPART} "
  473. SMNTPT="`mount | grep "$sPTN" | head -n1 | tr -s " " | cut -f 3 -d " "`"
  474. #ntfs uses /dev/fuse so '/dev/$SAVEPART' no good for grep... NOTE: this fixed later versions ntfs-3g, so this line actually redundant...
  475. [ "$SMNTPT" = "" ] && SMNTPT="`ps -e | grep -o 'ntfs\-3g.*' | grep "$sPTN" | tr '\t' ' ' | tr -s ' ' | tr ' ' "\n" | grep '^/mnt/'`"
  476. if [ "$SMNTPT" = "" ];then
  477. mkdir /mnt/$SAVEPART 2>/dev/null
  478. mount -t $SAVEFS /dev/$SAVEPART /mnt/$SAVEPART
  479. SMNTPT="/mnt/$SAVEPART"
  480. fi
  481. return 0
  482. }
  483. changefolder() {
  484. T_choosefoldertitle="$(gettext 'First shutdown: choose folder')"
  485. T_inputbox="$(gettext 'Edit path. '/' means top-level of partition.
  486. You are only allowed to save one-deep, for example: '/puppy300'.
  487. If folder does not exist, it will be created. Spaces are not allowed.
  488. If uncertain, just click OK button.')"
  489. NEWSAVEPATH="`${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_choosefoldertitle" --screen-center --stdout --no-cancel --inputbox "$T_inputbox" 0 0 "$SAVEPATH"`"
  490. [ "$NEWSAVEPATH" = "" ] && NEWSAVEPATH="$SAVEPATH"
  491. [ "`echo -n "$NEWSAVEPATH" | cut -b 1`" != "/" ] && NEWSAVEPATH="/${NEWSAVEPATH}"
  492. [ "$NEWSAVEPATH" != "/" ] && NEWSAVEPATH="`echo -n "$NEWSAVEPATH" | sed -e 's%/$%%'`"
  493. NEWSAVEPATH="`echo -n "$NEWSAVEPATH" | sed -e 's/ //g'`"
  494. SAVEPATH="$NEWSAVEPATH"
  495. SAVEPATHs="$SAVEPATH"
  496. [ "$SAVEPATH" != "/" ] && SAVEPATHs="${SAVEPATH}/"
  497. SAVEFILE="${SAVEPATHs}${NAMEONLY}"
  498. PUPSAVE="$SAVEPART,$SAVEFS,$SAVEFILE"
  499. }
  500. pupsavefunc() {
  501. SAVEPATH="`dirname $SAVEFILE`"
  502. #[ ! -d ${SMNTPT}${SAVEPATH} ] && mkdir -p ${SMNTPT}${SAVEPATH}
  503. #final sanity check...
  504. AAAMB=`expr $SIZEPFILE \/ 1024`
  505. T_sanititle="$(gettext 'First shutdown: sanity check')"
  506. T_saniyes="$(gettext 'YES, SAVE')"
  507. T_sanichange="$(gettext 'CHANGE FOLDER')"
  508. while [ 1 ];do
  509. nameclash || return 1
  510. SAVEPATH=$(dirname "$SAVEFILE")
  511. [ "$SAVEPATH" = '/' ] && SAVEPATH=''
  512. NAMEONLY=$(basename "$SAVEFILE")
  513. T_sanitext="`eval_gettext \"\Zb\Z1FINAL SANITY CHECK:\Zn\ZB
  514. Partition you are saving to: \Zb\\\${SAVEPART}\ZB
  515. The filesystem of \\\${SAVEPART} partition: \Zb\\\${SAVEFS}\ZB
  516. Name of the save file: \Zb\\\${NAMEONLY}\ZB
  517. Path (folder) of the save file: \Zb\\\${SAVEPATH}\ZB
  518. Size of save file: \Zb\\\${SIZEPFILE}KB (\\\${AAAMB}MB)\ZB
  519. Filesystem inside save file: \Zb\\\${SFFS}\ZB
  520. If they definitely look right, choose \Zb\\\${T_saniyes}\ZB button...
  521. Looks ok, but you want to change the folder, choose \Zb\\\${T_sanichange}\ZB...
  522. If anything looks wrong, choose \Zb\\\${T_notsave}\ZB...\"`"
  523. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_sanititle" --colors --no-collapse --extra-button --ok-label "$T_saniyes" --extra-label "$T_sanichange" --cancel-label "$T_notsave" --yesno "$T_sanitext" 0 0 #110926
  524. SANITYRET=$?
  525. [ $SANITYRET -ne 0 -a $SANITYRET -ne 3 ] && return 1
  526. [ $SANITYRET -eq 0 ] && break
  527. if [ $SANITYRET -eq 3 ];then #change folder.
  528. changefolder
  529. else
  530. SAVEFILE="${SAVEPATH}${NAMEONLY}"
  531. PUPSAVE="$SAVEPART,$SAVEFS,$SAVEFILE"
  532. fi
  533. done
  534. [ -f ${SMNTPT}${SAVEPATH} ] && return 1 #abort. must be a directory.
  535. [ ! -d ${SMNTPT}${SAVEPATH} ] && mkdir ${SMNTPT}${SAVEPATH}
  536. [ ! -d ${SMNTPT}${SAVEPATH} ] && return 1 #some kind of error, abort.
  537. #JOPT=""
  538. [ "$SAVEPART" = "fd0" ] && SIZEPFILE=`expr $SIZEPFILE - 16`
  539. [ "$SFEXT" = "3fs" ] && JOPT='-j'
  540. #echo "Creating $NAMEONLY in /dev/$SAVEPART, please wait awhile..."
  541. T_createtitle="$(gettext 'First shutdown: creating save-file')"
  542. T_createsf="$(eval_gettext "Creating \${NAMEONLY} in \${SAVEPART}, please wait awhile (no need to click OK button)...")"
  543. altT_createsf="$(eval_gettext "Creating \${NAMEONLY} in \${SAVEPART}, please wait awhile...")"
  544. if [ $DISPLAY ];then #130522 remove OK button...
  545. #create nice window looking like prior ones...
  546. export SHUTDLG="<window decorated=\"false\">
  547. <vbox>
  548. <text use-markup=\"true\"><label>\"<big><b>${T_createtitle}</b></big>\"</label></text>
  549. <text use-markup=\"true\"><label>\"<big>${altT_createsf}</big>\"</label></text>
  550. </vbox>
  551. </window>"
  552. GTK2_RC_FILES=/tmp/orange_gtkrc${$}:/root/.gtkrc-2.0 gtkdialog --center --class="splashwindow" --program=SHUTDLG & #130525 130712
  553. w1PID=$!
  554. else
  555. ${DIALOGEXE} ${BACKGROUNDORANGE} ${TITLEPARAM} "$T_createtitle" --colors --ok-label "OK" --msgbox "$T_createsf" 0 0 &
  556. w1PID=$!
  557. fi
  558. dd if=/dev/zero of=${SMNTPT}$SAVEFILE bs=1k count=$SIZEPFILE >&2
  559. sync
  560. #pupkill $w1PID
  561. echo "`eval_gettext \"Creating a \\\${SFFS} filesystem in \\\${NAMEONLY}...\"`"
  562. if [ "$CRYPTO" = "" ];then
  563. case $SFFS in
  564. ext2) mkfs.ext2 -q -m 0 -F ${SMNTPT}$SAVEFILE ;;
  565. ext3) mkfs.ext3 -q -m 0 -F ${SMNTPT}$SAVEFILE ;;
  566. ext4) mkfs.ext4 -q -m 0 -F ${SMNTPT}$SAVEFILE ;;
  567. esac
  568. #...default is f.s. auto checked every 26 mounts or 180 days. tune2fs to change.
  569. pupkill $w1PID #130525 moved down.
  570. else
  571. #note: loop2 is kept available for scripts to use. but, find which is free...
  572. DEVLOOP="`losetup-FULL -f`"
  573. if [ "$DEVLOOP" = "" ];then
  574. pupkill $w1PID #130525 moved down.
  575. return 1
  576. fi
  577. #'-p 0' means read password from stdin...
  578. #v2.17 crap, '-p 0' works for aes, not for xor encryption....
  579. if [ "$CRYPTO" = '-E 1' ];then #light xor encr.
  580. T_note1="$(gettext 'Note, a bug in one of the Linux utility programs requires you to reenter')"
  581. T_note2="$(gettext 'the password in the case of light encryption...')"
  582. echo "#!/bin/sh
  583. echo \"${T_note1}\"
  584. echo \"${T_note2}\"
  585. echo \"${MYPASSWORD}\" | losetup-FULL -p 0 ${CRYPTO} ${DEVLOOP} ${SMNTPT}${SAVEFILE}" > /tmp/shutdownconfig_encrypt_password
  586. chmod 755 /tmp/shutdownconfig_encrypt_password
  587. urxvt -bg '#FFFF80' -fg black -geometry 80x5 -title "$(gettext 'First shutdown: reenter password')" -e /tmp/shutdownconfig_encrypt_password
  588. else
  589. echo "$MYPASSWORD" | losetup-FULL -p 0 $CRYPTO $DEVLOOP ${SMNTPT}$SAVEFILE
  590. fi
  591. if [ $? -ne 0 ];then
  592. pupkill $w1PID #130525 moved down.
  593. return 1
  594. fi
  595. mke2fs -q -m 0 $DEVLOOP #REMOVEDv3.98 added '-O none', fix mntg fail at boot.
  596. sync
  597. pupkill $w1PID #130525 moved down.
  598. losetup -d $DEVLOOP
  599. fi
  600. sync
  601. return 0
  602. } #end pupsavefunc
  603. save_directory() {
  604. #final sanity check...
  605. T_sanititle="$(gettext 'First shutdown: sanity check')"
  606. T_saniyes="$(gettext 'YES, SAVE')"
  607. T_sanichange="$(gettext 'CHANGE FOLDER')"
  608. while [ 1 ];do
  609. nameclash || return 1
  610. SAVEPATH=$(dirname "$SAVEFILE")
  611. [ "$SAVEPATH" = '/' ] && SAVEPATH=''
  612. NAMEONLY=$(basename "$SAVEFILE")
  613. T_sanitext="`eval_gettext \"\Zb\Z1FINAL SANITY CHECK:\Zn\ZB
  614. Partition you are saving to: \Zb\\\${SAVEPART}\ZB
  615. The filesystem of \\\${SAVEPART} partition: \Zb\\\${SAVEFS}\ZB
  616. Path (folder) of the pupsave: \Zb\\\${SAVEPATH}/${NAMEONLY}\ZB
  617. If they definitely look right, choose \Zb\\\${T_saniyes}\ZB button...
  618. Looks ok, but you want to change the folder, choose \Zb\\\${T_sanichange}\ZB...
  619. If anything looks wrong, choose \Zb\\\${T_notsave}\ZB...\"`"
  620. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_sanititle" --colors --no-collapse --extra-button --ok-label "$T_saniyes" --extra-label "$T_sanichange" --cancel-label "$T_notsave" --yesno "$T_sanitext" 0 0 #110926
  621. SANITYRET=$?
  622. [ $SANITYRET -ne 0 -a $SANITYRET -ne 3 ] && return 1
  623. [ $SANITYRET -eq 0 ] && break
  624. if [ $SANITYRET -eq 3 ];then #change folder.
  625. changefolder
  626. else
  627. SAVEFILE="${SAVEPATH}${NAMEONLY}"
  628. PUPSAVE="$SAVEPART,$SAVEFS,$SAVEFILE"
  629. fi
  630. done
  631. mkdir -p $SMNTPT$SAVEFILE 2>/dev/null
  632. PUPSAVEICON=/usr/local/apps/ROX-Filer/ROX/MIME/application-x-ext2-image.png
  633. [ -s "$PUPSAVEICON" ] && cp -f "$PUPSAVEICON" "$SMNTPT$SAVEFILE/.DirIcon"
  634. #record all variables to a file...
  635. #echo "
  636. PUPMODE=128
  637. SAVEPART=${SAVEPART}
  638. SAVEFS=${SAVEFS}
  639. PUPSAVE=${PUPSAVE}
  640. SAVEFILE=${SAVEFILE}
  641. NAMEONLY=${NAMEONLY}
  642. SAVEPATH=${SAVEPATH}
  643. MYPASSWORD=''
  644. SFEXT=''
  645. xPDEV=${PDEV1}
  646. xDEVFS=${DEV1FS}
  647. xPSUBDIR=${PSUBDIR}
  648. SMNTPT=${SMNTPT}
  649. CRYPTO=''
  650. expBOOTDRV=${expBOOTDRV} #" > /tmp/shutdownconfig_results
  651. } #end sace_directory
  652. offersfscopy() {
  653. #offer to copy $DISTRO_PUPPYSFS (puppy.sfs) and $DISTRO_ZDRVSFS (zdrv.sfs) etc off the cd...
  654. if [ "$DEV1FS" = "iso9660" -o "$DEV1FS" = "udf" ];then #test if booted off cd. 130128
  655. if [ ! -f ${SMNTPT}/${DISTRO_PUPPYSFS} ];then #see file DISTRO_SPECS, init
  656. NAMEONLY="`basename $SAVEFILE`"
  657. T_copytitle="$(gettext 'First shutdown: copy .sfs from CD')"
  658. T_copy="$(gettext 'COPY')"
  659. yesno="`eval_gettext \"The CD has '\\\${DISTRO_PUPPYSFS}' and maybe other .sfs files on it. It will speed startup considerably if these are on the hard drive.
  660. Also, for PCs with less than 256MB of RAM, \\\${DISTRO_NAME} does not copy the \\\${DISTRO_PUPPYSFS} file to RAM so the CD drive remains mounted, meaning that the drive cannot be used for other purposes.
  661. However, if you reply \Zb\\\${T_copy}\ZB here then it will be copied to the same drive as the '\\\${DISTRO_FILE_PREFIX}save' file and loaded from there at startup, thus freeing the CD drive for other uses.
  662. Even if you have heaps of RAM, it is still good to answer \Zb\\\${T_copy}\ZB to get the faster startup.
  663. Note: if a CD has extra .sfs files on it, by copying them to the same drive as the '\\\${DISTRO_FILE_PREFIX}save' file, they are then available to be loaded at startup, which is configurable by the BootManager (the BootManager is in the System menu)
  664. If you answer \Zb\\\${T_copy}\ZB here, please \Zb\Z1FIRST, RIGHT NOW\Zn\ZB, put the \\\${DISTRO_NAME} CD into the \\\${PDEV1} drive (the same one that the CD was in at startup), if it isn't already, THEN select the \Zb\\\${T_copy}\ZB button...\"`"
  665. ${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "$T_copytitle" --colors --yes-label "$T_copy" --yesno "$yesno" 0 0
  666. RETVAL=$?
  667. clear
  668. if [ $RETVAL -eq 0 ];then
  669. #echo "Please wait, accessing CD drive..."
  670. T_waitcopy="$(gettext 'Please wait, copying .sfs files from CD...')"
  671. if [ $DISPLAY ];then #130525 remove OK button...
  672. #create nice window looking like prior ones...
  673. export COPYSFSDLG="<window decorated=\"false\">
  674. <vbox>
  675. <text use-markup=\"true\"><label>\"<big><b>${T_copytitle}</b></big>\"</label></text>
  676. <text use-markup=\"true\"><label>\"<big>${T_waitcopy}</big>\"</label></text>
  677. </vbox>
  678. </window>"
  679. GTK2_RC_FILES=/tmp/orange_gtkrc${$}:/root/.gtkrc-2.0 gtkdialog --center --class="splashwindow" --program=COPYSFSDLG & #130712
  680. cPID=$!
  681. else
  682. ${DIALOGEXE} ${BACKGROUNDORANGE} ${TITLEPARAM} "$T_copytitle" --msgbox "$T_waitcopy" 0 0 &
  683. cPID=$!
  684. fi
  685. APATTERN="/dev/$PDEV1 "
  686. CDMNTPT="`mount | grep "$APATTERN" | cut -f 3 -d ' '`"
  687. mkdir -p /mnt/$PDEV1
  688. if [ "$CDMNTPT" = "" ];then
  689. mount -t iso9660 /dev/$PDEV1 /mnt/$PDEV1
  690. CDMNTPT="/mnt/$PDEV1"
  691. fi
  692. for ONESFS in `find $CDMNTPT -maxdepth 1 -type f -name \*.sfs | grep -v ' ' | tr '\n' ' '`
  693. do
  694. BASESFS="`basename $ONESFS`"
  695. FILESIZEB=`stat --format=%s $ONESFS`
  696. FILESIZEK=`expr $FILESIZEB \/ 1024 + 2048` #2MB slack.
  697. BPATTERN=" $SMNTPT"'$'
  698. DRVFREEK=`df -k | tr -s ' ' | grep "$BPATTERN" | cut -f 4 -d ' '`
  699. if [ $DRVFREEK -gt $FILESIZEK ];then
  700. echo "`eval_gettext \"Copying \\\${BASESFS}...\"`"
  701. cp -f $ONESFS $SMNTPT/
  702. sync
  703. else
  704. T_cantcopy="`eval_gettext \"Insufficient space! Cannot copy \\\${BASESFS}\"`"
  705. echo "$T_cantcopy"
  706. [ $DISPLAY ] && pupmessage -bg red -center "$T_cantcopy"
  707. break
  708. fi
  709. done
  710. busybox umount $CDMNTPT
  711. pupkill $cPID
  712. fi
  713. fi
  714. fi
  715. } #end offersfscopy
  716. xDEVFS="$DEV1FS"
  717. xPDEV="$PDEV1"
  718. if [ "$PSAVEMARK" != "" -a "$PDEV1" != "" ];then #see /etc/rc.d/PUPSTATE
  719. devnameonly="`echo -n "$PDEV1" | sed -e 's/[0-9]*$//'`"
  720. SAVEPART="${devnameonly}${PSAVEMARK}" #partition that will-have ${DISTRO_FILE_PREFIX}save.
  721. spPATTERN='/dev/'"$SAVEPART"'|'
  722. SAVEFS="`probepart -m | grep "$spPATTERN" | cut -f 2 -d '|'`"
  723. xDEVFS="$SAVEFS"
  724. xPDEV="$SAVEPART"
  725. fi
  726. [ ! "$DEV1FS" ] && xDEVFS='xxx' #this will enable choice of create a save-file.
  727. SAVECHOICE=255
  728. # some word processing now...
  729. T_canceltitle="$(gettext 'Click close-box to cancel shutdown')"
  730. T_countdown="$(gettext 'Shutdown in TIME seconds')"
  731. T_savetofile="$(gettext 'SAVE TO FILE')"
  732. T_savetopart="`eval_gettext \"SAVE TO \\\${xPDEV}\"`"
  733. T_orwait240=""
  734. [ $TIMELIMIT -gt 0 ] && \
  735. T_orwait240=$(printf "$(gettext '(Or, wait %s seconds to shutdown without saving session)')" "$TIMELIMIT")
  736. T_save="$(gettext 'SAVE')"
  737. T_cd="$(gettext 'SAVE TO CD')"
  738. #130221 note, pupdialog will exit with 255 if click window close-box, 254 if timeout.
  739. # former, want to abort shutdown, latter, shutdown without saving.
  740. #shinobar: for all case
  741. xPSUBDIR="`echo -n "$PUPSFS" | cut -f 3 -d ',' | sed -e 's%/[^/]*$%%'`" #ex: sda3,vfat,/pup220/puppy.sfs will return /pup220
  742. T_ms="`eval_gettext \"You can save the session (all of your personal data and settings) to the storage, named '\\\${DISTRO_FILE_PREFIX}save'.
  743. Do you want to create a '\\\${DISTRO_FILE_PREFIX}save'? If unsure, it is recommended that you do save the session, so all your personal settings and files will be automatically loaded at next boot.\"`"
  744. if [ $DISPLAY ];then
  745. T_display="`eval_gettext \"Click the \Zb\\\${T_save}\ZB button to create '\\\${DISTRO_FILE_PREFIX}save' and save to it, or click \Zb\\\${T_no}\ZB to not save session...\"`" #111012 fix.
  746. yesno="$T_ms \n\n$T_display \n\n$T_orwait240"
  747. pupdialog --background '#FFFF80' --colors --title "$T_canceltitle" --backtitle "$T_title" --timeout $TIMELIMIT --countdown "$T_countdown" --no-label "$T_no" --yes-label "$T_save" --yesno "$yesno" 0 0 #120512
  748. else
  749. T_display="`eval_gettext \"Select \Zb\\\${T_save}\ZB (just press ENTER key) to create '\\\${DISTRO_FILE_PREFIX}save' and save to it, or select \Zb\\\${T_no}\ZB (TAB then ENTER) to not save session...\"`"
  750. yesno="$T_ms \n\n$T_display \n\n$T_orwait240"
  751. dialog --colors --title "$T_title" --timeout $TIMELIMIT --no-label "$T_no" --yes-label "$T_save" --yesno "$yesno" 0 0 #120512
  752. fi
  753. SAVECHOICE=$?
  754. case $SAVECHOICE in
  755. 0)
  756. if choosepartfunc; then
  757. enmount
  758. case $SAVEFS in
  759. ext?|reiserfs|minix|btrfs|f2fs) SAVEFS_IS_LINUX="y";;
  760. *) SAVEFS_IS_LINUX="";;
  761. esac
  762. SAVESTYLE='file'
  763. DENSITY=''
  764. SFEXT=''
  765. choosecrypt
  766. [ -z "$DENSITY" ] && [ "$SAVEFS_IS_LINUX" ] && choosestyle
  767. if [ "$SAVESTYLE" = "file" ]; then
  768. SFEXT='2fs'
  769. [ -z "$DENSITY" ] && choosefs
  770. choosesize || exit ###FIXME###
  771. fi
  772. if [ "$SAVESTYLE" != "partition" ]; then
  773. choosename
  774. NAMEROOT="$NAMEONLY"
  775. [ "${SFEXT}" ] && NAMEONLY="$NAMEROOT.${SFEXT}"
  776. SAVEFILE="$PSUBDIR/$NAMEONLY"
  777. #nameclash || exit ###FIXME###
  778. PUPSAVE="$SAVEPART,$SAVEFS,$SAVEFILE"
  779. fi
  780. case "$SAVESTYLE" in
  781. folder) save_directory && PUPMODE=128;;
  782. partition) PUPMODE=32;;
  783. file) pupsavefunc && PUPMODE=128;;
  784. *) "SAVESTYLE=$SAVESTYLE" ;;
  785. esac
  786. fi
  787. ;;
  788. 3)
  789. echo #case already handled above.
  790. ;;
  791. 255)
  792. exit 255 #wmreboot and wmpoweroff can cancel shutdown. 130221
  793. ;;
  794. *)
  795. echo "$(gettext 'Shutting down without saving...')"
  796. ;;
  797. esac
  798. if [ $PUPMODE -eq 128 ];then #will be saving session.
  799. offersfscopy
  800. fi
  801. #record all variables to a file...
  802. echo "PUPMODE=${PUPMODE}
  803. SAVEPART='${SAVEPART}'
  804. SAVEFS='${SAVEFS}'
  805. PUPSAVE='${PUPSAVE}'
  806. SAVEFILE='${SAVEFILE}'
  807. NAMEONLY='${NAMEONLY}'
  808. SAVEPATH='${SAVEPATH}'
  809. MYPASSWORD='${MYPASSWORD}'
  810. SFEXT='${SFEXT}'
  811. xPDEV='${xPDEV}'
  812. xDEVFS='${xDEVFS}'
  813. xPSUBDIR='${xPSUBDIR}'
  814. SMNTPT='${SMNTPT}'
  815. CRYPTO='${CRYPTO}'
  816. expBOOTDRV='${expBOOTDRV}'" > /tmp/shutdownconfig_results
  817. exit 0
  818. #the end#