Advertisement
s243a

remasterpup3 (2)

Aug 26th, 2019
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 41.30 KB | None | 0 0
  1. #!/bin/bash
  2. #simple script to remaster the puppy live-cd.
  3. #(c) Copyright 2006 Barry Kauler, www.puppyos.com
  4. #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  5. #v411 update what gets copied from /root and /etc.
  6. #v412 /etc/DISTRO_SPECS, renamed pup_xxx.sfs, pup_save.2fs etc.
  7. # 22jun09 by Masaki Shinomiya <shino@pos.to> bugfix in cd drive selection
  8. # 01jul09 needed space calculation
  9. # 08jul09 loop mounted iso file usable
  10. # 7aug09 grub4dos support
  11. #w482 shinobar: exclude /lib/modules/${KERNELVER}/initrd.
  12. #v431JP mkisofs with Joliet option, volume id, what copied from cd, remove slmodems
  13. #091212 weird bug, no processes but when run this, x restarts...
  14. # 28dec09 remove /modules/${KERNELVER}/modules.*
  15. #110505 support sudo for non-root user.
  16. #110808 PANZERKOPF: bug fix. 110822 reverted.
  17. #120605 rerwin: omit /dev/snd content, /dev/.udev subdirectory and modem daemons from new master (because daemons reinstalled from firmware if needed).
  18. #120606 rerwin: support users' replacement of stripped /root & /etc with complete directories (for "boot disk").
  19. #120607 rerwin: Remove indicators/files for integrated user-installed packages.
  20. #120721 revert 'wildcards' option (from 120605); improve /dev/snd file exclusion; exclude /usr/share/icons/hicolor/icon-theme.cache (shinobar).
  21. #121021 rerwin: revert 120605 modem daemon removals (because daemons no longer copied from firmware directory).
  22. #130222 convert internationalization from "technosaurus method" to gettext method.
  23. #130222 virtual-CD detection was broken.
  24. #130223 various fixes. note, also fixed /usr/sbin/filemnt. now can retain files between remasters.
  25. #130301 o/p of "losetup" (BB), shows all in use, but "losetup-FULL -a" needs param, also o/p format different.
  26. #130302 L18L: moved m_09 m_10 m_11 top and made another use of it.
  27. #130306 gettext translation fixed, line 354. 130307 again.
  28. #130308 npierce: filter out wrong CDs from choices offered to user; remove CD drive from VIRTUALCD list.
  29. #130527 /etc/.XLOADED has been moved to /root, refer /usr/bin/xwin.
  30.  
  31. [ "`whoami`" != "root" ] && exec sudo -A ${0} ${@} #110505
  32. TMP=/tmp/remasterpup2
  33. #NOTE: rename to avoid clash with 'remasterpup2.mo' used by previous i18n method.
  34. export TEXTDOMAIN=remasterpup2x
  35. export OUTPUT_CHARSET=UTF-8
  36. . gettext.sh
  37.  
  38. set_home_action(){
  39.        etc_action=${etc_action:-"$1"}    
  40.        root_action=${root_action:-"$1"}
  41.        spot_action=${spot_action:-"$1"}
  42.        fido_action=${fido_action:-"$1"}
  43.        puppy_action=${puppy_action:-"$1"}  
  44. }
  45.  
  46. TEMP=`getopts -o ae:r:p:f: --long auto,:etc,root:,home:,spot:,fido -- "$@"`
  47. eval set -- "$TEMP"
  48. while true;  do
  49.   case "$1" in
  50.     -a|--auto)
  51.       set_home_action "default"
  52.       customize_etc=${customize_etc:-no} #Don't customize ect based on hardware
  53.       MK_NEW_ISO_ROOT=${MK_NEW_ISO_ROOT:-yes}
  54.     -e|--etc) etc_action=$2; shift 2; ;;
  55.     -r|--root) root_action=$2; shift 2; ;;  
  56.     -s|--spot) spot_action=$2; shift 2; ;;  
  57.     -f|--fido) fido_action=$2; shift 2; ;;  
  58.     -p|--puppy) puppy_action=$2; shift 2; ;;  
  59.     -h|--home)
  60.        set_home_action "$2"
  61.        shift 2
  62.        ;;
  63.     -i|--iso-root-old) ISO_ROOT_old="$2"; shift 2; ;;
  64.     -n|--make-new-isoroot) MK_NEW_ISO_ROOT="$2"; shift 2; ;;      
  65.     -o|--iso-root-new) ISO_ROOT_new="$2"; shift 2; ;;
  66.     -w|--working-partition)      
  67.       WKGPART="$2"; shift 2; ;;
  68.     -m|--working-mount-point)
  69.       WKGMNTPT="$2"; shift 2; ;;
  70.     -c|--customize customize_etc=$2
  71.      ;;
  72.   esac
  73. done
  74.  
  75. Yes_lbl="$(gettext 'Yes')"
  76. No_lbl="$(gettext 'No')"
  77. m_01="$(gettext 'Puppy simple CD remaster')" #window title.
  78. m_02="$(gettext 'ERROR')"
  79. m_07="$(gettext 'currently mounted')"
  80. m_08="$(gettext 'not mounted')"
  81. m_09="$(gettext 'Filesystem')" #130302
  82. m_10="$(gettext 'Size')" #130302
  83. m_11="$(gettext 'Free')" #130302
  84.  
  85. choice_cdd () {
  86.     #copy files off live-cd.... w018 use probedisk2...
  87.     SELECTIONS="`probedisk 2>&1 | grep '^/dev/' | grep "|optical|" | cut -f 1,3 -d "|" | tr " " "_" | tr "|" " " | tr '$' "_"`"
  88.     SELECTIONS="$SELECTIONS $VIRTUALCD"
  89.     if [ "$(echo "$SELECTIONS"|tr -d ' ')" = "" ]; then
  90.         m_14_2="$(gettext 'NO CD/DVD drives found.')"
  91.         Xdialog --wrap --left --title "$m_01: $m_02" --msgbox "$m_14_2
  92. $MSG" 0 80
  93.         exit 1
  94.     fi
  95.     if [ "$1" = "filter" ];then #130308 Filter out devices with a missing file.
  96.         FILT_SELECTIONS=""
  97.         i="0"
  98.         for ASELECTION in $SELECTIONS
  99.         do
  100.             if [ "$((i++&1))" -eq "0"  ];then
  101.                 BLKDEV="$ASELECTION"
  102.             else
  103.                 DEVNAME="$ASELECTION"
  104.                 MNTPNT="`mount | grep "$BLKDEV" | tr -s " " | cut -f 3 -d " "`"
  105.                 [ -z "$MNTPNT" -o -f "$MNTPNT/initrd.gz" -a -f "$MNTPNT/$PUPPYSFS" ] && FILT_SELECTIONS="$FILT_SELECTIONS $BLKDEV $DEVNAME"
  106.             fi
  107.         done
  108.         SELECTIONS="$FILT_SELECTIONS"
  109.         if [ -z "$SELECTIONS" ];then
  110.             m_14_3="$(gettext 'Puppy live-CD or virtual CD was not found.')
  111. $(eval_gettext "(No CD or .iso file has both 'initrd.gz' and '${PUPPYSFS}'.)")"
  112.             Xdialog --wrap --left  --title "$m_01: $m_02" --msgbox "$m_14_3" 0 0
  113.             exit
  114.         fi
  115.     fi #130308 end of filter
  116.     m_14_1="$(gettext 'Choose the CD/DVD drive...')"
  117.     DIALOG="Xdialog --wrap --left --title \"$m_01\" --stdout --menubox \"$MSG\n\n$m_14_1\" 0 56 4 $SELECTIONS 2> /dev/null"
  118.     BURNERDRV=""
  119.     RESULT=$(eval $DIALOG) #w018    # 22jun09
  120.     [ $? -ne 0 ] && exit
  121.     BURNERDRV=$RESULT
  122.     [ "$BURNERDRV" = "" ] && exit
  123.     BURNERDRV="`echo -n "$BURNERDRV" | cut -f 3 -d '/'`"
  124. }
  125.  
  126. #LANG=C #faster, plus Xdialog happier.
  127. KERNELVER="`uname -r`"
  128.  
  129. #variables created at bootup by /initrd/usr/sbin/init...
  130. . /etc/rc.d/PUPSTATE
  131. [ "$PUP_LAYER" = "" ] && PUP_LAYER="/pup_ro2"
  132.  
  133. . /etc/DISTRO_SPECS
  134. PUPPYSFS="$DISTRO_PUPPYSFS" #ex: puppy.sfs
  135. PUPSFS_ROOT="${PUPPYSFS%.sfs}"
  136. ZDRVSFS="$DISTRO_ZDRVSFS"   #ex: zdrv.sfs
  137. SFSBASE="`basename $PUPPYSFS .sfs`" #ex: puppy
  138.  
  139.  
  140. PPATTERN="/initrd${PUP_LAYER}"
  141. if [ "`mount | grep "$PPATTERN"`" = "" ];then
  142.     #no puppy.sfs file mounted on pup_ro2, probably h.d. install...
  143.     m_03="$(eval_gettext 'This program requires a ${PUPPYSFS} file mounted on /initrd${PUP_LAYER}.')
  144. $(gettext 'Which is not the case here, probably because this is a full hard drive installation?')
  145. $(gettext 'Whatever, boot Puppy from live-CD and then you will be able to use this script.')
  146.  
  147. $(eval_gettext 'Note, I have not tried it, but if you setup the situation of ${PUPPYSFS} mounted on directory /initrd${PUP_LAYER}, that will be acceptable for this program.')
  148. $(gettext 'You will also need a current live-CD, as the program gets files off it.')
  149. $(gettext 'Anyone want to try it?')
  150.  
  151. $(gettext "Click 'Ok' button to quit...")"
  152.     Xdialog --wrap --left --title "m_01: m_02"  --msgbox "$m_03" 0 80
  153.     exit
  154. fi
  155.  
  156. SAVEPART="$PDEV1" #from PUPSTATE.
  157. CDR="/dev/$SAVEPART"
  158.  
  159. #choose where to create isolinux-builds/ directory...
  160. m_05="$(gettext 'Welcome! This little program takes a snapshot of your current system and create a ISO file.')
  161.  
  162. $(eval_gettext 'A Puppy live-CD has 4 main files: vmlinuz, isolinux.cfg, initrd.gz and ${PUPPYSFS}. Note, in some builds of Puppy there may also be a 5th file, ${ZDRVSFS}.')
  163.  
  164. $(eval_gettext "It is \${PUPPYSFS} that mainly interests us here: it has the entire Puppy filesystem, everything from '/' down. What this script does is rebuild this file \${PUPPYSFS}, with everything currently under '/' -- that is, all user-installed packages, all mounted .sfs extension files, everything, gets combined into one file, \${PUPPYSFS}.")
  165. $(eval_gettext "Note, if you have an 'underdog Linux' mounted, that too will get combined into the \${PUPPYSFS} file, so beware, it could get big!")
  166.  
  167. $(gettext 'Click OK button to continue (or close window to quit)...')"
  168. Xdialog --wrap --left --title "$m_01" --msgbox "$m_05" 0 80
  169.  
  170. [ $? -ne 0 ] && exit
  171.  
  172. #calc size needed...
  173. m_06="$(gettext 'Calculating needed working space.')
  174. $(gettext 'Please wait, this may take awhile...')"
  175. Xdialog --wrap --left  --title "$m_01" --no-buttons --ignore-eof  --infobox "$m_06" 0 0 0 &
  176. XPID=$!
  177. SIZEOPT=0
  178. SIZEBIN=`du -sk /bin | cut -f 1`
  179. SIZESBIN=`du -sk /sbin | cut -f 1`
  180. SIZELIB=`du -sk /lib | cut -f 1`
  181. SIZEUSR=`du -sk /usr | cut -f 1`
  182. SIZEOPT=0   # 01jul09
  183. [ -d /opt ] && SIZEOPT=`du -sk /opt | cut -f 1`
  184. sync
  185. SIZETOTALK=`LANG=C dc $SIZEBIN $SIZESBIN + $SIZELIB + $SIZEUSR + $SIZEOPT + p`
  186. SIZETOTALM=`LANG=C dc $SIZETOTALK 1024 \/ p| cut -d'.' -f1` # 01jul09
  187. [ "$SIZETOTALM" ] || SIZETOTALM=1
  188. #estimate a compressed size...
  189. SIZENEEDEDM=`expr $SIZETOTALM \/ 3`
  190. SIZESLACKM=`expr $SIZENEEDEDM \/ 3` #guess
  191. SIZENEEDEDM=`expr $SIZENEEDEDM + $SIZESLACKM`
  192. SIZENEEDEDM=`expr $SIZENEEDEDM + 25` #space for vmlinuz, initrd.gz, zdrv, etc
  193. #now choose working partition... v431 add ext4...  130216 add f2fs...
  194. PARTSLIST="`probepart -m 2> /dev/null | grep '^/dev/' | grep -E 'f2fs|ext2|ext3|ext4|reiserfs|btrfs|minix|msdos|vfat|exfat|ntfs' | cut -f 1-3 -d '|'`"
  195.  
  196.  
  197. if [ -z "$WKGPART" ]; then
  198.  echo -n "" > "${TMP}"/schoices.txt
  199.  echo "$PARTSLIST" |
  200.  while read APART
  201.  do
  202.     [ "$APART" = "" ] && continue #v3.01 preaution
  203.     MNTSTATUS="($m_07)" #"currently mounted"
  204.     ATAG="`echo -n "$APART" | cut -f 1 -d '|' | cut -f 3 -d '/'`"
  205.     ASIZE="`echo -n "$APART" | cut -f 3 -d '|'`"
  206.     AFS="`echo -n "$APART" | cut -f 2 -d '|'`"
  207.     AFPATTERN="^/dev/$ATAG " #v3.01
  208.     AFREE="`df -m | grep -m 1 "$AFPATTERN" | tr -s " " | cut -f 4 -d " "`"
  209.     FLAG_RO='no' #v431
  210.     if [ ! "$AFREE" ];then
  211.         MNTSTATUS="($m_08)" #"not mounted"
  212.         mkdir -p /mnt/$ATAG
  213.         mount -t $AFS /dev/$ATAG /mnt/$ATAG > /dev/null 2>&1
  214.         if [ $? -eq 0 ];then
  215.             if [ "$ATAG" = "fd0" ];then
  216.                 FFREE=`df -k | grep -m 1 "$AFPATTERN" | tr -s " " | cut -f 4 -d " "`
  217.                 AFREE="`LANG=C dc $FFREE 1024 \/ p`"
  218.             else
  219.                 AFREE="`df -m | grep -m 1 "$AFPATTERN" | tr -s " " | cut -f 4 -d " "`"
  220.             fi
  221.             [ "`mount | grep -m 1 "$AFPATTERN" | grep ' (rw'`" = "" ] && FLAG_RO='yes' #v431 make sure writable.
  222.             umount /dev/$ATAG
  223.         else #v431
  224.             continue
  225.         fi
  226.     else
  227.         [ "`mount | grep -m 1 "$AFPATTERN" | grep ' (rw'`" = "" ] && FLAG_RO='yes' #v431 make sure writable.
  228.     fi
  229.     [ "$FLAG_RO" = "yes" ] && continue #v431
  230.     [ "$AFS" ] && echo "${ATAG} \"${m_09}: $AFS  ${m_10}: ${ASIZE}M  ${m_11}: ${AFREE}M ${MNTSTATUS}\" \\" >> "${TMP}"/schoices.txt #v3.01 added precaution. #130302 L18L
  231.   done
  232.   SCHOICES="`cat "${TMP}"/schoices.txt`"
  233.  
  234.   #add tmpfs ramdisk choice...
  235.   SIZETMPFSM=`df -m | grep '^tmpfs' | grep -E "/initrd/pup_rw|/initrd/mnt/tmpfs" | tr -s " " | cut -f 4 -d " "`
  236.   TMPFSMSG=''
  237.  
  238.   if [ "$SIZETMPFSM" != "" ];then
  239.     TOTALTMPFSM=`df -m | grep '^tmpfs' | grep -E '/initrd/pup_rw|/initrd/mnt/tmpfs' | tr -s " " | cut -f 2 -d " "`
  240.     if [ "$SCHOICES" = "" ];then #v3.01
  241.         SCHOICES="ramdisk \"$m_09: tmpfs  $m_10: ${TOTALTMPFSM}M  $m_11: ${SIZETMPFSM}M ($m_07)\" \\"
  242.     else
  243.         SCHOICES="$SCHOICES
  244. ramdisk \"$m_09: tmpfs  $m_10: ${TOTALTMPFSM}M  $m_11: ${SIZETMPFSM}M ($m_07)\" \\"
  245.     fi
  246.     m_12="$(gettext 'Note 2: you can use the tmpfs ramdisk, which is in RAM, if it has enough space.')"
  247.     TMPFSMSG="$m_12
  248. "
  249.   fi
  250.  
  251.   [ "$SCHOICES" = "" ] && exit #precaution.
  252.  
  253. m_13="$(gettext 'A working area is required in which to create the new live-CD iso file.')
  254. $(eval_gettext 'Here are the available partitions. You must choose one that has at least ${SIZENEEDEDM}M free space on it.') $(gettext 'You will need an extra 100 - 300MB space (whatever the size of ISO file is going to be).')
  255.  
  256. $(eval_gettext 'If the partition that you would like to use has less than ${SIZENEEDEDM}M free space on it, you will need to quit this script and delete some files.')
  257.  
  258. $(gettext 'Note 1: you can use a usb drive, but it needs to have been plugged in before running this script, so that it will get detected.')
  259. ${TMPFSMSG}
  260. $(gettext 'Highlight desired choice then click OK button...')"
  261.   echo '#!/bin/sh' > "${TMP}"/savedlg
  262.   echo -n "Xdialog --wrap --left --stdout --title \"$m_01\" --menubox \"$m_13\" 0 80 5 " >> "${TMP}"/savedlg
  263.   echo "$SCHOICES"  >> "${TMP}"/savedlg
  264.   echo ' > "${TMP}"/tag.txt' >> "${TMP}"/savedlg
  265.   chmod 755 "${TMP}"/savedlg
  266.  
  267.   kill $XPID
  268.   "${TMP}"/savedlg
  269.   [ $? -ne 0 ] && exit #130223
  270.   WKGPART="`cat "${TMP}"/tag.txt`"
  271.   echo "WKGPART=$WKGPART"
  272.   [ "$WKGPART" = "" ] && exit
  273. fi #End selecting working partition.
  274.  
  275.  
  276. #now get the files off it...
  277. #firstly need working place to write to...
  278. [ "$WKGPART" = "ramdisk" ] && WKGMNTPT="/"
  279. WPATTERN="/dev/$WKGPART "
  280. if [ "$WKGMNTPT" = "" ] ; then
  281.     WKGMNTPT="`mount | grep "$WPATTERN" | head -n 1 | tr -s " " | cut -f 3 -d " "`"
  282. fi
  283. if [ "$WKGMNTPT" = "" ];then
  284.     PPATTERN="^$WKGPART "
  285.     WKGFS="`echo "$SCHOICES" | grep "$PPATTERN" | cut -f 2 -d ':' | cut -f 2 -d " "`"
  286.     [ "$WKGFS" = "msdos" ] && WKGFS="vfat"
  287.     mkdir -p /mnt/$WKGPART
  288.     mount -t $WKGFS /dev/$WKGPART /mnt/$WKGPART
  289.     [ $? -ne 0 ] && exit #precaution.
  290.     WKGMNTPT="/mnt/$WKGPART"
  291. fi
  292. [ "$WKGMNTPT" = "/" ] && WKGMNTPT=""
  293.  
  294. # reuse if sfs file already exists
  295. NEW="yes"
  296. [ -z "$ISO_ROOT_new" ] && ISO_ROOT_new="$WKGMNTPT/puppylivecdbuild"
  297. SFSPATH=$(ls -1 "${ISO_ROOT_new}/$PUPPYSFS" 2>/dev/null)
  298. if [ ! -z "$MK_NEW_ISO_ROOT" ]; then
  299.   NEW="$MK_NEW_ISO_ROOT"
  300. elif [ "$SFSPATH" != "" -a $(echo "$SFSPATH" | wc -l) -eq 1 ]; then
  301.     m_35="$(eval_gettext '${SFSPATH} found.')
  302. $(gettext 'Do you want to reuse it without any change?')
  303. $(gettext "If uncertain, click the 'No' button")"
  304.     Xdialog --wrap --left --title "$m_01" --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "$m_35" 0 0 && NEW="no"
  305. fi
  306. SFSPATH=""
  307.  
  308. #=================================================================
  309.  
  310. if [ "$NEW" = "yes" ]; then  ###### long skip if, cleating new sfs
  311.     #130223 i think should wipe contents of "$ISO_ROOT_new"?
  312.     if [ -d "${ISO_ROOT_new}" ];then
  313.         [ -f "${ISO_ROOT_new}"/$PUPPYSFS ] && rm -f "${ISO_ROOT_new}"/$PUPPYSFS
  314.         [ -f "${ISO_ROOT_new}"/$ZDRVSFS ] && rm -f "${ISO_ROOT_new}"/$ZDRVSFS
  315.         m_41="$(eval_gettext 'Directory ${WKGMNTPT}/puppylivecdbuild already exists.')
  316.  
  317. $(gettext "Normally, this would be created fresh, empty. However, it exists from a previous execution of 'remasterpup2' script (this program), with files in it. You may choose to leave these files in-place, for the current remaster. If uncertain, click the 'Erase' button.")
  318.  
  319. $(gettext 'Note, if you choose to retain the files: The next operation is this script will will read files from a CD, however they will not over-write existing files. Therefore, any customised files will be retained.')
  320.  
  321. $(gettext "WARNING: If the files in 'puppylivecdbuild' are for a different version of Puppy, click the 'Erase' button.")
  322. $(gettext "Again, warning, if at all uncertain, click the 'Erase' button.")
  323.  
  324. $(gettext "Click 'Keep' button to retain the files...")
  325. $(gettext "Click 'Erase' button to delete the files...")"
  326.         lbl_41="$(gettext 'Keep')"
  327.         lbl_42="$(gettext 'Erase')"
  328.         Xdialog --wrap --left --title "$m_01" --ok-label "$lbl_41" --cancel-label "$lbl_42" --yesno "$m_41" 0 80
  329.         [ $? -ne 0 ] && rm -rf "${ISO_ROOT_new}"
  330.     fi
  331.  
  332.     #130222
  333.     #130307 notice, line 356 "WARNING:....", the $ is not backslashed, which is confusing...
  334.     m_42=""
  335.     #if [ -d "${ISO_ROOT_new}" ];then #TODO: s243a need to decide where to close this if.
  336.         m_42="$(gettext 'NOTICE:')
  337. $(eval_gettext 'Directory ${WKGMNTPT}/puppylivecdbuild already exists.')
  338. $(gettext 'If you want to re-use the files in it, and not re-read files from the CD (or virtual-CD), just click the window close-box to bypass this operation.')
  339. $(gettext '(You may view the directory contents with a file-manager to satisfy yourself whether these files should be re-used)')"
  340.     fi
  341.     if [ -z "$ISO_ROOT_old" ]; then
  342.       m_40="$(gettext 'This remaster program needs to read some files off the current live-CD.')
  343.  
  344. $(gettext "However, if a CD-image file (which has filename extension .iso) is mounted, the files may be read from that. We refer to this as a 'virtual CD'. To mount a virtual CD, just click on a .iso file.")
  345.  
  346. $(eval_gettext "WARNING: Be sure that the live-CD or .iso file is the correct one for the currently running Puppy, which is '\${DISTRO_NAME}', version \${DISTRO_VERSION}. As a check, it must have in it the file '\${DISTRO_PUPPYSFS}'")
  347.  
  348. $(gettext "If you want to read the files off a .iso file rather than a CD/DVD, please click on the .iso file right now (before clicking the 'OK' button below)")
  349. $(gettext "Alternatively, if you want to read the files off a Puppy live-CD, insert it in drive, then click 'OK' button.")${m_42}"
  350.       Xdialog --wrap --left  --title "$m_01" --msgbox "$m_40" 0 80
  351.  
  352.       if [ $? -eq 0 ];then #130223 big if "BIGIF2"
  353.         #130222 fix this...
  354.         VIRTUALCD=""
  355.         #130301 crap, earlier was using losetup-FULL from util-linux git, now using older 2.21.1, it needs -a param,
  356.         #but also truncates long lines (same as bb losetup) -- what a nuisance...
  357.         for ONELOOP in `cat /proc/mounts | grep -E '(^/dev/loop.*)( udf | iso9660 )' | cut -f 1 -d ' ' | tr '\n' ' '` #130308 /dev/loop only
  358.         do
  359.             oPTN="^${ONELOOP} "
  360.             ONEISO="$(cat /proc/mounts | grep "$oPTN" | cut -f 2 -d ' ' | rev | cut -f 1 -d '+' | cut -f 1 -d '/' | rev)" #130301
  361.             [ "$ONEISO" = "" ] && continue #130301 precaution.
  362.             ONELOOP=$(echo "$ONELOOP" | sed 's|/loop/|/loop|')
  363.             VIRTUALCD="${VIRTUALCD} ${ONELOOP} ${ONEISO}"
  364.         done
  365.         m_14="$(gettext 'This remaster program needs to read some files off the current live-CD.')
  366. $(gettext 'You can also use a .iso file if it is already mounted as a virtual CD (you would need to have previously clicked on a .iso file to mount it).')"
  367.         MSG="$m_14"
  368.         choice_cdd filter #130308 Use filtering.
  369.  
  370.         CDPATTERN="/dev/$BURNERDRV "
  371.         CDMNTPT="`mount | grep "$CDPATTERN" | tr -s " " | cut -f 3 -d " "`"
  372.         if [ "$CDMNTPT" != "" ];then
  373.             if [ ! -f $CDMNTPT/initrd.gz ];then #130308 In theory, this will now never be true.
  374.                 #091212 weird bug, no processes but when run this, x restarts...
  375.                 xFUSER="`fuser -m /dev/$BURNERDRV 2>/dev/null`" #do this first, seems to fix it.
  376.                 [ "$xFUSER" != "" ] && fuser -k -m /dev/$BURNERDRV
  377.                 sync
  378.                 umount /dev/$BURNERDRV 2> /dev/null
  379.                 if [ $? -ne 0 ];then
  380.                     m_15="$(gettext 'Mounted CD, get rid of it before running this program!')"
  381.                     Xdialog --wrap --left  --title "$m_02" --msgbox "$m_15" 0 0
  382.                     exit
  383.                 fi
  384.                 CDMNTPT=""
  385.             fi
  386.         fi
  387.  
  388.         if [ "$CDMNTPT" = "" ];then
  389.             m_16="$(eval_gettext 'Please insert the current Puppy live-CD into drive ${BURNERDRV}.')
  390. $(gettext 'Then click OK...')"
  391.             while [ 1 ];do
  392.                 Xdialog --wrap --left  --title "$m_01" --msgbox "$m_16" 0 0
  393.                 [ $? -eq 0  ] || exit   # 22jun09
  394.                 case $BURNERDRV in
  395.                     loop*) #ISO.. already mounted
  396.                         CDMNTPT=$(mount | grep "^/dev/$BURNERDRV " | cut -f 3 -d ' ')
  397.                         ;;
  398.                     *) #CD
  399.                         #now mount it...
  400.                         CDMNTPT="/mnt/$BURNERDRV"
  401.                         mkdir -p /mnt/$BURNERDRV
  402.                         mount -t iso9660 /dev/$BURNERDRV /mnt/$BURNERDRV
  403.                         [ $? -eq 0 ] && break
  404.                         ;;
  405.                 esac
  406.             done
  407.         fi
  408.  
  409.         #now get the files off it...
  410.         m_17="$(eval_gettext 'Copying files from CD to ${WKGMNTPT}/puppylivecdbuild/, please wait...')"
  411.         Xdialog --wrap --left  --title "$m_01" --no-buttons --ignore-eof   --infobox "$m_17" 0 0 0 &
  412.         XPID=$!
  413.         mkdir -p "${ISO_ROOT_new}"
  414.         #now copy the files... # v431JP HTM, ICO, INF
  415.         sync
  416.         (
  417.         cd $CDMNTPT
  418.         for F in ${ZDRVSFS} vmlinuz initrd.gz  grldr *efi* *EFI* *.c32 *.sh *.lst *.xpm *.jpg *.png *.bin *.cfg *.msg *.16 *.HTM* *.ICO *.INF help
  419.         do
  420.             #130223 -n means do not override an existing file... 130304 hmmm, -n not supported, use -u ...
  421.             [ -e "$F" ] && cp -a -u $F "${ISO_ROOT_new}"/
  422.             sync
  423.         done
  424.         )
  425.         umount /dev/$BURNERDRV 2> /dev/null
  426.         kill $XPID
  427.  
  428.     fi #end "BIGIF2"
  429.  
  430.     m_16_1="$(eval_gettext 'Do you like to make ${ZDRVSFS}, the separate driver file?')"
  431.     Xdialog --wrap --left  --title "$m_01" --default-no --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "$m_16_1" 0 0
  432.     [ $? -eq 0 ] && MKZDRV="yes" || MKZDRV=""
  433.     [ $? -eq 255 ] && exit #130223
  434.  
  435.     # set compression
  436.     /usr/lib/gtkdialog/box_yesno --yes-label "xz (default)" --no-label "gzip" --yes-first --info \
  437.     --yes-icon "execute.svg" --no-icon "execute.svg" \
  438. "$m_01" "$(gettext 'You can use xz or gzip compression. Choose one...')"
  439.     case $? in
  440.         1) COMP="-comp gzip" ;;
  441.         *) COMP="-comp xz -Xbcj x86" ;;
  442.     esac
  443.     #COMP="-noI -noD -noF -noX" #fast tests zzzzzz
  444.     echo "COMP=${COMP}"
  445.     # -
  446.  
  447.     m_18="$(eval_gettext 'Creating the ${PUPPYSFS} file in ${WKGMNTPT}/puppylivecdbuild/.')
  448. $(gettext 'This can take quite a long time, so please wait.... and wait...')
  449. $(eval_gettext 'This window will disappear when ${PUPPYSFS} is finally created.')
  450. $(gettext 'Please wait...')"
  451.     Xdialog --wrap --left  --title "$m_01" --no-buttons --ignore-eof   --infobox "$m_18" 0 0 0 &
  452.     XPID=$!
  453.  
  454.     #create new puppy.sfs file...
  455.     squash() {
  456.         echo $0 $@
  457.         rxvt -bg orange -fg black -title "$m_01" -geometry 80x6 -e mksquashfs $@ 2> /dev/null
  458.     }
  459.    fk_squash() {
  460.         echo $0 $@
  461.         #s243a: use set -x to echo cpio commands in fk_mksquashfs and pass to rxvt
  462.         #rxvt -bg orange -fg black -title "$m_01" -geometry 80x6 -e mksquashfs $@ 2> /dev/null
  463.         fk_mksquashfs $@ #Short term hack
  464.     }
  465.     do_squash(){
  466.       if [ "$mode" = dir ]; then
  467.         fk_squash $@    
  468.       else
  469.         squash $@
  470.       fi
  471.     }  
  472.     fk_mksquashfs(){
  473.       #source_dir=$1; shift
  474.       #target_dir=$2; shift
  475.      option=""
  476.      out=() #Currently not used
  477.      args=()
  478.      declare -A exludes
  479.       for arg in "$@";do
  480.         if [[ "$arg" == -* ]]; then
  481.           case "$arg" in
  482.           -*)
  483.           option="$arg" ;;
  484.           esac  
  485.         else
  486.           case option in
  487.           -e)
  488.             exludes+=( ["$arg"]=1 ) ;;
  489.           '')
  490.             args+=( "$arg" ) ;;
  491.           *)
  492.             out+=( "$arg" ) ;;
  493.           esac
  494.         fi
  495.       done
  496.       n_args=${#args}
  497.       target_dir=$args[$n_args]
  498.       target_dir="${target_dir%.sfs}"
  499.      
  500.       mkdir -p "$target_dir"
  501.       unset 'args[$n_args-1]' #https://stackoverflow.com/questions/8247433/remove-the-last-element-from-an-array
  502.       #while read aDir; do
  503.       if [ realpath "$target_dir" != "/" ]; then
  504.        for aDir in "$args[@]"; do
  505.           excluded="${excludes[$aDir]}"
  506.           [ -z "$excluded" ] && excluded=0
  507.           if [ ! $excluded -eq 1 ]; then
  508.             cd $aDir
  509.             cpio -pd "$target_dir"
  510.           fi
  511.         done
  512.       fi
  513.       #done < <(ls -a -1)
  514.      
  515.     }  
  516.     do_mksquashfs(){
  517.       if [ "$mode" = dir ]; then
  518.         fk_mksquashfs $@    
  519.       else
  520.         mksquashfs $@
  521.       fi
  522.     }          
  523.    
  524.     DIRHOME=""
  525.     [ -d /home ] && DIRHOME="/home"
  526.     [ -d /sys ] && DIRSYS="/sys"
  527.     [ -d /lost+found ] && DIRLOST="/lost+found"
  528.     rm -f ${WKGMNTPT}/puppylivecdbuild/$PUPPYSFS 2> /dev/null
  529.     sync
  530.     #note, /puppy.sfs is not normally there, i relocated it to a separate tmpfs,
  531.     #however have not yet done that for multisession-cd/dvd (PUPMODE=77).
  532.     #note, /home could be in underdog linux...
  533.  
  534.     # modules copied from initrd
  535.     ANOTHER_REMOVE="/lib/modules/$KERNELVER/initrd /lib/modules/*/modules.*"    # 28dec09 modules.*
  536.     if [ "$MKZDRV" = "yes" ]; then
  537.         rm -f "${ISO_ROOT_new}"/$ZDRVSFS 2> /dev/null
  538.         do_mksquashfs /lib "${ISO_ROOT_new}"/$ZDRVSFS -keep-as-directory -e /lib/[^m]* $ANOTHER_REMOVE
  539.         ANOTHER_REMOVE="/lib/modules"
  540.     fi
  541.     #120605 Omit certain /dev subdir content and modem components loaded from firmware tarballs...
  542.     [ -d /dev/snd ] && [ "`ls /dev/snd`" != "" ] && DIRDEVSNDFILES="/dev/snd/*" #120721
  543.     [ -d /dev/.udev ] && DIRDEVUDEV="/dev/.udev"
  544.     #121021 modem daemons now left in place.
  545.     [ -f /usr/share/icons/hicolor/icon-theme.cache ] && ICONCACHE=/usr/share/icons/hicolor/icon-theme.cache #120721
  546.     TOPPLCDB=''
  547.     [ -e /puppylivecdbuild ] && TOPPLCDB='/puppylivecdbuild'
  548.     TOPPUPSFS=''
  549.     [ -e /${PUPPYSFS} ] && TOPPUPSFS="/${PUPPYSFS}"
  550.    
  551.  
  552.  
  553.     # display terminal only for the first stage because it takes the most of time. 'squash' is a function, see above. 120512 $COMP added...
  554.     do_squash / "${ISO_ROOT_new}"/$PUPPYSFS ${COMP} -e /media /etc /proc /initrd /var /tmp /archive /mnt /root $TOPPLCDB $ANOTHER_REMOVE $DIRHOME $DIRSYS $DIRLOST $TOPPUPSFS $DIRDEVSNDFILES $DIRDEVUDEV $ICONCACHE  #120605 end #120721 avoid wildecards option, icon-theme.cache 121021
  555.     sync
  556.  
  557.     #add pristine folders (out of current puppy.sfs)...
  558.     do_mksquashfs /initrd${PUP_LAYER}/home "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  559.     sync
  560.     do_mksquashfs /initrd${PUP_LAYER}/proc "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  561.     sync
  562.     do_mksquashfs /initrd${PUP_LAYER}/tmp "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  563.     sync
  564.     do_mksquashfs /initrd${PUP_LAYER}/mnt "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  565.     sync
  566.     do_mksquashfs /initrd${PUP_LAYER}/media "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  567.     sync
  568.  
  569.     kill $XPID
  570.  
  571.     #######START WORKING ON /root#######
  572. for aUser in root spot fido puppy; do
  573.     rm -rf "${TMP}""${aHome}" 2> /dev/null
  574.    aHOME=$(eval echo "~$aUser")
  575.    mkdir -p "${TMP}${aHome}"
  576.     #do some work on "$aHome" before add it to the squashfs...
  577.     cp -a /initrd${PUP_LAYER}"${aHome}" "${TMP}""${aHome}" #pristine "$aHome"
  578.     #copy all of my-applications/
  579.     cp -af "${aHome}"/my-applications/* "${TMP}${aHome}/my-applications/"
  580.     #some dotpups get installed here...
  581.     cp -af "${aHome}/my-roxapps" "${TMP}${aHome}/" 2>/dev/null
  582.     #window manager config files...
  583.     cp -af "${aHome}/.jwmrc" "${TMP}${aHome}/"
  584.     cp -af "${aHome}/.jwmrc-tray" "${TMP}${aHome}/" #v411
  585.     cp -af "${aHome}/.fvwm95rc" "${TMP}${aHome}/"
  586.     cp -af "${aHome}/.icewm/menu" "${TMP}${aHome}/.icewm/"
  587.     #rox desktop settings...
  588.     cp -af "${aHome}/Choices/ROX-Filer/PuppyPin" "${TMP}${aHome}/Choices/ROX-Filer/"
  589.     cp -af "${aHome}/Choices/ROX-Filer/globicons" "${TMP}${aHome}/Choices/ROX-Filer/"
  590.     #100117 user changes get saved here, which overrides original...
  591.     if [ -f "${aHome}/.config/rox.sourceforge.net/ROX-Filer/globicons" ];then
  592.         mkdir -p "${TMP}${aHome}/.config/rox.sourceforge.net/ROX-Filer/"
  593.         cp -af "${aHome}/.config/rox.sourceforge.net/ROX-Filer/globicons" "${TMP}${aHome}/.config/rox.sourceforge.net/ROX-Filer/"
  594.     fi
  595.     #100117 i think also save user settings...
  596.     if [ -f "${aHome}/.config/rox.sourceforge.net/ROX-Filer/Options" ];then
  597.         mkdir -p "${TMP}${aHome}/.config/rox.sourceforge.net/ROX-Filer/"
  598.         cp -af "${aHome}/.config/rox.sourceforge.net/ROX-Filer/Options" "${TMP}${aHome}/.config/rox.sourceforge.net/ROX-Filer/"
  599.     fi
  600.     #v411 tidy up, remove desktop drive icons...
  601.     grep -v '"${TMP}"/pup_event_frontend/drive_' "${TMP}${aHome}/Choices/ROX-Filer/PuppyPin" > "${TMP}"/remaster-PuppyPin
  602.     mv -f "${TMP}/remaster-PuppyPin" "${TMP}${aHome}/Choices/ROX-Filer/PuppyPin"
  603.     #this may have been modified for a different w.m...
  604.     cp -af "${aHome}/.xinitrc" "${TMP}${aHome}/"
  605.     #also this...
  606.     [ -f "${aHome}/.xset.sh" ] && cp -af "${aHome}/.xset.sh" "${TMP}/root/"
  607.  
  608.     #v411 gtk theme may have been changed...
  609.     cp -af "${aHome}/.gtkrc-2.0" "${TMP}${aHome}/"
  610.  
  611.     #v411 jwm theme may have changed...
  612.     cp -af "${aHome}/.jwm/jwmrc-personal" "${TMP}${aHome}/.jwm/"
  613.     cp -af "${aHome}/.jwm/jwmrc-personal2" "${TMP}${aHome}/.jwm/"
  614.     cp -af "${aHome}/.jwm/jwmrc-theme" "${TMP}${aHome}/.jwm/"
  615.  
  616.     #v411 pmount preferences...
  617.     cp -af "${aHome}/.pmountauto" "${TMP}${aHome}"/
  618.     cp -af "${aHome}/.pmountengine" "${TMP}${aHome}"/
  619.     cp -af "${aHome}/.pmountquit" "${TMP}${aHome}"/
  620.     cp -af "${aHome}/.pmountsingle" "${TMP}${aHome}"/
  621.    if [ -d /var/packages ]; then
  622.      PKGS_DIR=/var/packages
  623.    else
  624.      PKGS_DIR="$(realpath "${aHome}/.pacakges")"
  625.    fi
  626.  
  627.    if [ -e "$PKGS_DIR/package-files" ]; then
  628.      PKG_FILES_DIR="$(realpath "$PKGS_DIR/package-files")"
  629.    else
  630.      PKG_FILES_DIR="$PKGS_DIR"
  631.    fi
  632.    if [ -d "$BUILTIN_FILES_DIR" \' ]; then
  633.      BUILTIN_FILES_DIR="$PKGS_DIR/builtin_files"
  634.    else
  635.      BUILTIN_FILES_DIR="$(realpath "$PKGS_DIR/builtin_files")"
  636.    fi
  637.     #.packages/ .files, copy any files installed to "${aHome}"...
  638.     echo -n "" > "${TMP}"/allpkgs.files
  639.     #for ONEPKG in `ls -1 "$PKG_FILES_DIR/*.files" 2>/dev/null | tr "\n" " "`
  640.     #do
  641.     #   grep '^'"$PKG_FILES_DIR" $ONEPKG | \
  642.     #
  643.     #modify "${aHome}"/.packages/ files, as all installed packages are now part of the new cd...
  644.     cp -a -f "${aHome}/.packages" "${TMP}${aHome}/"
  645.     #if [ ${PKG_FILES_DIR:0:5} = '"${aHome}"/' ]; then
  646.     #   while read -r ONEFILE
  647.     #   do
  648.     #       if [ -d "$ONEFILE" ] && [ ! -L "$ONEFILE" ];then #w018
  649.     #           mkdir -p ""${TMP}"${ONEFILE}"
  650.     #       fi
  651.     #       if [ -f "$ONEFILE" ] || [ -L "$ONEFILE" ];then #w018
  652.     #           DIRNAME="`dirname "$ONEFILE"`"
  653.     #           mkdir -p ""${TMP}"${DIRNAME}"
  654.     #           rm -f ""${TMP}"${ONEFILE}" # if ONEFILE already exists and it's a link, needs to be removed
  655.     #           cp -a -f "$ONEFILE" ""${TMP}"${DIRNAME}/"
  656.     #       fi
  657.     #   done < <(ls -1 "$PKG_FILES_DIR/*.files" 2>/dev/null)
  658.     #fi
  659.     #done
  660.  
  661.     #w018...
  662.  
  663.  
  664.    
  665.  
  666.     # 141008: move *.files to ~/.packages/builtin_files/
  667.     LH=$(("${#aHome}"+1))
  668.     if [ ${PKG_FILES_DIR:0:$LH} = "${aHome}" ]; then
  669.       touch "${aHome}/.packages/user-installed-packages"   
  670.       cat "${aHome}/.packages/user-installed-packages" | \
  671.       while read -r ONEPKG
  672.       do
  673.         ONEFILE="${TMP}$PKG_FILES_DIR/"`echo "$ONEPKG" | cut -f1 -d '|'`.files
  674.         ONENAME="${TMP}${aHome}/.packages/builtin_files/"`echo "$ONEPKG" | cut -f2 -d '|'`
  675.         mv -f "$ONEFILE" "$ONENAME"
  676.       done
  677.       cat "${aHome}/.packages/user-installed-packages" >> "${TMP}${aHome}/.packages/woof-installed-packages"
  678.       sort -u --key=1 --field-separator="|" "${TMP}${aHome}/.packages/woof-installed-packages" > "${TMP}/woof-installed-packages-tmp" #110722
  679.       mv -f "${TMP}/woof-installed-packages-tmp" "${TMP}${aHome}/.packages/woof-installed-packages"
  680.       echo -n "" > "${TMP}${aHome}/.packages/user-installed-packages" #v431  
  681.     fi
  682.  
  683.     sync #120607
  684.     rm -f "${TMP}${aHome}/.packages/"*.files #120607
  685.     rm -f "${TMP}${aHome}/.packages/"*.remove #120607
  686.  
  687.     [ -f "${TMP}${aHome}/.XLOADED" ] && rm -f "${TMP}${aHome}/.XLOADED" #130527
  688. done
  689.    #######END WORKING ON "${aHome}" (Part #1)#######
  690.  
  691.  
  692.     #######START WORKING ON /etc#######
  693.     rm -rf "${TMP}"/etc 2> /dev/null
  694.     #do some work on /etc before add it to the .sfs...
  695.     cp -a /initrd${PUP_LAYER}/etc "${TMP}"/etc #pristine /etc.
  696.     #maybe this has been modified...
  697.     cp -af /etc/ld.so.conf "${TMP}"/etc/
  698.  
  699.     #.packages/ .files, copy any files installed to /etc...
  700.     echo -n "" > "${TMP}"/allpkgs.files
  701.     #for ONEPKG in `ls -1 "${aHome}"/.packages/*.files 2>/dev/null | tr "\n" " "`
  702.     #do
  703.     #   grep '^/etc/' $ONEPKG | \
  704.     #   while read -r ONEFILE
  705.     #   do
  706.     #       if [ -d "$ONEFILE" ] && [ ! -L "$ONEFILE" ];then #w018
  707.     #           mkdir -p ""${TMP}"${ONEFILE}"
  708.     #       fi
  709.     #       if [ -f "$ONEFILE" ] || [ -L "$ONEFILE" ];then #w018
  710.     #           DIRNAME="`dirname "$ONEFILE"`"
  711.     #           mkdir -p ""${TMP}"${DIRNAME}"
  712.     #           rm -f ""${TMP}"${ONEFILE}" # if ONEFILE already exists and it's a link, needs to be removed
  713.     #           cp -a -f "$ONEFILE" ""${TMP}"${DIRNAME}/"
  714.     #       fi
  715.     #   done
  716.     #done
  717.     sync
  718.  
  719.     cp -af /etc/eventmanager "${TMP}"/etc/ #v411
  720.  
  721.     #what about settings for a particular pc?...
  722.     m_20="$(gettext 'Hardware customisation was not chosen.')"
  723.     MSG1="$m_20"
  724.     m_21="$(eval_gettext 'Have created the /etc directory for the new ${PUPPYSFS} file.')
  725. $(gettext "It is in a 'pristine' state, but you can choose to customise it.")
  726. $(gettext "Do you want to add customisations for your hardware? Examples are mouse, keyboard, video. But, if you answer 'Yes' here, the live-CD will be preconfigured for your PC only. Therefore, it is best to answer 'No' if you want to boot the new live-CD on different PCs.")
  727.  
  728. $(gettext "Click 'Yes' button to customise /etc...")
  729. $(gettext "Click 'No' button not to customise (recommended)...")"
  730.    
  731.     [ -z "$customize_etc" ]&& Xdialog --wrap --left --title "$m_01" --default-no --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "$m_21" 0 80
  732.     [ $? -eq 0 ] && customize_etc=yes || customize_etc=no
  733.     if [ "$customize_etc" = yes ];then
  734.         cp -af /etc/codepage "${TMP}"/etc/
  735.         cp -af /etc/fontmap "${TMP}"/etc/
  736.         cp -af /etc/keymap "${TMP}"/etc/
  737.         cp -af /etc/mousedevice "${TMP}"/etc/
  738.         cp -af /etc/eth0mode "${TMP}"/etc/
  739.         cp -af /etc/eth1mode "${TMP}"/etc/
  740.         cp -af /etc/resolv.conf "${TMP}"/etc/
  741.         rm -f "${TMP}"/etc/localtime #a symlink
  742.         cp -af /etc/localtime "${TMP}"/etc/
  743.         cp -af /etc/TZ "${TMP}"/etc/
  744.         cp -af /etc/cdburnerdevice "${TMP}"/etc/
  745.         cp -af /etc/dvddevice "${TMP}"/etc/
  746.         cp -af /etc/modemdevice "${TMP}"/etc/
  747.         cp -af /etc/securetelnetrc "${TMP}"/etc/
  748.         cp -af /etc/modules.conf "${TMP}"/etc/
  749.         cp -af /etc/modprobe.d "${TMP}"/etc/ #101020
  750.         cp -af /etc/rdesktoprc "${TMP}"/etc/
  751.         cp -af /etc/windowmanager "${TMP}"/etc/
  752.         cp -af /etc/X11/xorg.conf "${TMP}"/etc/X11
  753.         cp -af /etc/network-wizard "${TMP}"/etc/
  754.         cp -af /etc/simple_network_setup/* "${TMP}"/etc/simple_network_setup/
  755.         m_22="$(gettext 'These files were customised in /etc:')
  756. codepage fontmap keymap mousedevice eth0mode eth1mode resolv.conf localtime TZ cdburnerdevice dvddevice modemdevice securetelnetrc modprobe.d/* rdesktoprc windowmanager X11/xorg.conf
  757. $(gettext 'Also these directories:')
  758. network-wizard."
  759.         MSG1="$m_22"
  760.     fi
  761.  
  762.     #some files to always copy...
  763.     cp -af /etc/Puppybackgroundpicture "${TMP}"/etc/
  764.     #TODO: other gtk and jwm customisations.
  765.  
  766.     cp -f "${TMP}"/etc/DISTRO_SPECS "${TMP}"/DISTRO_SPECSupdated #keep this to put into initrd.gz.
  767.  
  768.    #######END WORKING ON /etc (Part #1) #######
  769.  
  770.  
  771.     #######START WORKING ON /var#######
  772.     rm -rf "${TMP}"/var 2> /dev/null
  773.     cp -a /initrd${PUP_LAYER}/var "${TMP}"/var #pristine var
  774.  
  775.     #.packages/ .files, copy any files installed to /var...
  776.     echo -n "" > "${TMP}"/allpkgs.files
  777.     #for ONEPKG in `ls -1 "$PKG_FILES_DIR/"*.files 2>/dev/null | tr "\n" " "`
  778.     #do
  779.     #   grep '^/var/' $ONEPKG | \
  780.     if [ ! -d /var/packages ]; then
  781.       mkdir  -p "${TMP}"/var #This is probably already done
  782.     fi
  783.     [ -d /var/packages ] && cp -arf --remove-destination /var/packages/* "${TMP}"/var/packages
  784.     if [ ${PKG_FILES_DIR:0:5} = '/var/' ]; then
  785.         #while read -r ONEFILE
  786.         #do
  787.         #   if [ -d "$ONEFILE" ] && [ ! -L "$ONEFILE" ];then #w018
  788.         #       mkdir -p ""${TMP}"${ONEFILE}"
  789.         #   fi
  790.         #   if [ -f "$ONEFILE" ] || [ -L "$ONEFILE" ];then #w018
  791.         #       DIRNAME="`dirname "$ONEFILE"`"
  792.         #       mkdir -p ""${TMP}"${DIRNAME}"
  793.         #       rm -f ""${TMP}"${ONEFILE}" # if ONEFILE already exists and it's a link, needs to be removed
  794.         #       cp -a -f "$ONEFILE" ""${TMP}"${DIRNAME}/"
  795.         #   fi
  796.         #done < <(ls -1 "$PKG_FILES_DIR/"*.files 2>/dev/null)
  797.    
  798.     #done
  799.        
  800.     # 141008: move *.files to ~/.packages/builtin_files/
  801.       if [ ${PKG_FILES_DIR:0:5} = '/var/' ]; then
  802.         touch "$PKGS_DIR/user-installed-packages"
  803.         cat "$PKGS_DIR/user-installed-packages" | \
  804.         while read -r ONEPKG
  805.         do
  806.           ONEFILE="${TMP}$PKG_FILES_DIR/`echo "$ONEPKG" | cut -f1 -d '|'`.files"
  807.           ONENAME="$BUILTIN_FILES_DIR/`echo "$ONEPKG" | cut -f2 -d '|'`"
  808.           mv -f "$ONEFILE" "$ONENAME"
  809.         done
  810.       fi
  811.       #cat "$PKGS_DIR/user-installed-packages" >> "${TMP}$PKGS_DIR/woof-installed-packages"
  812.       sort -u --key=1 --field-separator="|" "${TMP}"$PKGS_DIR/woof-installed-packages > "${TMP}"/woof-installed-packages-tmp #110722
  813.       mv -f "${TMP}"/woof-installed-packages-tmp "${TMP}"$PKGS_DIR/woof-installed-packages
  814.       echo -n "" > "${TMP}"$PKGS_DIR/user-installed-packages #v431
  815.       sync #120607
  816.       rm -f "${TMP}"$PKGS_DIR/*.files #120607
  817.       rm -f "${TMP}"$PKGS_DIR/*.remove #120607
  818.    fi
  819.     sync
  820.     [ "$CLEARPKGLOG" = "yes" ] && rm -f "${TMP}"/var/log/packages/* #120607
  821.  
  822.    #######END WORKING ON /var (Part #1)#######
  823.  
  824.    
  825.     #######Start WORKING ON "${aHome}" (Part #2) #######   
  826. for aUser in root spot fido puppy; do
  827.    aHOME=$(eval echo "~$aUser")
  828.     m_19="$(eval_gettext 'This program has created folder '"${TMP}${aHome}"', which has everything that is now going to be added as '"${aHome}"' in the ${PUPPYSFS} file.')
  829. $(gettext "This is mostly 'pristine', as obviously you do not want all your cache files, temp files, email files, and other working/temporary files to be the ISO. However, if you are familiar with the workings of Puppy, you might like to take a look at ${TMP}${aHome} right now, and possibly add anything that you want from ${aHome} (or remove something!)")
  830. $(gettext '(if you think that this program has missed out something important, please let us know..')
  831.  
  832. $(eval_gettext "After examining ${TMP}${aHome}, click 'Ok' to add ${aHome} in \${PUPPYSFS} file...")"
  833.    if  -z "$root_action" ]; then
  834.       Xdialog --wrap --left --title "$m_01" --msgbox "$m_19" 0 80
  835.     else
  836.       case "$root_action"
  837.       default) cp_user_for_remaster ;;
  838.       *) echo "Root action='$root_action' not yet defined"
  839.     fi
  840.     sync
  841.     [ "$(ls "${TMP}${aHome}/.packages/"*.files)" = "" ] && CLEARPKGLOG="yes" || CLEARPKGLOG="no" #120607 in case user copied entire "${aHome}" to "${TMP}" for boot disk.
  842.     do_mksquashfs "${TMP}${aHome}" "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  843.     sync
  844.     rm -rf "${TMP}${aHome}"
  845. done
  846.     #######END WORKING ON "${aHome}" (Part #2) ####### 
  847.    #######Start WORKING ON /etc (Part #2) #######
  848.     m_23="${MSG1}
  849.  
  850. $(gettext 'If you know what you are doing, you can now modify any files in '"'"${TMP}'/etc'"'"' folder. This is just about to be added to /etc in the .sfs file.')
  851. $(gettext "Do anything you want before clicking 'Ok'.")
  852. $(gettext '(If this program has missed something important, let me know -- Barry Kauler)')
  853.  
  854. $(eval_gettext "Click 'Ok' to add /etc in \${PUPPYSFS} file...")"
  855.    if  -z "$etc_action" ]; then
  856.       Xdialog --wrap --left  --title "$m_01" --msgbox "$m_23" 0 80
  857.     else
  858.       case "$etc_action"
  859.       default) cp_etc_for_remaster ;;
  860.       *) echo "Root action='$root_action' not yet defined"
  861.     fi
  862.  
  863.     #120606 in case user just now replaced the /etc directory...
  864.     sync
  865.     #130527 .XLOADED moved to /root (see /usr/bin/xwin), change test...
  866.     MODIFETC="$(find "${TMP}"/etc/modules -mindepth 1 -maxdepth 1 -name 'firmware.dep.inst.*')"
  867.     if [ "$MODIFETC" != "" ];then
  868.         #rm -f "${TMP}"/etc/.XLOADED
  869.         rm -f "${TMP}"/etc/modules/firmware.dep.inst.*
  870.         touch "${TMP}"/etc/personal_settings_popup_disabled
  871.         touch "${TMP}"/etc/personal_data_save_disabled
  872.     fi
  873.     [ -f "${TMP}"/etc/.XLOADED ] && rm -f "${TMP}"/etc/.XLOADED #130527 just in case old file still there.
  874.  
  875.     sync
  876.  
  877.     do_mksquashfs "${TMP}/etc" "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  878.     sync
  879.     rm -rf "${TMP}"/etc
  880.     #######END WORKING ON /etc (Part #2) #######   
  881.    
  882.    #######Start WORKING ON /var (Part #2) #######
  883.  
  884.     sync
  885.     do_mksquashfs "${TMP}"/var "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  886.     sync
  887.     rm -rf "${TMP}"/var
  888.    
  889.     #s243a: TODO: add prompt to modify the var folder like was done in the etc folder
  890.    
  891.     #######END WORKING ON /var#######
  892.    
  893.     chmod a+r "${ISO_ROOT_new}"/* &>/dev/null
  894.     chmod a-x "${ISO_ROOT_new}"/*.sfs &>/dev/null
  895.  
  896. fi ###### end of long skip if, cleating new sfs
  897.  
  898. #=================================================================
  899.  
  900. m_25="$(gettext 'Almost ready to create the new ISO file!')
  901.  
  902. $(gettext "If you want to add any more files, say extra SFS files, or to edit or modify the files in any way, do it now. Note, if you add an extra SFS file, say 'devx.sfs' then it will be available for use when you boot the new live-CD.")
  903.  
  904. $(eval_gettext "If you want to make any changes, use ROX-Filer to open \${WKGMNTPT}/puppylivecdbuild/ and do so now, before clicking the 'OK' button.")"
  905. Xdialog --wrap --left  --title "$m_01" --msgbox "$m_25" 0 80
  906. sync
  907.  
  908. BOOTLOADER=""
  909. [ -f "${ISO_ROOT_new}"/grldr ] && BOOTLOADER="grldr"
  910. [ -f "${ISO_ROOT_new}"/isolinux.bin ] && BOOTLOADER="isolinux.bin"
  911. if [ "$BOOTLOADER" = "" ]; then
  912.     m_25_1="$(gettext 'No boot loaders found. You need isolinux.bin or grldr to make bootable CD.')
  913. $(gettext "Click 'OK' to quit.")
  914. $(eval_gettext '(leaving ${WKGMNTPT}/puppylivecdbuild/ files in existence)')"
  915.     Xdialog --wrap --left  --title "$m_01" --msgbox "$m_25_1" 0 0
  916.     exit
  917. fi
  918.  
  919. if [ "$NEW" = "yes" ]; then #120628: no change id-string for reuse
  920.     sync
  921.     #100913 need to update file DISTRO_SPECS in initrd.gz, so init script can find puppy files...
  922.     mv -f "${ISO_ROOT_new}"/initrd.gz "${TMP}" #note $WKGMNTPT may be non-linux fs.
  923.     cd "${TMP}"
  924.     gunzip initrd.gz
  925.     mkdir initrd-tree-tmp1
  926.     cd initrd-tree-tmp1
  927.     cat ../initrd | cpio -i -d -m
  928.     sync
  929.     rm -f ../initrd
  930.     cp -a -f "${TMP}"/DISTRO_SPECSupdated ./DISTRO_SPECS #see earlier.
  931.     find . | cpio -o -H newc | gzip -9 > "${ISO_ROOT_new}"/initrd.gz
  932.     sync
  933.     cd ..
  934.     rm -rf initrd-tree-tmp1
  935.     cd /root
  936. fi #120628 end
  937.  
  938. if [ -f "${ISO_ROOT_new}"/efi.img ] ; then
  939.     EFI_IMG='efi.img'
  940. fi
  941.  
  942. #build new iso file
  943. MSG="$(gettext 'ISO file not created.')"
  944. m_27="$(eval_gettext "Click 'Yes' button to create a 'custom-puppy.iso' in \${WKGMNTPT}/ (assuming that there is 100MB-300MB free space)...")
  945. $(eval_gettext "Click 'No' button (or close-box on window) to quit program at this point (leaving  \${WKGMNTPT}/puppylivecdbuild/ files in existence)...")"
  946. Xdialog --wrap --left  --title "$m_01" --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "$m_27" 0 80
  947. if [ $? -eq 0 ];then
  948.     VOLI=""
  949.     m_27_1="$(gettext 'You can add the CD volume ID.')"
  950.     VOLI=$(Xdialog --title "$m_01" --stdout --inputbox "$m_27_1" 0 60 "$SFSBASE")
  951.     [ "$VOLI" != "" ] && VOLI="-V $(echo "$VOLI"|tr ' ' '_')"
  952.     rm -f $WKGMNTPT/custom-puppy*.iso
  953.     #=
  954.     if [ "$EFI_IMG" ];then
  955.         UEFI='-uefi'
  956.         UEFI_OPT='-u'
  957.         # make uefi iso
  958.         rxvt -bg orange -fg black -title "$m_01" -e \
  959.             mkisofs -iso-level 4 -D -R $VOLI -o $WKGMNTPT/custom-puppy${UEFI}.iso \
  960.             -b ${BOOTLOADER} -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
  961.             -eltorito-alt-boot -eltorito-platform efi -b "$EFI_IMG" -no-emul-boot \
  962.                 "${ISO_ROOT_new}"/
  963.     else
  964.         rxvt -bg orange -fg black -title "$m_01" -e \
  965.             mkisofs -iso-level 4 -D -R $VOLI -o $WKGMNTPT/custom-puppy.iso \
  966.             -b ${BOOTLOADER} -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
  967.                 "${ISO_ROOT_new}"/
  968.     fi
  969.     case $BOOTLOADER in *"isolinux"*)
  970.         if which isohybrid ; then
  971.             echo "isohybrid ${UEFI_OPT} $WKGMNTPT/custom-puppy${UEFI}.iso"
  972.             isohybrid ${UEFI_OPT} "$WKGMNTPT/custom-puppy${UEFI}.iso"
  973.         fi ;;
  974.     esac
  975.     MSG="$(eval_gettext '${WKGMNTPT}/custom-puppy${UEFI}.iso created.')"
  976. fi
  977. sync
  978. m_28="$(eval_gettext '${WKGMNTPT}/puppylivecdbuild/ files left in existence.')
  979. $(gettext "Click 'Ok' button to quit...")"
  980. Xdialog --wrap --left  --title "$m_01" --msgbox "$MSG
  981. $m_28" 0 0
  982.  
  983. ### END ###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement