Advertisement
s243a

/usr/sbin/remasterpup3

Aug 21st, 2019
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 41.21 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
  336.         m_42="
  337.  
  338. $(gettext 'NOTICE:')
  339. $(eval_gettext 'Directory ${WKGMNTPT}/puppylivecdbuild already exists.')
  340. $(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.')
  341. $(gettext '(You may view the directory contents with a file-manager to satisfy yourself whether these files should be re-used)')"
  342.     fi
  343.     m_40="$(gettext 'This remaster program needs to read some files off the current live-CD.')
  344.  
  345. $(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.")
  346.  
  347. $(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}'")
  348.  
  349. $(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)")
  350. $(gettext "Alternatively, if you want to read the files off a Puppy live-CD, insert it in drive, then click 'OK' button.")${m_42}"
  351.     Xdialog --wrap --left  --title "$m_01" --msgbox "$m_40" 0 80
  352.  
  353.     if [ $? -eq 0 ];then #130223 big if "BIGIF2"
  354.         #130222 fix this...
  355.         VIRTUALCD=""
  356.         #130301 crap, earlier was using losetup-FULL from util-linux git, now using older 2.21.1, it needs -a param,
  357.         #but also truncates long lines (same as bb losetup) -- what a nuisance...
  358.         for ONELOOP in `cat /proc/mounts | grep -E '(^/dev/loop.*)( udf | iso9660 )' | cut -f 1 -d ' ' | tr '\n' ' '` #130308 /dev/loop only
  359.         do
  360.             oPTN="^${ONELOOP} "
  361.             ONEISO="$(cat /proc/mounts | grep "$oPTN" | cut -f 2 -d ' ' | rev | cut -f 1 -d '+' | cut -f 1 -d '/' | rev)" #130301
  362.             [ "$ONEISO" = "" ] && continue #130301 precaution.
  363.             ONELOOP=$(echo "$ONELOOP" | sed 's|/loop/|/loop|')
  364.             VIRTUALCD="${VIRTUALCD} ${ONELOOP} ${ONEISO}"
  365.         done
  366.         m_14="$(gettext 'This remaster program needs to read some files off the current live-CD.')
  367. $(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).')"
  368.         MSG="$m_14"
  369.         choice_cdd filter #130308 Use filtering.
  370.  
  371.         CDPATTERN="/dev/$BURNERDRV "
  372.         CDMNTPT="`mount | grep "$CDPATTERN" | tr -s " " | cut -f 3 -d " "`"
  373.         if [ "$CDMNTPT" != "" ];then
  374.             if [ ! -f $CDMNTPT/initrd.gz ];then #130308 In theory, this will now never be true.
  375.                 #091212 weird bug, no processes but when run this, x restarts...
  376.                 xFUSER="`fuser -m /dev/$BURNERDRV 2>/dev/null`" #do this first, seems to fix it.
  377.                 [ "$xFUSER" != "" ] && fuser -k -m /dev/$BURNERDRV
  378.                 sync
  379.                 umount /dev/$BURNERDRV 2> /dev/null
  380.                 if [ $? -ne 0 ];then
  381.                     m_15="$(gettext 'Mounted CD, get rid of it before running this program!')"
  382.                     Xdialog --wrap --left  --title "$m_02" --msgbox "$m_15" 0 0
  383.                     exit
  384.                 fi
  385.                 CDMNTPT=""
  386.             fi
  387.         fi
  388.  
  389.         if [ "$CDMNTPT" = "" ];then
  390.             m_16="$(eval_gettext 'Please insert the current Puppy live-CD into drive ${BURNERDRV}.')
  391. $(gettext 'Then click OK...')"
  392.             while [ 1 ];do
  393.                 Xdialog --wrap --left  --title "$m_01" --msgbox "$m_16" 0 0
  394.                 [ $? -eq 0  ] || exit   # 22jun09
  395.                 case $BURNERDRV in
  396.                     loop*) #ISO.. already mounted
  397.                         CDMNTPT=$(mount | grep "^/dev/$BURNERDRV " | cut -f 3 -d ' ')
  398.                         ;;
  399.                     *) #CD
  400.                         #now mount it...
  401.                         CDMNTPT="/mnt/$BURNERDRV"
  402.                         mkdir -p /mnt/$BURNERDRV
  403.                         mount -t iso9660 /dev/$BURNERDRV /mnt/$BURNERDRV
  404.                         [ $? -eq 0 ] && break
  405.                         ;;
  406.                 esac
  407.             done
  408.         fi
  409.  
  410.         #now get the files off it...
  411.         m_17="$(eval_gettext 'Copying files from CD to ${WKGMNTPT}/puppylivecdbuild/, please wait...')"
  412.         Xdialog --wrap --left  --title "$m_01" --no-buttons --ignore-eof   --infobox "$m_17" 0 0 0 &
  413.         XPID=$!
  414.         mkdir -p "${ISO_ROOT_new}"
  415.         #now copy the files... # v431JP HTM, ICO, INF
  416.         sync
  417.         (
  418.         cd $CDMNTPT
  419.         for F in ${ZDRVSFS} vmlinuz initrd.gz  grldr *efi* *EFI* *.c32 *.sh *.lst *.xpm *.jpg *.png *.bin *.cfg *.msg *.16 *.HTM* *.ICO *.INF help
  420.         do
  421.             #130223 -n means do not override an existing file... 130304 hmmm, -n not supported, use -u ...
  422.             [ -e "$F" ] && cp -a -u $F "${ISO_ROOT_new}"/
  423.             sync
  424.         done
  425.         )
  426.         umount /dev/$BURNERDRV 2> /dev/null
  427.         kill $XPID
  428.  
  429.     fi #end "BIGIF2"
  430.  
  431.     m_16_1="$(eval_gettext 'Do you like to make ${ZDRVSFS}, the separate driver file?')"
  432.     Xdialog --wrap --left  --title "$m_01" --default-no --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "$m_16_1" 0 0
  433.     [ $? -eq 0 ] && MKZDRV="yes" || MKZDRV=""
  434.     [ $? -eq 255 ] && exit #130223
  435.  
  436.     # set compression
  437.     /usr/lib/gtkdialog/box_yesno --yes-label "xz (default)" --no-label "gzip" --yes-first --info \
  438.     --yes-icon "execute.svg" --no-icon "execute.svg" \
  439. "$m_01" "$(gettext 'You can use xz or gzip compression. Choose one...')"
  440.     case $? in
  441.         1) COMP="-comp gzip" ;;
  442.         *) COMP="-comp xz -Xbcj x86" ;;
  443.     esac
  444.     #COMP="-noI -noD -noF -noX" #fast tests zzzzzz
  445.     echo "COMP=${COMP}"
  446.     # -
  447.  
  448.     m_18="$(eval_gettext 'Creating the ${PUPPYSFS} file in ${WKGMNTPT}/puppylivecdbuild/.')
  449. $(gettext 'This can take quite a long time, so please wait.... and wait...')
  450. $(eval_gettext 'This window will disappear when ${PUPPYSFS} is finally created.')
  451. $(gettext 'Please wait...')"
  452.     Xdialog --wrap --left  --title "$m_01" --no-buttons --ignore-eof   --infobox "$m_18" 0 0 0 &
  453.     XPID=$!
  454.  
  455.     #create new puppy.sfs file...
  456.     squash() {
  457.         echo $0 $@
  458.         rxvt -bg orange -fg black -title "$m_01" -geometry 80x6 -e mksquashfs $@ 2> /dev/null
  459.     }
  460.    fk_squash() {
  461.         echo $0 $@
  462.         #s243a: use set -x to echo cpio commands in fk_mksquashfs and pass to rxvt
  463.         #rxvt -bg orange -fg black -title "$m_01" -geometry 80x6 -e mksquashfs $@ 2> /dev/null
  464.         fk_mksquashfs $@ #Short term hack
  465.     }
  466.     do_squash(){
  467.       if [ "$mode" = dir ]; then
  468.         fk_squash $@    
  469.       else
  470.         squash $@
  471.       fi
  472.     }  
  473.     fk_mksquashfs(){
  474.       #source_dir=$1; shift
  475.       #target_dir=$2; shift
  476.      option=""
  477.      out=() #Currently not used
  478.      args=()
  479.      declare -A exludes
  480.       for arg in "$@";do
  481.         if [[ "$arg" == -* ]]; then
  482.           case "$arg" in
  483.           -*)
  484.           option="$arg" ;;
  485.           esac  
  486.         else
  487.           case option in
  488.           -e)
  489.             exludes+=( ["$arg"]=1 ) ;;
  490.           '')
  491.             args+=( "$arg" ) ;;
  492.           *)
  493.             out+=( "$arg" ) ;;
  494.           esac
  495.         fi
  496.       done
  497.       n_args=${#args}
  498.       target_dir=$args[$n_args]
  499.       target_dir="${target_dir%.sfs}"
  500.      
  501.       mkdir -p "$target_dir"
  502.       unset 'args[$n_args-1]' #https://stackoverflow.com/questions/8247433/remove-the-last-element-from-an-array
  503.       #while read aDir; do
  504.       if [ realpath "$target_dir" != "/" ]; then
  505.        for aDir in "$args[@]"; do
  506.           excluded="${excludes[$aDir]}"
  507.           [ -z "$excluded" ] && excluded=0
  508.           if [ ! $excluded -eq 1 ]; then
  509.             cd $aDir
  510.             cpio -pd "$target_dir"
  511.           fi
  512.         done
  513.       fi
  514.       #done < <(ls -a -1)
  515.      
  516.     }  
  517.     do_mksquashfs(){
  518.       if [ "$mode" = dir ]; then
  519.         fk_mksquashfs $@    
  520.       else
  521.         mksquashfs $@
  522.       fi
  523.     }          
  524.    
  525.     DIRHOME=""
  526.     [ -d /home ] && DIRHOME="/home"
  527.     [ -d /sys ] && DIRSYS="/sys"
  528.     [ -d /lost+found ] && DIRLOST="/lost+found"
  529.     rm -f ${WKGMNTPT}/puppylivecdbuild/$PUPPYSFS 2> /dev/null
  530.     sync
  531.     #note, /puppy.sfs is not normally there, i relocated it to a separate tmpfs,
  532.     #however have not yet done that for multisession-cd/dvd (PUPMODE=77).
  533.     #note, /home could be in underdog linux...
  534.  
  535.     # modules copied from initrd
  536.     ANOTHER_REMOVE="/lib/modules/$KERNELVER/initrd /lib/modules/*/modules.*"    # 28dec09 modules.*
  537.     if [ "$MKZDRV" = "yes" ]; then
  538.         rm -f "${ISO_ROOT_new}"/$ZDRVSFS 2> /dev/null
  539.         do_mksquashfs /lib "${ISO_ROOT_new}"/$ZDRVSFS -keep-as-directory -e /lib/[^m]* $ANOTHER_REMOVE
  540.         ANOTHER_REMOVE="/lib/modules"
  541.     fi
  542.     #120605 Omit certain /dev subdir content and modem components loaded from firmware tarballs...
  543.     [ -d /dev/snd ] && [ "`ls /dev/snd`" != "" ] && DIRDEVSNDFILES="/dev/snd/*" #120721
  544.     [ -d /dev/.udev ] && DIRDEVUDEV="/dev/.udev"
  545.     #121021 modem daemons now left in place.
  546.     [ -f /usr/share/icons/hicolor/icon-theme.cache ] && ICONCACHE=/usr/share/icons/hicolor/icon-theme.cache #120721
  547.     TOPPLCDB=''
  548.     [ -e /puppylivecdbuild ] && TOPPLCDB='/puppylivecdbuild'
  549.     TOPPUPSFS=''
  550.     [ -e /${PUPPYSFS} ] && TOPPUPSFS="/${PUPPYSFS}"
  551.    
  552.  
  553.  
  554.     # display terminal only for the first stage because it takes the most of time. 'squash' is a function, see above. 120512 $COMP added...
  555.     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
  556.     sync
  557.  
  558.     #add pristine folders (out of current puppy.sfs)...
  559.     do_mksquashfs /initrd${PUP_LAYER}/home "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  560.     sync
  561.     do_mksquashfs /initrd${PUP_LAYER}/proc "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  562.     sync
  563.     do_mksquashfs /initrd${PUP_LAYER}/tmp "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  564.     sync
  565.     do_mksquashfs /initrd${PUP_LAYER}/mnt "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  566.     sync
  567.     do_mksquashfs /initrd${PUP_LAYER}/media "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  568.     sync
  569.  
  570.     kill $XPID
  571.  
  572.     #######START WORKING ON /root#######
  573. for aUser in root spot fido puppy; do
  574.     rm -rf "${TMP}""${aHome}" 2> /dev/null
  575.    aHOME=$(eval echo "~$aUser")
  576.    mkdir -p "${TMP}${aHome}"
  577.     #do some work on "$aHome" before add it to the squashfs...
  578.     cp -a /initrd${PUP_LAYER}"${aHome}" "${TMP}""${aHome}" #pristine "$aHome"
  579.     #copy all of my-applications/
  580.     cp -af "${aHome}"/my-applications/* "${TMP}${aHome}/my-applications/"
  581.     #some dotpups get installed here...
  582.     cp -af "${aHome}/my-roxapps" "${TMP}${aHome}/" 2>/dev/null
  583.     #window manager config files...
  584.     cp -af "${aHome}/.jwmrc" "${TMP}${aHome}/"
  585.     cp -af "${aHome}/.jwmrc-tray" "${TMP}${aHome}/" #v411
  586.     cp -af "${aHome}/.fvwm95rc" "${TMP}${aHome}/"
  587.     cp -af "${aHome}/.icewm/menu" "${TMP}${aHome}/.icewm/"
  588.     #rox desktop settings...
  589.     cp -af "${aHome}/Choices/ROX-Filer/PuppyPin" "${TMP}${aHome}/Choices/ROX-Filer/"
  590.     cp -af "${aHome}/Choices/ROX-Filer/globicons" "${TMP}${aHome}/Choices/ROX-Filer/"
  591.     #100117 user changes get saved here, which overrides original...
  592.     if [ -f "${aHome}/.config/rox.sourceforge.net/ROX-Filer/globicons" ];then
  593.         mkdir -p "${TMP}${aHome}/.config/rox.sourceforge.net/ROX-Filer/"
  594.         cp -af "${aHome}/.config/rox.sourceforge.net/ROX-Filer/globicons" "${TMP}${aHome}/.config/rox.sourceforge.net/ROX-Filer/"
  595.     fi
  596.     #100117 i think also save user settings...
  597.     if [ -f "${aHome}/.config/rox.sourceforge.net/ROX-Filer/Options" ];then
  598.         mkdir -p "${TMP}${aHome}/.config/rox.sourceforge.net/ROX-Filer/"
  599.         cp -af "${aHome}/.config/rox.sourceforge.net/ROX-Filer/Options" "${TMP}${aHome}/.config/rox.sourceforge.net/ROX-Filer/"
  600.     fi
  601.     #v411 tidy up, remove desktop drive icons...
  602.     grep -v '"${TMP}"/pup_event_frontend/drive_' "${TMP}${aHome}/Choices/ROX-Filer/PuppyPin" > "${TMP}"/remaster-PuppyPin
  603.     mv -f "${TMP}/remaster-PuppyPin" "${TMP}${aHome}/Choices/ROX-Filer/PuppyPin"
  604.     #this may have been modified for a different w.m...
  605.     cp -af "${aHome}/.xinitrc" "${TMP}${aHome}/"
  606.     #also this...
  607.     [ -f "${aHome}/.xset.sh" ] && cp -af "${aHome}/.xset.sh" "${TMP}/root/"
  608.  
  609.     #v411 gtk theme may have been changed...
  610.     cp -af "${aHome}/.gtkrc-2.0" "${TMP}${aHome}/"
  611.  
  612.     #v411 jwm theme may have changed...
  613.     cp -af "${aHome}/.jwm/jwmrc-personal" "${TMP}${aHome}/.jwm/"
  614.     cp -af "${aHome}/.jwm/jwmrc-personal2" "${TMP}${aHome}/.jwm/"
  615.     cp -af "${aHome}/.jwm/jwmrc-theme" "${TMP}${aHome}/.jwm/"
  616.  
  617.     #v411 pmount preferences...
  618.     cp -af "${aHome}/.pmountauto" "${TMP}${aHome}"/
  619.     cp -af "${aHome}/.pmountengine" "${TMP}${aHome}"/
  620.     cp -af "${aHome}/.pmountquit" "${TMP}${aHome}"/
  621.     cp -af "${aHome}/.pmountsingle" "${TMP}${aHome}"/
  622.    if [ -d /var/packages ]; then
  623.      PKGS_DIR=/var/packages
  624.    else
  625.      PKGS_DIR="$(realpath "${aHome}/.pacakges")"
  626.    fi
  627.  
  628.    if [ -e "$PKGS_DIR/package-files" ]; then
  629.      PKG_FILES_DIR="$(realpath "$PKGS_DIR/package-files")"
  630.    else
  631.      PKG_FILES_DIR="$PKGS_DIR"
  632.    fi
  633.    if [ -d "$BUILTIN_FILES_DIR" \' ]; then
  634.      BUILTIN_FILES_DIR="$PKGS_DIR/builtin_files"
  635.    else
  636.      BUILTIN_FILES_DIR="$(realpath "$PKGS_DIR/builtin_files")"
  637.    fi
  638.     #.packages/ .files, copy any files installed to "${aHome}"...
  639.     echo -n "" > "${TMP}"/allpkgs.files
  640.     #for ONEPKG in `ls -1 "$PKG_FILES_DIR/*.files" 2>/dev/null | tr "\n" " "`
  641.     #do
  642.     #   grep '^'"$PKG_FILES_DIR" $ONEPKG | \
  643.     #
  644.     #modify "${aHome}"/.packages/ files, as all installed packages are now part of the new cd...
  645.     cp -a -f "${aHome}/.packages" "${TMP}${aHome}/"
  646.     #if [ ${PKG_FILES_DIR:0:5} = '"${aHome}"/' ]; then
  647.     #   while read -r ONEFILE
  648.     #   do
  649.     #       if [ -d "$ONEFILE" ] && [ ! -L "$ONEFILE" ];then #w018
  650.     #           mkdir -p ""${TMP}"${ONEFILE}"
  651.     #       fi
  652.     #       if [ -f "$ONEFILE" ] || [ -L "$ONEFILE" ];then #w018
  653.     #           DIRNAME="`dirname "$ONEFILE"`"
  654.     #           mkdir -p ""${TMP}"${DIRNAME}"
  655.     #           rm -f ""${TMP}"${ONEFILE}" # if ONEFILE already exists and it's a link, needs to be removed
  656.     #           cp -a -f "$ONEFILE" ""${TMP}"${DIRNAME}/"
  657.     #       fi
  658.     #   done < <(ls -1 "$PKG_FILES_DIR/*.files" 2>/dev/null)
  659.     #fi
  660.     #done
  661.  
  662.     #w018...
  663.  
  664.  
  665.    
  666.  
  667.     # 141008: move *.files to ~/.packages/builtin_files/
  668.     LH=$(("${#aHome}"+1))
  669.     if [ ${PKG_FILES_DIR:0:$LH} = "${aHome}" ]; then
  670.       touch "${aHome}/.packages/user-installed-packages"   
  671.       cat "${aHome}/.packages/user-installed-packages" | \
  672.       while read -r ONEPKG
  673.       do
  674.         ONEFILE="${TMP}$PKG_FILES_DIR/"`echo "$ONEPKG" | cut -f1 -d '|'`.files
  675.         ONENAME="${TMP}${aHome}/.packages/builtin_files/"`echo "$ONEPKG" | cut -f2 -d '|'`
  676.         mv -f "$ONEFILE" "$ONENAME"
  677.       done
  678.       cat "${aHome}/.packages/user-installed-packages" >> "${TMP}${aHome}/.packages/woof-installed-packages"
  679.       sort -u --key=1 --field-separator="|" "${TMP}${aHome}/.packages/woof-installed-packages" > "${TMP}/woof-installed-packages-tmp" #110722
  680.       mv -f "${TMP}/woof-installed-packages-tmp" "${TMP}${aHome}/.packages/woof-installed-packages"
  681.       echo -n "" > "${TMP}${aHome}/.packages/user-installed-packages" #v431  
  682.     fi
  683.  
  684.     sync #120607
  685.     rm -f "${TMP}${aHome}/.packages/"*.files #120607
  686.     rm -f "${TMP}${aHome}/.packages/"*.remove #120607
  687.  
  688.     [ -f "${TMP}${aHome}/.XLOADED" ] && rm -f "${TMP}${aHome}/.XLOADED" #130527
  689. done
  690.    #######END WORKING ON "${aHome}" (Part #1)#######
  691.  
  692.  
  693.     #######START WORKING ON /etc#######
  694.     rm -rf "${TMP}"/etc 2> /dev/null
  695.     #do some work on /etc before add it to the .sfs...
  696.     cp -a /initrd${PUP_LAYER}/etc "${TMP}"/etc #pristine /etc.
  697.     #maybe this has been modified...
  698.     cp -af /etc/ld.so.conf "${TMP}"/etc/
  699.  
  700.     #.packages/ .files, copy any files installed to /etc...
  701.     echo -n "" > "${TMP}"/allpkgs.files
  702.     #for ONEPKG in `ls -1 "${aHome}"/.packages/*.files 2>/dev/null | tr "\n" " "`
  703.     #do
  704.     #   grep '^/etc/' $ONEPKG | \
  705.     #   while read -r ONEFILE
  706.     #   do
  707.     #       if [ -d "$ONEFILE" ] && [ ! -L "$ONEFILE" ];then #w018
  708.     #           mkdir -p ""${TMP}"${ONEFILE}"
  709.     #       fi
  710.     #       if [ -f "$ONEFILE" ] || [ -L "$ONEFILE" ];then #w018
  711.     #           DIRNAME="`dirname "$ONEFILE"`"
  712.     #           mkdir -p ""${TMP}"${DIRNAME}"
  713.     #           rm -f ""${TMP}"${ONEFILE}" # if ONEFILE already exists and it's a link, needs to be removed
  714.     #           cp -a -f "$ONEFILE" ""${TMP}"${DIRNAME}/"
  715.     #       fi
  716.     #   done
  717.     #done
  718.     sync
  719.  
  720.     cp -af /etc/eventmanager "${TMP}"/etc/ #v411
  721.  
  722.     #what about settings for a particular pc?...
  723.     m_20="$(gettext 'Hardware customisation was not chosen.')"
  724.     MSG1="$m_20"
  725.     m_21="$(eval_gettext 'Have created the /etc directory for the new ${PUPPYSFS} file.')
  726. $(gettext "It is in a 'pristine' state, but you can choose to customise it.")
  727. $(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.")
  728.  
  729. $(gettext "Click 'Yes' button to customise /etc...")
  730. $(gettext "Click 'No' button not to customise (recommended)...")"
  731.    
  732.     [ -z "$customize_etc" ]&& Xdialog --wrap --left --title "$m_01" --default-no --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "$m_21" 0 80
  733.     [ $? -eq 0 ] && customize_etc=yes || customize_etc=no
  734.     if [ "$customize_etc" = yes ];then
  735.         cp -af /etc/codepage "${TMP}"/etc/
  736.         cp -af /etc/fontmap "${TMP}"/etc/
  737.         cp -af /etc/keymap "${TMP}"/etc/
  738.         cp -af /etc/mousedevice "${TMP}"/etc/
  739.         cp -af /etc/eth0mode "${TMP}"/etc/
  740.         cp -af /etc/eth1mode "${TMP}"/etc/
  741.         cp -af /etc/resolv.conf "${TMP}"/etc/
  742.         rm -f "${TMP}"/etc/localtime #a symlink
  743.         cp -af /etc/localtime "${TMP}"/etc/
  744.         cp -af /etc/TZ "${TMP}"/etc/
  745.         cp -af /etc/cdburnerdevice "${TMP}"/etc/
  746.         cp -af /etc/dvddevice "${TMP}"/etc/
  747.         cp -af /etc/modemdevice "${TMP}"/etc/
  748.         cp -af /etc/securetelnetrc "${TMP}"/etc/
  749.         cp -af /etc/modules.conf "${TMP}"/etc/
  750.         cp -af /etc/modprobe.d "${TMP}"/etc/ #101020
  751.         cp -af /etc/rdesktoprc "${TMP}"/etc/
  752.         cp -af /etc/windowmanager "${TMP}"/etc/
  753.         cp -af /etc/X11/xorg.conf "${TMP}"/etc/X11
  754.         cp -af /etc/network-wizard "${TMP}"/etc/
  755.         cp -af /etc/simple_network_setup/* "${TMP}"/etc/simple_network_setup/
  756.         m_22="$(gettext 'These files were customised in /etc:')
  757. codepage fontmap keymap mousedevice eth0mode eth1mode resolv.conf localtime TZ cdburnerdevice dvddevice modemdevice securetelnetrc modprobe.d/* rdesktoprc windowmanager X11/xorg.conf
  758. $(gettext 'Also these directories:')
  759. network-wizard."
  760.         MSG1="$m_22"
  761.     fi
  762.  
  763.     #some files to always copy...
  764.     cp -af /etc/Puppybackgroundpicture "${TMP}"/etc/
  765.     #TODO: other gtk and jwm customisations.
  766.  
  767.     cp -f "${TMP}"/etc/DISTRO_SPECS "${TMP}"/DISTRO_SPECSupdated #keep this to put into initrd.gz.
  768.  
  769.    #######END WORKING ON /etc (Part #1) #######
  770.  
  771.  
  772.     #######START WORKING ON /var#######
  773.     rm -rf "${TMP}"/var 2> /dev/null
  774.     cp -a /initrd${PUP_LAYER}/var "${TMP}"/var #pristine var
  775.  
  776.     #.packages/ .files, copy any files installed to /var...
  777.     echo -n "" > "${TMP}"/allpkgs.files
  778.     #for ONEPKG in `ls -1 "$PKG_FILES_DIR/"*.files 2>/dev/null | tr "\n" " "`
  779.     #do
  780.     #   grep '^/var/' $ONEPKG | \
  781.     if [ ! -d /var/packages ]; then
  782.       mkdir  -p "${TMP}"/var #This is probably already done
  783.     fi
  784.     [ -d /var/packages ] && cp -arf --remove-destination /var/packages/* "${TMP}"/var/packages
  785.     if [ ${PKG_FILES_DIR:0:5} = '/var/' ]; then
  786.         #while read -r ONEFILE
  787.         #do
  788.         #   if [ -d "$ONEFILE" ] && [ ! -L "$ONEFILE" ];then #w018
  789.         #       mkdir -p ""${TMP}"${ONEFILE}"
  790.         #   fi
  791.         #   if [ -f "$ONEFILE" ] || [ -L "$ONEFILE" ];then #w018
  792.         #       DIRNAME="`dirname "$ONEFILE"`"
  793.         #       mkdir -p ""${TMP}"${DIRNAME}"
  794.         #       rm -f ""${TMP}"${ONEFILE}" # if ONEFILE already exists and it's a link, needs to be removed
  795.         #       cp -a -f "$ONEFILE" ""${TMP}"${DIRNAME}/"
  796.         #   fi
  797.         #done < <(ls -1 "$PKG_FILES_DIR/"*.files 2>/dev/null)
  798.    
  799.     #done
  800.        
  801.     # 141008: move *.files to ~/.packages/builtin_files/
  802.       if [ ${PKG_FILES_DIR:0:5} = '/var/' ]; then
  803.         touch "$PKGS_DIR/user-installed-packages"
  804.         cat "$PKGS_DIR/user-installed-packages" | \
  805.         while read -r ONEPKG
  806.         do
  807.           ONEFILE="${TMP}$PKG_FILES_DIR/`echo "$ONEPKG" | cut -f1 -d '|'`.files"
  808.           ONENAME="$BUILTIN_FILES_DIR/`echo "$ONEPKG" | cut -f2 -d '|'`"
  809.           mv -f "$ONEFILE" "$ONENAME"
  810.         done
  811.       fi
  812.       #cat "$PKGS_DIR/user-installed-packages" >> "${TMP}$PKGS_DIR/woof-installed-packages"
  813.       sort -u --key=1 --field-separator="|" "${TMP}"$PKGS_DIR/woof-installed-packages > "${TMP}"/woof-installed-packages-tmp #110722
  814.       mv -f "${TMP}"/woof-installed-packages-tmp "${TMP}"$PKGS_DIR/woof-installed-packages
  815.       echo -n "" > "${TMP}"$PKGS_DIR/user-installed-packages #v431
  816.       sync #120607
  817.       rm -f "${TMP}"$PKGS_DIR/*.files #120607
  818.       rm -f "${TMP}"$PKGS_DIR/*.remove #120607
  819.    fi
  820.     sync
  821.     [ "$CLEARPKGLOG" = "yes" ] && rm -f "${TMP}"/var/log/packages/* #120607
  822.  
  823.    #######END WORKING ON /var (Part #1)#######
  824.  
  825.    
  826.     #######Start WORKING ON "${aHome}" (Part #2) #######   
  827. for aUser in root spot fido puppy; do
  828.    aHOME=$(eval echo "~$aUser")
  829.     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.')
  830. $(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!)")
  831. $(gettext '(if you think that this program has missed out something important, please let us know..')
  832.  
  833. $(eval_gettext "After examining ${TMP}${aHome}, click 'Ok' to add ${aHome} in \${PUPPYSFS} file...")"
  834.    if  -z "$root_action" ]; then
  835.       Xdialog --wrap --left --title "$m_01" --msgbox "$m_19" 0 80
  836.     else
  837.       case "$root_action"
  838.       default) cp_user_for_remaster ;;
  839.       *) echo "Root action='$root_action' not yet defined"
  840.     fi
  841.     sync
  842.     [ "$(ls "${TMP}${aHome}/.packages/"*.files)" = "" ] && CLEARPKGLOG="yes" || CLEARPKGLOG="no" #120607 in case user copied entire "${aHome}" to "${TMP}" for boot disk.
  843.     do_mksquashfs "${TMP}${aHome}" "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  844.     sync
  845.     rm -rf "${TMP}${aHome}"
  846. done
  847.     #######END WORKING ON "${aHome}" (Part #2) ####### 
  848.    #######Start WORKING ON /etc (Part #2) #######
  849.     m_23="${MSG1}
  850.  
  851. $(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.')
  852. $(gettext "Do anything you want before clicking 'Ok'.")
  853. $(gettext '(If this program has missed something important, let me know -- Barry Kauler)')
  854.  
  855. $(eval_gettext "Click 'Ok' to add /etc in \${PUPPYSFS} file...")"
  856.    if  -z "$etc_action" ]; then
  857.       Xdialog --wrap --left  --title "$m_01" --msgbox "$m_23" 0 80
  858.     else
  859.       case "$etc_action"
  860.       default) cp_etc_for_remaster ;;
  861.       *) echo "Root action='$root_action' not yet defined"
  862.     fi
  863.  
  864.     #120606 in case user just now replaced the /etc directory...
  865.     sync
  866.     #130527 .XLOADED moved to /root (see /usr/bin/xwin), change test...
  867.     MODIFETC="$(find "${TMP}"/etc/modules -mindepth 1 -maxdepth 1 -name 'firmware.dep.inst.*')"
  868.     if [ "$MODIFETC" != "" ];then
  869.         #rm -f "${TMP}"/etc/.XLOADED
  870.         rm -f "${TMP}"/etc/modules/firmware.dep.inst.*
  871.         touch "${TMP}"/etc/personal_settings_popup_disabled
  872.         touch "${TMP}"/etc/personal_data_save_disabled
  873.     fi
  874.     [ -f "${TMP}"/etc/.XLOADED ] && rm -f "${TMP}"/etc/.XLOADED #130527 just in case old file still there.
  875.  
  876.     sync
  877.  
  878.     do_mksquashfs "${TMP}/etc" "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  879.     sync
  880.     rm -rf "${TMP}"/etc
  881.     #######END WORKING ON /etc (Part #2) #######   
  882.    
  883.    #######Start WORKING ON /var (Part #2) #######
  884.  
  885.     sync
  886.     do_mksquashfs "${TMP}"/var "${ISO_ROOT_new}"/$PUPPYSFS -keep-as-directory
  887.     sync
  888.     rm -rf "${TMP}"/var
  889.    
  890.     #s243a: TODO: add prompt to modify the var folder like was done in the etc folder
  891.    
  892.     #######END WORKING ON /var#######
  893.    
  894.     chmod a+r "${ISO_ROOT_new}"/* &>/dev/null
  895.     chmod a-x "${ISO_ROOT_new}"/*.sfs &>/dev/null
  896.  
  897. fi ###### end of long skip if, cleating new sfs
  898.  
  899. #=================================================================
  900.  
  901. m_25="$(gettext 'Almost ready to create the new ISO file!')
  902.  
  903. $(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.")
  904.  
  905. $(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.")"
  906. Xdialog --wrap --left  --title "$m_01" --msgbox "$m_25" 0 80
  907. sync
  908.  
  909. BOOTLOADER=""
  910. [ -f "${ISO_ROOT_new}"/grldr ] && BOOTLOADER="grldr"
  911. [ -f "${ISO_ROOT_new}"/isolinux.bin ] && BOOTLOADER="isolinux.bin"
  912. if [ "$BOOTLOADER" = "" ]; then
  913.     m_25_1="$(gettext 'No boot loaders found. You need isolinux.bin or grldr to make bootable CD.')
  914. $(gettext "Click 'OK' to quit.")
  915. $(eval_gettext '(leaving ${WKGMNTPT}/puppylivecdbuild/ files in existence)')"
  916.     Xdialog --wrap --left  --title "$m_01" --msgbox "$m_25_1" 0 0
  917.     exit
  918. fi
  919.  
  920. if [ "$NEW" = "yes" ]; then #120628: no change id-string for reuse
  921.     sync
  922.     #100913 need to update file DISTRO_SPECS in initrd.gz, so init script can find puppy files...
  923.     mv -f "${ISO_ROOT_new}"/initrd.gz "${TMP}" #note $WKGMNTPT may be non-linux fs.
  924.     cd "${TMP}"
  925.     gunzip initrd.gz
  926.     mkdir initrd-tree-tmp1
  927.     cd initrd-tree-tmp1
  928.     cat ../initrd | cpio -i -d -m
  929.     sync
  930.     rm -f ../initrd
  931.     cp -a -f "${TMP}"/DISTRO_SPECSupdated ./DISTRO_SPECS #see earlier.
  932.     find . | cpio -o -H newc | gzip -9 > "${ISO_ROOT_new}"/initrd.gz
  933.     sync
  934.     cd ..
  935.     rm -rf initrd-tree-tmp1
  936.     cd /root
  937. fi #120628 end
  938.  
  939. if [ -f "${ISO_ROOT_new}"/efi.img ] ; then
  940.     EFI_IMG='efi.img'
  941. fi
  942.  
  943. #build new iso file
  944. MSG="$(gettext 'ISO file not created.')"
  945. m_27="$(eval_gettext "Click 'Yes' button to create a 'custom-puppy.iso' in \${WKGMNTPT}/ (assuming that there is 100MB-300MB free space)...")
  946. $(eval_gettext "Click 'No' button (or close-box on window) to quit program at this point (leaving  \${WKGMNTPT}/puppylivecdbuild/ files in existence)...")"
  947. Xdialog --wrap --left  --title "$m_01" --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "$m_27" 0 80
  948. if [ $? -eq 0 ];then
  949.     VOLI=""
  950.     m_27_1="$(gettext 'You can add the CD volume ID.')"
  951.     VOLI=$(Xdialog --title "$m_01" --stdout --inputbox "$m_27_1" 0 60 "$SFSBASE")
  952.     [ "$VOLI" != "" ] && VOLI="-V $(echo "$VOLI"|tr ' ' '_')"
  953.     rm -f $WKGMNTPT/custom-puppy*.iso
  954.     #=
  955.     if [ "$EFI_IMG" ];then
  956.         UEFI='-uefi'
  957.         UEFI_OPT='-u'
  958.         # make uefi iso
  959.         rxvt -bg orange -fg black -title "$m_01" -e \
  960.             mkisofs -iso-level 4 -D -R $VOLI -o $WKGMNTPT/custom-puppy${UEFI}.iso \
  961.             -b ${BOOTLOADER} -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
  962.             -eltorito-alt-boot -eltorito-platform efi -b "$EFI_IMG" -no-emul-boot \
  963.                 "${ISO_ROOT_new}"/
  964.     else
  965.         rxvt -bg orange -fg black -title "$m_01" -e \
  966.             mkisofs -iso-level 4 -D -R $VOLI -o $WKGMNTPT/custom-puppy.iso \
  967.             -b ${BOOTLOADER} -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
  968.                 "${ISO_ROOT_new}"/
  969.     fi
  970.     case $BOOTLOADER in *"isolinux"*)
  971.         if which isohybrid ; then
  972.             echo "isohybrid ${UEFI_OPT} $WKGMNTPT/custom-puppy${UEFI}.iso"
  973.             isohybrid ${UEFI_OPT} "$WKGMNTPT/custom-puppy${UEFI}.iso"
  974.         fi ;;
  975.     esac
  976.     MSG="$(eval_gettext '${WKGMNTPT}/custom-puppy${UEFI}.iso created.')"
  977. fi
  978. sync
  979. m_28="$(eval_gettext '${WKGMNTPT}/puppylivecdbuild/ files left in existence.')
  980. $(gettext "Click 'Ok' button to quit...")"
  981. Xdialog --wrap --left  --title "$m_01" --msgbox "$MSG
  982. $m_28" 0 0
  983.  
  984. ### END ###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement