SHARE
TWEET

/initrd/init (tahrpup)

s243a Dec 27th, 2017 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. # see also /sbin scripts: usablefs, set_plang, wait4usb, switch
  3. #
  4. # _FN = _FILENAME
  5. # _MP = _MOUNTPOINT
  6. #
  7.  
  8. #Aufs layers setup by this script...
  9. #aufs layers:            RW (top)      RO1             RO2              PUPMODE
  10. #First boot (or pfix=ram):  tmpfs                         pup_xxx.sfs      5
  11. #pup_save is a partition:   PDEV1                         pup_xxx.sfs      6
  12. #ditto, but flash drive:    tmpfs         PDEV1           pup_xxx.sfs      7
  13. #Normal running puppy:      pup_save.3fs                  pup_xxx.sfs      12
  14. #ditto, but flash drive:    tmpfs         pup_save.3fs    pup_xxx.sfs      13
  15. #Multisession cd/dvd:       tmpfs         folders         pup_xxx.sfs      77
  16.  
  17. ######################## localization ########################
  18. #ex: /locale/<locale>/init.mo
  19. L_WINDOWS_HIBERNATED="ERROR: Windows NTFS hibernated partition, cannot mount"
  20. L_DONE="done"
  21. L_FAILED="failed"
  22. L_DUMPING_BOOTINIT_LOG="Dumping last lines of /tmp/bootinit.log..."
  23. L_DUMPING_KERNEL_LOG="Dumping last lines of kernel log..."
  24. L_ERROR_IS_TOO_CRITICAL="Error is too critical, dropping out to console..."
  25. L_PAUSING_60_SECONDS="Pausing for 60 seconds..."
  26. L_LOADING_FILE="Loading the '%s' %s file..." #printf
  27. L_CANNOT_RESIZE_PUPSAVE="SORRY, cannot resize %s" #printf
  28. L_INCREASING_PUPSAVE='Increasing %s by %s Kbytes, please wait...' #printf
  29. L_LOADING_PUPSAVE='Loading personal storage %s [%s]...' #printf
  30. L_LOADING_PUPSAVE_FILE='Loading personal storage %s [%s] (%s)...' #printf
  31. L_UPGRADE_MSG_1="This personal storage was last used with version %s of Puppy." #printf
  32. L_UPGRADE_MSG_2="Hit the ENTER key only if it is okay to upgrade this file, or to not use it and boot up in RAM only type any other printable character."
  33. L_UPGRADE_MSG_3="ENTER only to upgrade: "
  34. L_UPGRADE_NO="Backing off, not using personal storage, booting in RAM only, PUPMODE=5..."
  35. L_LOADING_FROM_CD="Loading folder %s from CD/DVD..." #printf
  36. L_RAM_DISK_FULL="RAM disk full, copy failed at %s" #printf
  37. L_ADDING_SAVE_LAYER_FAILED="adding %s to aufs stack failed." #printf
  38. L_WAITING_FOR_USB="Waiting for USB storage."
  39. L_LOADING_KEYBOARD_LAYOUT="Loading '%s' keyboard layout..." #printf
  40. L_COPY_MESSAGE="copying to ram"
  41. L_LOAD_MESSAGE="main"
  42. L_PRE_MESSAGE="Loading puppy main sfs file."
  43. L_ERR_PDRV_INCOMPLETE="%s information is incomplete." #printf
  44. L_ERR_ONEPART_NOT_MOUNTED="%s is not mounted." #printf
  45. L_ERR_ONEPART_NOT_OK="%s %s is not Ok." #printf
  46. L_ERR_ONEPART_MOUNT_SFS_FAILED="%s %s mount of sfs failed." #printf
  47. L_ERR_AUFS_SFS_FAILED="aufs mount of %s failed." #printf
  48. L_ERR_TYPE_PUPSAVE="Type a number to choose which personal file to use:"
  49. L_DROPPED_TO_INITRD_SHELL="Dropped to initramfs shell. Type 'exec switch' to continue booting Puppy."
  50. L_SWITCH_ROOT="Performing a 'switch_root' to the layered filesystem..."
  51. L_CONTINUING_LOADING="...continuing with loading %s..." #printf
  52. L_FOLDER_MARKED_BAD="Folder %s marked bad." #printf
  53. L_0_NONE="0  none"
  54. L_ERROR_FAILED_AUFS_STACK='Failed to create empty aufs stack'
  55. L_ADDING_MODULE="Adding module %s" #printf
  56. L_NO_DISTRO_SPECS="No DISTRO_SPECS file found, assuming that personal storage is empty."
  57. L_DEBUG_SAVE="To save debug info to a partition, type 'debugsave'"
  58. L_PASSWORD="Password:"
  59. L_PASSWORD_MSG_1="NOTICE: As you type your password nothing will be displayed on the screen."
  60. L_PASSWORD_MSG_2="This is a security measure. Just type it in then press ENTER key..."
  61. L_SFFS_ERROR="ERROR: savefile filesystem is not ext2/3/4"
  62.  
  63. ##############################################################
  64.  
  65. /sbin/usablefs # mount: /proc /sys /dev / (proc sysfs devtmpfs rootfs)
  66.  
  67. export TERM="xterm"
  68. export TERMINFO="/usr/share/terminfo"
  69. export LANG=C
  70. PATH="/bin:/sbin"
  71. KERNELVER="$(uname -r)"
  72. VFAT_OUT_PARAM='shortname=mixed,quiet,utf8' #see also /sbin/set_plang
  73. . /DISTRO_SPECS #v412 has DISTRO_VERSION, DISTRO_FILE_PREFIX
  74.  
  75. #precaution - if DISTRO_SPECS was not processed by 3builddistro...
  76. [ ! "$DISTRO_ZDRVSFS" ] && DISTRO_ZDRVSFS="zdrv_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
  77. [ ! "$DISTRO_FDRVSFS" ] && DISTRO_FDRVSFS="fdrv_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
  78. [ ! "$DISTRO_ADRVSFS" ] && DISTRO_ADRVSFS="adrv_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
  79. [ ! "$DISTRO_YDRVSFS" ] && DISTRO_YDRVSFS="adrv_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
  80. [ ! "$DISTRO_PUPPYSFS" ] && DISTRO_PUPPYSFS="puppy_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
  81.  
  82. # filenames specified in DISTRO_SPECS: DISTRO_ZDRVSFS, DISTRO_PUPPYSFS...
  83. Z_DEF_FN="$DISTRO_ZDRVSFS"
  84. F_DEF_FN="$DISTRO_FDRVSFS"
  85. A_DEF_FN="$DISTRO_ADRVSFS"
  86. Y_DEF_FN="$DISTRO_YDRVSFS"
  87. P_DEF_FN="$DISTRO_PUPPYSFS"
  88.  
  89. [ $loglevel ] && LOGLEVEL=$loglevel #v2.22
  90.  
  91. #=============================================================
  92. #                        FUNCTIONS
  93. #=============================================================
  94.  
  95. fsck_func() {
  96. # "$1" - partition device - ex: /dev/sdb2
  97. # "$2" - fstype - ex: ext2
  98.  case $2 in
  99.   ext2|ext3|ext4) fsck_app='e2fsck' ; fsck_OPT='-y' ;;
  100.   vfat|msdos) fsck_app='fsck.fat' ; fsck_OPT='-y' ;;
  101.   exfat) fsck_app='exfatfsck' ; fsck_OPT='' ;;
  102.   *) return ;;
  103.  esac
  104.  which "${fsck_app}" || {
  105.    echo "WARNING: '${fsck_app}' not found"
  106.    FSCKDPARTS="${FSCKDPARTS}${1}|"
  107.    return
  108.  }
  109.  if [ "$(echo "$FSCKDPARTS" | grep "${1}|")" = "" ];then
  110.   ${fsck_app} ${fsck_OPT} ${1} > /dev/console 2>&1 || sleep 3 #so the user has time to read the error msg..
  111.   FSCKDPARTS="${FSCKDPARTS}${1}|"
  112.  fi
  113. }
  114.  
  115. mntfunc() {
  116.  MNT_T="$1"    #ex: vfat
  117.  MNT_DEV="$2"  #ex: /dev/sda1
  118.  MNT_DIR="$3"  #ex: /mnt/sda1
  119.  MNT_O="$4"    #ex: noatime   [optional]
  120.  MNT_DSK="${MNT_DEV:5:3}"
  121.  if [ "$PTRIM" = "yes" -a "$MNT_DSK" != "" -a "$(cat /sys/block/$MNT_DSK/queue/rotational)" = "0" ];then
  122.   if [ "$MNT_T" = "ext4" -o "$MNT_T" = "f2fs" ];then
  123.    if [ "$MNT_O" = "" ];then
  124.     MNT_O="discard"
  125.    else
  126.     MNT_O="${MNT_O},discard"
  127.    fi
  128.   fi
  129.  fi
  130.  [ "$PFSCKP" = "yes" ] && fsck_func "$MNT_DEV" "$MNT_T"
  131.  case $MNT_T in
  132.   ntfs)
  133.    ntfs-3g $MNT_DEV $MNT_DIR -o umask=0,no_def_opts,noatime,rw,silent 2>/dev/null #default is rw. 130211 add silent.
  134.    ntfsRETVAL=$?
  135.    [ $ntfsRETVAL -eq 0 ] && return 0
  136.    if [ $ntfsRETVAL -eq 14 ];then
  137.     echo -e "\\033[1;31m${L_WINDOWS_HIBERNATED}\\033[0;39m" >/dev/console #31=red
  138.     return 14
  139.    else
  140.     ntfs-3g $MNT_DEV $MNT_DIR -o umask=0,no_def_opts,noatime,rw,force,silent 2>/dev/null #130211 add silent.
  141.    fi
  142.   ;;
  143.   vfat)  mount -t $MNT_T -o $VFAT_OUT_PARAM $MNT_DEV $MNT_DIR ;;
  144.   exfat) mount.exfat-fuse $MNT_DEV $MNT_DIR ;;
  145.   *)
  146.    if [ "$MNT_O" = "" ];then
  147.     mount -t $MNT_T $MNT_DEV $MNT_DIR
  148.    else
  149.     mount -t $MNT_T -o $MNT_O $MNT_DEV $MNT_DIR
  150.    fi
  151.   ;;
  152.  esac
  153.  return $?
  154. }
  155.  
  156. check_status() #args: [-critical] $RET_VAL "$ERROR_MSG"
  157. {
  158.   ERROR_CRITICAL=""
  159.   [ "$1" = "-critical" ] && { ERROR_CRITICAL="yes" ; shift; }
  160.   RET_VAL=$1
  161.   shift
  162.   ERROR_MSG="$@"
  163.   if [ $RET_VAL -eq 0 ] ; then
  164.     echo -en "\\033[74G" >/dev/console #move to column 72. 110426: 74
  165.     echo -e "\\033[1;32m${L_DONE}\\033[0;39m" >/dev/console #32=green
  166.   else
  167.     echo -en "\\033[72G" >/dev/console #move to column 72.
  168.     echo -e "\\033[1;31m${L_FAILED}\\033[0;39m" >/dev/console #31=red
  169.     echo -e "\\033[1;35m${L_DUMPING_BOOTINIT_LOG}\\033[0;39m" >/dev/console #35=purple
  170.     echo -en "\\033[1;31m" >/dev/console #31=red
  171.     cat /tmp/bootinit.log | tail -n 4 >/dev/console
  172.     echo -en "\\033[0;39m" >/dev/console
  173.     echo -e "\\033[1;35m${L_DUMPING_KERNEL_LOG}\\033[0;39m" >/dev/console #35=purple
  174.     echo -en "\\033[1;31m" >/dev/console #31=red
  175.     dmesg | tail -n 4 >/dev/console
  176.     echo -en "\\033[0;39m" >/dev/console
  177.     #exit to initial ramdisk shell...
  178.     [ "$RDSH" != "" ] && exec /bin/sh >/dev/console 2>&1
  179.     if [ "$ERROR_CRITICAL" = "yes" ] ; then
  180.       echo -en "\\033[1;35m" >/dev/console #35=purple
  181.       [ "$ERROR_MSG" != "" ] && echo "*** $ERROR_MSG" >/dev/console
  182.       echo "*** ${L_ERROR_IS_TOO_CRITICAL}" >/dev/console
  183.       echo -en "\\033[0;39m" >/dev/console
  184.       echo -e "\\033[1;32m*** $L_DEBUG_SAVE\\033[0;39m" >/dev/console
  185.       exec /bin/sh >/dev/console 2>&1
  186.     else
  187.       echo "${L_PAUSING_60_SECONDS}" >/dev/console
  188.       sleep 60
  189.     fi
  190.   fi
  191. }
  192.  
  193. decode_spec() {
  194.  ONE_BP_ID=""; ONE_BP_FN=""
  195.  [ "${1}" ] || return
  196.  ONE_BP_ID="$(echo "$1" | cut -f 1 -d ':')"
  197.  ONE_BP_FN="$(echo "$1" | cut -f 2 -d ':')"
  198.  [ "$ONE_BP_FN" = "$ONE_BP_ID" ] && ONE_BP_FN=""
  199.  [ "$ONE_BP_FN" ] && [ "${ONE_BP_FN:0:1}" != "/" ] && ONE_BP_FN="$PSUBDIR/$ONE_BP_FN"
  200. }
  201.  
  202. decode_id() {
  203.  ONE_PART=""
  204.  [ "${1}" ] || return
  205.  if [ "$(echo -n ${1} | grep -E '^[a-z]+[0-9]')" -a "$(grep -m1 "${1}$" /proc/partitions)" ];then
  206.   ONE_PART="$1"  #is a real partition
  207.  else
  208.   [ "$BLKIDOUT" ] || BLKIDOUT="$(blkid)"
  209.   ONE_PART="$(echo "$BLKIDOUT" | grep -m1 -E " LABEL=.${1}| UUID=.${1}" | cut -f1 -d: | cut -f3 -d/)" #is LABEL or UUID
  210.  fi
  211. }
  212.  
  213. decode_other_ids() {
  214.  #get ONE_PART from DEV or ID specified in sfs boot params
  215.  decode_id "$Z_BP_ID"
  216.  [ "$ONE_PART" ] && { Z_PART="$ONE_PART"; Z_BP_ID=""; }
  217.  decode_id "$F_BP_ID"
  218.  [ "$ONE_PART" ] && { F_PART="$ONE_PART"; F_BP_ID=""; }
  219.  decode_id "$A_BP_ID"
  220.  [ "$ONE_PART" ] && { A_PART="$ONE_PART"; A_BP_ID=""; }
  221.  decode_id "$Y_BP_ID"
  222.  [ "$ONE_PART" ] && { Y_PART="$ONE_PART"; Y_BP_ID=""; }
  223.  decode_id "$SAVE_BP_ID"
  224.  [ "$ONE_PART" ] && { SAVEPART="$ONE_PART"; PSAVEPART="$ONE_PART"; SAVE_BP_ID=""; }
  225. }
  226.  
  227. log_part_id() {
  228. # "$1" - partition id - ex: Work or sdc4
  229.  echo "Partition ${1} not found."
  230. }
  231.  
  232. ensure_mounted() {
  233. # "$1" - partition - ex: sda3
  234. # "$2" - mountpoint - ex: /mnt/pdrv
  235.  ONE_MP="$(mount | grep -m1 "/dev/${1} " | cut -f 3 -d ' ')"
  236.  [ "$ONE_MP" ] && return
  237.  ONE_FS="$(echo "$HAVE_PARTS" | grep -m1 "${1}|" | cut -f 2 -d '|')"
  238.  ONE_MP="${2}"
  239.  [ -d "$ONE_MP" ] || mkdir -p $ONE_MP
  240.  mntfunc $ONE_FS /dev/${1} $ONE_MP #-t $ONE_FS /dev/$ONE_PART $ONE_MP
  241.  if [ $? -ne 0 ] ; then
  242.   sleep 3 # usb optical drive showing as /sys/block/sr0, but won't mount, needs more delay...
  243.   mntfunc $ONE_FS /dev/${1} $ONE_MP
  244.   [ $? -ne 0 ] && { echo "${1} on $ONE_MP as $ONE_FS mount failed."; ONE_MP=""; return 1; }
  245.  fi
  246.  # fsckme.flg is created by rc.sysinit and deleted by rc.shutdown
  247.  # this flag will be set for any prior improper shutdown. if have lots of installations
  248.  # of puppy on the pc, the flag may not even be for this install of puppy, however, this is
  249.  # the simplest implementation...
  250.  if [ -f ${ONE_MP}/fsckme.flg ] ; then
  251.   #sda1,ext3,/PUPPYBOOT/precise/precisesave.4fs
  252.   FSCKME="`cat ${ONE_MP}/fsckme.flg`"
  253.   echo -e "${ONE_MP}/fsckme.flg\n  $FSCKME"
  254.   FSCK_PART="$(echo "$FSCKME" | cut -f 1 -d ",")"
  255.   FSCK_EXT="$(echo "$FSCKME" | cut -f 2 -d ",")"
  256.   FSCK_SAVEFILE="$(echo "$FSCKME" | cut -f 3 -d ",")"
  257.   rm -f ${ONE_MP}/fsckme.flg
  258.   [ "$FSCK_SAVEFILE" ] && PFSCK="yes"
  259.   [ "$PFSCKP" = "yes" ] && return # boot param, partition already fsck'ed
  260.   case ${FSCK_EXT} in ext2|ext3|ext4|vfat|msdos|exfat)
  261.     umount ${ONE_MP}
  262.     [ "$FSCKME" ] && fsck_func /dev/${FSCK_PART} ${FSCK_EXT}
  263.     ensure_mounted "$1" "$2" ;;
  264.   esac
  265.  fi
  266. }
  267.  
  268. ensure_save_mounted() {
  269.  ensure_mounted "$SAVEPART" "${SAVE_MP}"
  270.  SAVE_MP="$ONE_MP"
  271.  [ "${SAVE_MP}" ] && SAVE_FS="$ONE_FS"
  272. }
  273.  
  274. find_drv_file() {
  275. # "$1" - specified filename - ex: /pup/mydrv-1.2.3.sfs
  276. # "$2" - default filename - ex: adrv_tahr_6.0.5.sfs
  277.  ONE_FN=""
  278.  [ "${1}" ] || [ "${2}" ] || return
  279.  if [ "${1}" ];then
  280.   ONE_TRY_FN="${1}"
  281.   [ "${ONE_TRY_FN:$((${#ONE_TRY_FN} - 1))}" = "/" ] && ONE_TRY_FN="${ONE_TRY_FN}${2}" #last char
  282.  else
  283.   ONE_TRY_FN="${PSUBDIR}/${2}"
  284.  fi
  285.  [ -f "${ONE_MP}${ONE_TRY_FN}" ] && ONE_FN="$ONE_TRY_FN"
  286. }
  287.  
  288. find_onepupdrv() {
  289. # "$1" - partition - ex: sda3
  290. # "$2" - specified filename - ex: /pup/mydrv-1.2.3.sfs
  291. # "$3" - default filename - ex: adrv_tahr_6.0.5.sfs
  292. # "$4" - prefix for "drv" mountpoint - ex: a
  293.  ONE_FN=""
  294.  [ "${2}" ] || [ "${3}" ] || return
  295.  [ "${4}" ] || return
  296.  if [ "${1}" ];then
  297.   ONE_PART="${1}"
  298.  else
  299.   ONE_PART="$P_PART"
  300.  fi
  301.  [ "$ONE_PART" ] || return
  302.  ensure_mounted "$ONE_PART" "/mnt/${4}drv"
  303.  [ "$ONE_MP" ] || return
  304.  find_drv_file "${2}" "${3}"
  305.  [ "$ONE_FN" = "" -a "${2}" ] && echo "$ONE_PART, $ONE_TRY_FN file not found."
  306. }
  307.  
  308. setup_loop_sfs() {
  309. # "$1" - sfs filename - ex: /mnt/dev_save/puppy/tahr/puppy_tahr_6.0.5.sfs
  310.  ONE_LOOP="$(losetup -f)"
  311.  losetup $LO_OPT $ONE_LOOP ${1}
  312.  [ $? -eq 0 ] || { LO_OPT=""; losetup $LO_OPT $ONE_LOOP ${1}; }
  313. }
  314.  
  315. load_sfs_file() {
  316.  [ "$LOADMSG" ] && echo -n "$(printf "${L_LOADING_FILE}" "$ONE_BASENAME" "$LOADMSG")" > /dev/console
  317.  if [ "$COPY2RAM" = "" ];then
  318.   COPY2RAM="no"
  319.   #if there's heaps of ram, copy puppy.sfs to a tmpfs...
  320.   #v405 fast media plus more than 256MB ram then definitely worth copying to ram...
  321.   SIZESFSK=$(du -k $ONE_FN | cut -f 1)
  322.   SIZESFSK=$(($SIZESFSK + 1000)) #some slack.
  323.   MINRAM2CPY=$(($SIZESFSK * 2)) #100222 technosaurus: in case of very big puppies.
  324.   #decide whether to copy .sfs's to ram
  325.   [ "$PNOCOPY" = "yes" ] || COPYCONTENDER='yes'
  326.   [ "$PCOPY" = "yes" ] && COPYCONTENDER='yes'
  327.   [ "$PRAMONLY" = "yes" ] && COPYCONTENDER='yes'
  328.   [ "$COPYCONTENDER" = "yes" ] && [ $RAMSIZE -gt 400000 ] && [ $RAMSIZE -gt $MINRAM2CPY ] && COPY2RAM="yes"
  329.  fi
  330.  if [ "$COPY2RAM" = "yes" ];then
  331.   SIZEZK=$(du -k $ONE_FN | cut -f 1)
  332.   TFREEK=$(df | grep -m1 ' /mnt/tmpfs' | tr -s ' ' | cut -f 4 -d ' ')
  333.   if [ $TFREEK -gt $SIZEZK ];then
  334.    if [ "$ONE_MP" = "" ];then #101101 humongous initrd.
  335.     mv -af $ONE_FN /mnt/tmpfs/
  336.    else
  337.     [ "$LOADMSG" ] && [ "$COPYMSG" ] && echo -en " \\033[1;35m${COPYMSG}\\033[0;39m" > /dev/console #purple.
  338.     TOTAL_SIZEK_SFS_RAM=$(($TOTAL_SIZEK_SFS_RAM + $SIZEZK))
  339.     cp -af $ONE_FN /mnt/tmpfs/
  340.    fi
  341.    sync
  342.    setup_loop_sfs /mnt/tmpfs/$ONE_BASENAME
  343.   else
  344.    setup_loop_sfs $ONE_FN
  345.    [ "$ONE_PART" != "rootfs" ] && KEEPMOUNTED="${KEEPMOUNTED}${ONE_PART} "
  346.   fi
  347.  else
  348.   setup_loop_sfs $ONE_FN
  349.   [ "$ONE_PART" != "rootfs" ] && KEEPMOUNTED="${KEEPMOUNTED}${ONE_PART} "
  350.  fi
  351.  SFS_MP="/pup_${ONE_SFX}"
  352.  [ "$ONE_SFX" = "p" ] && SFS_MP="/pup_ro2"
  353.  [ -d "$SFS_MP" ] || mkdir $SFS_MP
  354.  mount -r -t squashfs -o noatime $ONE_LOOP $SFS_MP > /dev/console 2>&1
  355.  STATUS=$?
  356.  [ $STATUS -eq 0 ] && ONE_LAYER="$SFS_MP=rr"
  357.  [ "$LOADMSG" ] && check_status $STATUS
  358. }
  359.  
  360. setup_onepupdrv() {
  361. # "$1" - sfs spec - ex: sdb2,ext4,/pup/mydrv-1.2.3.sfs
  362. # "$2" - suffix for "pup_" branch directory - ex: a
  363. # "$3" - prepend after rw layer indicator - ex: p
  364.  ONE_LAYER=""
  365.  [ "$1" ] || return 1
  366.  [ "$2" ] || return 1
  367.  ONE_PART="$(echo "${1}" | cut -f 1 -d ',')"
  368.  [ "$ONE_PART" ] || return 1
  369.  ONE_REL_FN="$(echo "${1}" | cut -f 3 -d ',')"
  370.  [ "$ONE_REL_FN" ] || return 1
  371.  ONE_SFX="${2}"
  372.  ONE_PREP="${3}"
  373.  if [ "$ONE_PART" = "rootfs" ];then #humongous initrd.
  374.   ONE_MP="" #actually it's '/'.
  375.   COPY2RAM='yes' #actually it is already in ram, but load_sfs_file code puts it in a tmpfs.
  376.  else
  377.   if [ "$ONE_PART" = "$P_PART" ];then
  378.    ONE_MP="$P_MP"
  379.   else
  380.    ONE_MP="$(mount | grep -m1 "/dev/$ONE_PART " | cut -f 3 -d ' ')"
  381.    [ "$ONE_MP" ] || return 2
  382.   fi
  383.  fi
  384.  ONE_FN="${ONE_MP}${ONE_REL_FN}"
  385.  ONE_BASENAME="$(basename $ONE_REL_FN)"
  386.  #validate sfs here
  387.  [ -s "$ONE_FN" ] || return 3 #sfs not Ok
  388.  load_sfs_file
  389.  [ "$ONE_LAYER" ] || return 4 #sfs mount failed
  390.  if [ "$ONE_PREP" ];then
  391.   echo "mount -o remount,add:1:$ONE_LAYER /pup_new" #debug
  392.   mount -o remount,add:1:$ONE_LAYER /pup_new
  393.   [ $? -eq 0 ] || return 5
  394.  else
  395.   echo "mount -o remount,append:$ONE_LAYER /pup_new" #debug
  396.   mount -o remount,append:$ONE_LAYER /pup_new
  397.   [ $? -eq 0 ] || return 5
  398.  fi
  399.  NEWUNIONRECORD="${NEWUNIONRECORD}${ONE_BASENAME} "
  400.  return 0
  401. }
  402.  
  403. format_bytes() {
  404.  [ $1 ] || return
  405.  if [ $1 -gt 1073741824 ] ; then #GB
  406.   SIZEX="`dc $1 1073741824 \/ p`"
  407.   SIZEX="`printf "%.1f" $SIZEX`"
  408.   SIZEX="${SIZEX%.0}G"
  409.  else
  410.   SIZEX="$(($1/1048576))M"
  411.  fi
  412.  echo ${SIZEX}
  413. }
  414.  
  415.  
  416. load_ext_file() { #ex: stretchsave.4fs
  417.  SAVE_SZ_FN=""
  418.  RESIZE_FN="$(dirname $SAVE_FN)/pupsaveresizenew.txt"
  419.  #delete following line when resize file location is fixed
  420.  [ -f "$RESIZE_FN" ] || RESIZE_FN="${SAVE_MP}/pupsaveresizenew.txt"
  421.  #-- resize savefile?.. see /usr/sbin/resizepfile.sh
  422.  if [ -f "$RESIZE_FN" ] ; then
  423.    #(1) resize extX file. see below (2)
  424.    . $RESIZE_FN #$PUPSAVEFILEX $KILOBIG
  425.    if [ "$PUPSAVEFILEX" = "$SAVE_REL_FN" ] ; then
  426.     if [ ! -e /bin/resize2fs ];then
  427.      echo -en "\\033[1;31m" > /dev/console
  428.      echo -n "$(printf "${L_CANNOT_RESIZE_PUPSAVE}" "$PUPSAVEFILEX")" > /dev/console #31=red
  429.      echo -en "\\033[0;39m" > /dev/console
  430.      rm -f $RESIZE_FN
  431.     else
  432.      SAVE_SZ_FN="$SAVE_FN"
  433.      rm -f $RESIZE_FN
  434.      echo > /dev/console
  435.      echo -n "$(printf "${L_INCREASING_PUPSAVE}" "$PUPSAVEFILEX" "$KILOBIG")" >/dev/console
  436.      dd if=/dev/zero bs=1024 count=$KILOBIG >> $SAVE_SZ_FN
  437.      sync
  438.     fi
  439.    fi
  440.  fi
  441.  #--
  442.  ONE_LOOP="$(losetup -f)"
  443.  #-- is the ${DISTRO_FILE_PREFIX}save encrypted?...
  444.  if echo "$SAVE_FN" | grep -q '_crypt' ;then
  445.    #mount encrypted savefile
  446.    case $SAVE_FN in
  447.     *cryptx*) CRYPTO='-e 1' ;;
  448.     *) CRYPTO='-e aes' ;;
  449.    esac
  450.    echo >/dev/console
  451.    echo "${L_PASSWORD_MSG_1}"  >/dev/console
  452.    echo "${L_PASSWORD_MSG_2}" >/dev/console
  453.    echo -e "\\033[1;36m" >/dev/console #aqua-blue
  454.    echo -n "${L_PASSWORD} " >/dev/console
  455.    echo -en "\\033[0;39m" >/dev/console
  456.    read -s MYPASS
  457.    echo "$MYPASS" | losetup-222 -p 0 $CRYPTO $ONE_LOOP $SAVE_FN
  458.  else
  459.    losetup $ONE_LOOP $SAVE_FN
  460.  fi
  461.  #--
  462.  SFFS=$(blkid "$SAVE_FN" | grep -o ' TYPE=".*' | cut -f 2 -d '"')
  463.  case $SFFS in #savefile filesystem
  464.    ext2|ext3|ext4) ok=1 ;;
  465.    *) # might be encrypted - unrecognizable..
  466.      case "$SAVE_FN" in #savefile can have any extension/name. but must one of these strings
  467.        *".2fs"*) SFFS=ext2 ;;
  468.        *".3fs"*) SFFS=ext3 ;;
  469.        *".4fs"*) SFFS=ext4 ;;
  470.        *) echo "$L_SFFS_ERROR" #debug
  471.           echo -e "\\033[1;31m${L_SFFS_ERROR}\\033[0;39m" >/dev/console #31=red
  472.           ;;
  473.      esac
  474.      ;;
  475.  esac
  476.  if [ "$PFSCK" = "yes" ] ; then
  477.    echo "" > /dev/console
  478.    fsck_func "$ONE_LOOP" "$SFFS"
  479.  fi
  480.  #--
  481.  if [ "$SAVE_SZ_FN" ] ; then
  482.    #(2) resize extX filesystem - fill extX file. see above (1)
  483.    fsck_func "$ONE_LOOP" "$SFFS"
  484.    resize2fs -pf "$ONE_LOOP" #no size, will fill all of file.
  485.    sync
  486.    check_status 0 #note, e2fsck gives an error even though it works. v2.21 maybe okay now.
  487.    echo -n "$(printf "${L_CONTINUING_LOADING}" "$PUPSAVEFILE")" > /dev/console
  488.  fi
  489.  #--
  490.  [ -d "$SAVE_LAYER" ] || mkdir $SAVE_LAYER
  491.  echo "mount -t $SFFS -o noatime $ONE_LOOP $SAVE_LAYER" #debug
  492.  mount -t $SFFS -o noatime $ONE_LOOP $SAVE_LAYER
  493.  if [ $? -ne 0 ] ; then
  494.    echo 'Warning: PUPSAVE=""' #debug
  495.    PUPSAVE=""
  496.    losetup -d $ONE_LOOP
  497.  fi
  498. }
  499.  
  500.  
  501. setup_save_file(){
  502.  SAVE_REL_FN="$(echo "$PUPSAVE" | cut -f 3 -d ',')"
  503.  if [ -f "${SAVE_MP}${SAVE_REL_FN}" ];then #savefile
  504.   PUPSAVE_SIZE="$(format_bytes $(stat -c %s "${SAVE_MP}${SAVE_REL_FN}"))"
  505.   echo -n "$(printf "${L_LOADING_PUPSAVE_FILE}" "$SAVE_REL_FN" "$SAVEPART" "$PUPSAVE_SIZE")" > /dev/console
  506.  else
  507.   echo -n "$(printf "${L_LOADING_PUPSAVE}" "$SAVE_REL_FN" "$SAVEPART")" > /dev/console
  508.  fi
  509.  rm -r -f "$SAVE_LAYER"
  510.  SAVE_FN="${SAVE_MP}${SAVE_REL_FN}"
  511.  if [ -f "$SAVE_FN" ];then #savefile. ex: stretchsave.4fs
  512.   echo "--SAVEFILE-- $SAVE_FN" #debug
  513.   load_ext_file
  514.  elif [ -d "$SAVE_FN" ];then #savefolder
  515.   echo "--SAVEFOLDER-- $SAVE_FN" #debug
  516.   ln -sv "$SAVE_FN" "$SAVE_LAYER"
  517.  else
  518.   PUPSAVE=""
  519.  fi
  520.  #[ "$PUPSAVE" ] && decrypt directory at SAVE_LAYER
  521.  if [ "$PUPSAVE" ];then
  522.   SAVE_NAME="$(basename $SAVE_REL_FN)"
  523.   #- fix for empty pupsaves (missing /initrd/DISTRO_SPECS)
  524.   if [ ! -f "$SAVE_LAYER/initrd/DISTRO_SPECS" ] ; then
  525.     touch /tmp/rc_update_force_pm5 # see /etc/rc.d/rc.update
  526.     PCLEAN=""
  527.   fi
  528.   #-
  529.   if [ "$PCLEAN" != "yes" -a -f "$SAVE_LAYER/initrd/DISTRO_SPECS" ];then
  530.    OLDDISTRO_VERSION="$(grep '^DISTRO_VERSION' $SAVE_LAYER/initrd/DISTRO_SPECS | cut -f 2 -d '=' | cut -f 2 -d "'" | cut -f 2 -d '"' | cut -f 1 -d ' ')"
  531.    if [ "$DISTRO_VERSION" != "$OLDDISTRO_VERSION" ]; then
  532.     echo "" >/dev/console
  533.     echo -en "\\033[1;36m" >/dev/console #36=aquablue
  534.     echo "$(printf "${L_UPGRADE_MSG_1}" "$OLDDISTRO_VERSION")" >/dev/console
  535.     echo "${L_UPGRADE_MSG_2}"  >/dev/console
  536.     echo -n "${L_UPGRADE_MSG_3}"  >/dev/console
  537.     echo -en "\\033[0;39m" >/dev/console
  538.     read noupgradesf
  539.     if [ "$noupgradesf" != "" ];then
  540.      echo -e "\\033[1;35m${L_UPGRADE_NO}\\033[0;39m" >/dev/console #35=purple
  541.      PUPSAVE=""
  542.     else
  543.      PCLEAN="yes"
  544.     fi
  545.    fi
  546.   fi
  547.   if [ "$PCLEAN" = "yes" ];then
  548.    #do upgrade processing
  549.    touch /tmp/version_update_flag
  550.    CURDIR="$(pwd)"
  551.    cd "$SAVE_LAYER"
  552.    #delete critical system files
  553.    #keep rc.local - user customisations and/or fixes.
  554.    echo "Removing $(ls ./lib/modules/$KERNELVER/modules.*)"
  555.    rm -f ./lib/modules/$KERNELVER/modules.*
  556.    RC_STUFF="$(ls ./etc/rc.d/rc.* | grep -v "/rc.local$" | tr '\n' ' ')"
  557.    echo "Removing $RC_STUFF"
  558.    rm -f $RC_STUFF
  559.    echo "Removing $(ls ./etc/rc.d/funct*)"
  560.    rm -f ./etc/rc.d/funct*
  561.    #iterate over all files in save
  562.    for ONE_FILE in $(find . \( -type f -or -type l \) -print); do
  563.     ONE_BASE="${ONE_FILE##*/}" #basename
  564.     if [ "${ONE_BASE:0:4}" = ".wh." ]; then #remove most whiteout files
  565.      [ "${ONE_BASE:4:4}" = ".wh." ] && continue #internal aufs files
  566.      [ "${ONE_FILE%/*}" = "./root/.config/autostart" ] && continue #keep autostart changes
  567.      echo "Removing ${ONE_FILE}"
  568.      rm -f "$ONE_FILE" #remove whiteout file
  569.     fi
  570.    done
  571.    cd "$CURDIR"
  572.    sync
  573.   fi
  574.   check_status 0
  575.  else
  576.   check_status 1
  577.  fi
  578.  if [ ! "$PUPSAVE" ] ; then
  579.    echo "No pupsave. Setting PUPMODE 5" #debug
  580.    PUPMODE=5
  581.    SAVE_MP=""
  582.    SAVE_LAYER=""
  583.  fi
  584. }
  585.  
  586. setup_save_part() {
  587.  rm -r -f $SAVE_LAYER
  588.  ln -sv ${SAVE_MP} $SAVE_LAYER
  589.  SAVE_FN="${SAVE_MP}" #for after switch symbolic link
  590.  SAVE_NAME="$SAVEPART"
  591. }
  592.  
  593. copy_folders() { #SAVE_LAYER=/pup_ro1
  594.  echo -e "\n-------------------- copy_folders" #debug
  595.  echo "SAVE_MP=$SAVE_MP"
  596.  DESTDIR="/mnt/tmpfs/pup_ro1"
  597.  [ -d "$DESTDIR" ] || mkdir -p $DESTDIR
  598.  rm -r -f "$SAVE_LAYER"
  599.  SAVE_FN="$DESTDIR"
  600.  ln -s $DESTDIR $SAVE_LAYER
  601.  #BKFOLDERS now set in check for pupmode=77
  602.  BKLASTFOLDER="$(echo "${BKFOLDERS}" | head -n 1)"
  603.  #a boot option allows ignore last n sessions, also need to create a badlist...
  604.  if [ "$PIGNORELAST" ];then
  605.   BKBADLIST="$(echo "${BKFOLDERS}" | head -n ${PIGNORELAST})"
  606.   if [ -f ${SAVE_MP}/${BKLASTFOLDER}/.badfolders ];then
  607.    cp ${SAVE_MP}/${BKLASTFOLDER}/.badfolders ${DESTDIR}/
  608.    if [ $? -ne 0 ];then
  609.     #fallback, in case last folder badly corrupted...
  610.     BKPREVFOLDER="$(echo "${BKFOLDERS}" | head -n 2 | tail -n 1)"
  611.     [ -f ${SAVE_MP}/${BKPREVFOLDER}/.badfolders ] && cp ${SAVE_MP}/${BKPREVFOLDER}/.badfolders ${DESTDIR}/
  612.    fi
  613.   fi
  614.   echo "$BKBADLIST" >> ${DESTDIR}/.badfolders
  615.   #note, rc.shutdown and savesession-dvd 'touch' this file so it will get saved.
  616.   sync
  617.  else
  618.   [ -f ${SAVE_MP}/${BKLASTFOLDER}/.badfolders ] && cp ${SAVE_MP}/${BKLASTFOLDER}/.badfolders ${DESTDIR}/
  619.  fi
  620.  [ -f ${DESTDIR}/.badfolders ] && BKBADLIST="$(cat ${DESTDIR}/.badfolders | tr "\n" " ")"
  621.  echo "BKBADLIST=${BKBADLIST}" #debug
  622.  BKFOLDERS="$(echo -n "${BKFOLDERS}" | tr "\n" " ")"
  623.  for ONEFOLDER in ${BKFOLDERS}
  624.  do
  625.   if [ "$(echo -n "$BKBADLIST" | grep "${ONEFOLDER}")" != "" -o -L "${SAVE_MP}/${ONEFOLDER}" ];then
  626.    echo "$(printf "${L_FOLDER_MARKED_BAD}" "${ONEFOLDER}")" >/dev/console
  627.    continue #ignore bad folder.
  628.   fi
  629.   echo "$ONEFOLDER" #debug
  630.   echo -n "$(printf "${L_LOADING_FROM_CD}" "${ONEFOLDER}")" >/dev/console
  631.   #need to be careful not to overfill the ramdisk...
  632.   FREERAMDISK=$(df 2>/dev/null | grep /mnt/tmpfs | head -n 1 | tr -s " " | cut -f 4 -d " ")
  633.   SIZEFOLDER=$(du -k -s ${SAVE_MP}/${ONEFOLDER} | cut -f 1)
  634.   SIZEARCHIVE=0
  635.   if [ -d ${SAVE_MP}/${ONEFOLDER}/archive ];then
  636.    SIZEARCHIVE=$(du -k -s ${SAVE_MP}/${ONEFOLDER}/archive | cut -f 1)
  637.   fi
  638.   SIZESOURCE=$(expr $SIZEFOLDER - $SIZEARCHIVE)
  639.   if [ $FREERAMDISK -gt $SIZESOURCE ];then
  640.    #well, -u will only copy if files newer, so less stuff may get copied than calc'd above.
  641.    #need to copy everything except archive folder...
  642.    [ -d ${SAVE_MP}/${ONEFOLDER}/bin ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/bin ${DESTDIR}/
  643.    [ -d ${SAVE_MP}/${ONEFOLDER}/sbin ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/sbin ${DESTDIR}/
  644.    [ -d ${SAVE_MP}/${ONEFOLDER}/etc ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/etc ${DESTDIR}/
  645.    [ -d ${SAVE_MP}/${ONEFOLDER}/lib ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/lib ${DESTDIR}/
  646.    [ -d ${SAVE_MP}/${ONEFOLDER}/opt ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/opt ${DESTDIR}/
  647.    if [ -d ${SAVE_MP}/${ONEFOLDER}/root/.var_saved ];then #100820 see /etc/rc.d/functions4puppy
  648.     mkdir -p ${DESTDIR}/var
  649.     cp -a -u ${SAVE_MP}/${ONEFOLDER}/root/.var_saved/* ${DESTDIR}/var/
  650.    fi
  651.    [ -d ${SAVE_MP}/${ONEFOLDER}/root ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/root ${DESTDIR}/
  652.    [ -d ${SAVE_MP}/${ONEFOLDER}/root/.var_saved ] && rm -rf ${DESTDIR}/root/.var_saved
  653.    [ -d ${SAVE_MP}/${ONEFOLDER}/usr ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/usr ${DESTDIR}/
  654.    [ -f ${DESTDIR}/root/.XLOADED ] && rm -fv ${DESTDIR}/root/.XLOADED #toxic
  655.    cp -a -u ${SAVE_MP}/${ONEFOLDER}/*.sfs ${DESTDIR}/ 2>/dev/null
  656.    #delete deleted files (.wh.filename)... 110212 screen out .wh..wh..opq
  657.    WHITEOUTS="$(find ${DESTDIR} -xdev -type f -name .wh.* | grep -v '__dir_opaque' | grep -v '.wh..wh.')" #110212
  658.    echo "$WHITEOUTS" | while read DELWHITE ; do
  659.     DELFILE="$(echo -n "$DELWHITE" | sed -e 's/\.wh\.//g')"
  660.     if [ -e "$DELFILE" ];then
  661.      [ "$PDEBUG" ] && echo "Deleting $DELFILE" #debug
  662.      rm -rf "$DELFILE"
  663.      rm -rf "$DELWHITE"
  664.     fi
  665.    done
  666.    check_status 0 #display 'done' for each folder loaded.
  667.   else
  668.    printf "${L_RAM_DISK_FULL}\n" "${ONEFOLDER}"
  669.    check_status 1
  670.    break
  671.   fi
  672.  done
  673.  sync
  674.  echo -e "--------------------\n" # debug
  675. }
  676.  
  677. prepend_dir() { #SAVE_LAYER=/pup_ro1
  678.  rm -rf ${SAVE_LAYER}/tmp #in case last boot was pupmode=12
  679.  #adjust stack
  680.  echo "mount -o remount,add:1:${SAVE_LAYER}=ro+wh /pup_new" #debug
  681.  mount -o remount,add:1:${SAVE_LAYER}=ro+wh /pup_new #ro+wh = Readonly branch and it has/might have whiteouts on it
  682.  if [ $? -eq 0 ];then
  683.   [ $PUPMODE -ne 77 ] && KEEPMOUNTED="${KEEPMOUNTED}${SAVEPART} "
  684.   [ "$SAVE_NAME" ] && NEWUNIONRECORD="$SAVE_NAME $NEWUNIONRECORD"
  685.  else
  686.   printf "${L_ADDING_SAVE_LAYER_FAILED}\n" "$SAVE_LAYER"
  687.  fi
  688. }
  689.  
  690. replace_dir() { #SAVE_LAYER=/pup_rw
  691.  #setup empty /tmp on tmpfs for in stack
  692.  rm -rf ${SAVE_LAYER}/tmp
  693.  #adjust stack
  694.  echo "mount -o remount,prepend:${SAVE_LAYER}=rw,mod:/mnt/tmpfs/pup_rw=ro,del:/mnt/tmpfs/pup_rw /pup_new" #debug
  695.  mount -o remount,prepend:${SAVE_LAYER}=rw,mod:/mnt/tmpfs/pup_rw=ro,del:/mnt/tmpfs/pup_rw /pup_new
  696.  if [ $? -eq 0 ];then
  697.   rm -rf /mnt/tmpfs/pup_rw
  698.   KEEPMOUNTED="${KEEPMOUNTED}${SAVEPART} "
  699.   [ "$SAVE_NAME" ] && NEWUNIONRECORD="$SAVE_NAME $NEWUNIONRECORD"
  700.  else
  701.   printf "${L_ADDING_SAVE_LAYER_FAILED}\n" "$SAVE_LAYER"
  702.  fi
  703. }
  704.  
  705. set_fs_linux() {
  706. # "$1" - file system type - ex: ext4
  707.  ONE_FS_IS_LINUX=""
  708.  case ${1} in
  709.   ext2|ext3|ext4|reiserfs|minix|f2fs) ONE_FS_IS_LINUX="yes" ;;
  710.  esac
  711. }
  712.  
  713. find_save_file() {
  714. # "$1" - mount point - ex:  /mnt/pdrv
  715. # "$2" - partition name - ex: sdb2
  716. # "$3" - file system type - ex: ext4
  717.  if [ "$SAVE_BP_DIR" ];then
  718.   SAVE_DIR="$SAVE_BP_DIR"
  719.  else
  720.   SAVE_DIR="${PSUBDIR}/"
  721.  fi
  722.  SAVE_FILES="$(ls -d ${1}${SAVE_DIR}${DISTRO_FILE_PREFIX}save* 2>/dev/null)"
  723.  for ONE_SAVE in $SAVE_FILES;do
  724.   #validate savefiles here
  725.   [ "$ONE_FS_IS_LINUX" != "yes" ] && [ -d "$ONE_SAVE" ] && continue
  726.   IS_OK=""
  727.   case $ONE_SAVE in
  728.    *.2fs|*.3fs|*.4fs) [ -s "$ONE_SAVE" ] && IS_OK="yes" ;;
  729.    *.BKP-*) IS_OK="$PSAVEBKP" ;; #written by /usr/sbin/pupsave-backup
  730.    *) [ -d "$ONE_SAVE" ] && IS_OK="yes" ;;
  731.   esac
  732.   [ "$IS_OK" ] && PUP_SAVES="${PUP_SAVES}${2},${3},${SAVE_DIR}$(basename $ONE_SAVE)
  733. "
  734.  done
  735.  PUP_SAVES="$(echo "$PUP_SAVES")" #remove trailing newline char
  736.  echo "MENU_MAX_PUPSAVES=${MENU_MAX_PUPSAVES}" #debug
  737.  if [ "$MENU_MAX_PUPSAVES" ] ; then
  738.    PUP_SAVES="$(echo "$PUP_SAVES" | head -n $MENU_MAX_PUPSAVES)"
  739.  fi
  740. }
  741.  
  742. search_func() {
  743.  [ "$PDEBUG" -a "$LOOK_SAVE" ] && echo "3: filename=${PSUBDIR}/${DISTRO_FILE_PREFIX}save"
  744.  [ "$PDEBUG" -a "$LOOK_PUP" ] && echo "3: PSUBDIR=$PSUBDIR P_BP_FN=$P_BP_FN P_DEF_FN=$P_DEF_FN"
  745.  echo "HAVE_PARTS='${HAVE_PARTS}'" #debug
  746.  if [ "${1}" ];then
  747.   echo "param='${1}'" #debug
  748.   TRY_PARTS_FIRST="$(echo "$HAVE_PARTS" | grep -E "${1}")"
  749.   TRY_PARTS_LAST="$(echo "$HAVE_PARTS" | grep -Ev "${1}")"
  750.   TRY_PARTS="$TRY_PARTS_FIRST
  751. $TRY_PARTS_LAST"
  752.  else
  753.   TRY_PARTS="$HAVE_PARTS"
  754.  fi
  755.  echo "TRY_PARTS='${TRY_PARTS}'" #debug
  756.  [ "$TRY_PARTS" ] || return
  757.  for ONETRY in $TRY_PARTS;do
  758.   ONE_PART="$(echo -n "$ONETRY" | cut -f 1 -d '|')"
  759.   [ "$PDEBUG" ] && echo "4: ONE_PART=$ONE_PART"
  760.   ensure_mounted "$ONE_PART" "/mnt/pdrv"
  761.   if [ "$ONE_MP" ];then
  762.    if [ "$LOOK_SAVE" -a "$SAVEPART" = "" ];then
  763.     set_fs_linux "$ONE_FS"
  764.     find_save_file "$ONE_MP" "$ONE_PART" "$ONE_FS"
  765.     if [ "$PUP_SAVES" ];then
  766.      SAVEPART="$ONE_PART"
  767.      [ "$PDEBUG" ] && echo "5: ONE_PART=$ONE_PART filename=${PSUBDIR}/${DISTRO_FILE_PREFIX}save"
  768.     fi
  769.    fi
  770.    if [ "$LOOK_PUP" ];then
  771.     find_drv_file "$P_BP_FN" "$P_DEF_FN"
  772.     if [ "$ONE_FN" ];then
  773.      PDRV="$ONE_PART,$ONE_FS,$ONE_FN"
  774.      P_MP="$ONE_MP"
  775.      P_PART="$ONE_PART"
  776.      [ "$PDEBUG" ] && echo "5: ONE_PART=$ONE_PART PSUBDIR=$PSUBDIR P_BP_FN=$P_BP_FN P_DEF_FN=$P_DEF_FN"
  777.      break;
  778.     fi
  779.    fi
  780.    umount $ONE_MP
  781.   fi
  782.  done
  783. }
  784.  
  785. get_part_info() {
  786.  probedisk > /tmp/ALLDRVS
  787.  ls -1 /sys/block | grep -E '^scd|^sd|^mmc|^sr' > /tmp/ALLDRVS0
  788.  PCPARTSALL="$(/sbin/probepart_init -k)"
  789.  HAVE_PARTS="$(echo "$PCPARTSALL" | grep '^/dev/' | cut -f 1-2 -d '|'  | grep -E 'f2fs|udf|iso9660|ext2|ext3|ext4|reiserfs|msdos|vfat|minix|ntfs' | sed -e 's%/dev/%%')"
  790.  [ "$PDEBUG" ] && echo "$HAVE_PARTS" > /tmp/HAVE_PARTS
  791. }
  792.  
  793. wait_for_usb() {
  794.  [ -e /tmp/flag-usb-ready ] && return
  795.  echo -n "${L_WAITING_FOR_USB}" > /dev/console
  796.  /sbin/wait4usb
  797.  get_part_info
  798.  BLKIDOUT=""
  799.  check_status 0
  800. }
  801.  
  802. umount_unneeded() {
  803.  MTD_PARTS="$(mount | cut -f1 -d' ' | grep '^/dev' | grep -v loop | cut -f3 -d'/')"
  804.  for ONE_PART in $MTD_PARTS;do
  805.   [ "$(echo -n "$KEEPMOUNTED" | grep "$ONE_PART")" ] || umount /dev/$ONE_PART
  806.  done
  807. }
  808.  
  809. fatal_error() {
  810. # "$1" - message - ex: puppy_tahr_6.0.5.sfs not found
  811. # "$2" - pre-status-message - ex: Finding puppy
  812.  KEEPMOUNTED=""
  813.  umount_unneeded
  814.  [ "${2}" ] && echo -n "${2}" > /dev/console
  815.  check_status -critical 1 "$1"
  816. }
  817.  
  818. #=============================================================
  819. #                           MAIN
  820. #=============================================================
  821.  
  822. clear #clear the screen.
  823.  
  824. echo -en "\\033[0;34m***\\033[0;37m ${DISTRO_NAME} ${DISTRO_VERSION}"
  825. echo -en "\\033[0;34m -\\033[0;37m Linux ${KERNELVER} "
  826. echo -en "\\033[0;31m[\\033[0;37m`uname -m`\\033[0;31m]"
  827. echo -e "\\033[0;34m ***\\033[0;39m"
  828.  
  829. [ ! "$LOGLEVEL" ] && exec 1>/tmp/bootinit.log 2>&1 #remove o/p from console. v2.22 loglevel added.
  830.  
  831. [ ! -f /bin/resize2fs ] && touch /tmp/no_resize2fs
  832.  
  833. # sets PLANG, PKEYS, VFAT_OUT_PARAM, FONTMAP, KMAP, CODEPAGE
  834. [ -f /sbin/set_plang ] && . /sbin/set_plang
  835.  
  836. #pmedia= usbflash|usbhd|usbcd|ataflash|atahd|atacd|atazip|scsihd|scsicd|cd
  837. [ $pmedia ] && PMEDIA=$pmedia #boot parameter, broad category of boot media. ex: cd.
  838. [ $psubdir ] && PSUBDIR=$psubdir #boot parameter, directory for puppy files. ex: puppy220
  839. [ $psavemark ] && PSAVEMARK=$psavemark #100913 partition number that has/will-have save-file.
  840.  
  841. [ $PSUBDIR ] && [ "${PSUBDIR:0:1}" != "/" ] && PSUBDIR="/${PSUBDIR}" #add leading /.
  842.  
  843. [ $pdev1 ] && PDRV=$pdev1 #boot parameter, partition have booted off. ex: hda3
  844. #100915 requested by technosaurus (formats get changed further down)...
  845. [ $pdrv ] && PDRV=$pdrv #format partition:<path><filename> ex: sda2:/slacko/puppy_slacko_6.3.0.sfs
  846. [ $pupsfs ] && PDRV=$pupsfs
  847. [ $zdrv ] && ZDRV=$zdrv #ex: sda2:/slacko/zdrv_slacko_6.3.0.sfs
  848. [ $fdrv ] && FDRV=$fdrv
  849. [ $adrv ] && ADRV=$adrv
  850. [ $ydrv ] && YDRV=$ydrv
  851. #<partition>:<filename>, for savefile/savefolder. <partition> can be a name or Label or UUID
  852. [ $psave ] && PSAVE=$psave #ex: sdb4:/puppy/tahr/tahrsave or smark or 49baa82d-8c69:tahrsave
  853. #list of kernel modules to load, ex: pimod=hid-logitech-dj.ko,kernel/drivers/hid/hid-multitouch.ko
  854. [ $pimod ] && PIMOD=$pimod
  855. #specify partition for Underdog Linux (refer also underdog.lnx).
  856. [ $underdog ] && UNDERDOG=$underdog
  857. #[ $pdebug ] && PDEBUG=$pdebug
  858. PDEBUG=1
  859. TOTAL_SIZEK_SFS_RAM=0
  860.  
  861. # show menu with pupsaves
  862. [ $psavemenu ] && PSAVEMENU=$psavemenu
  863.  
  864. RDSH=""
  865. if [ "$pfix" ];then
  866.  for ONEFIX in $(echo -n "$pfix" | tr ',' ' ')
  867.  do
  868.   case $ONEFIX in
  869.    ram)     PRAMONLY="yes";;      #run in ram only (do not load ${DISTRO_FILE_PREFIX}save).
  870.    rdsh)    RDSH="yes";;          #exit to shell in initial ramdisk.
  871.    nox)     PNOX="yes";;          #do not start X.
  872.    clean)   PCLEAN="yes";;        #force version upgrade and cleanup.
  873.    trim)    PTRIM="yes";;         #add "discard" to mount options if SSD
  874.    copy)    PCOPY="yes";;         #copy .sfs files into ram.
  875.    nocopy)  PNOCOPY="yes";;        #do not copy .sfs files into ram (default is copy if enough ram).
  876.    fsck)    PFSCK="yes";;         #do a fsck of ${DISTRO_FILE_PREFIX}save file.
  877.    fsckp)   PFSCKP="yes";;        #do fsck before first mount of ext partitions
  878.    [0-9]*)  PIGNORELAST=$ONEFIX;; #blacklist last $ONEFIX folders (multisession).
  879.    psavebkp)PSAVEBKP='yes';;      #don't ignore pupsaves created by Pupsave Backup
  880.    *)       echo "pfix=$ONEFIX is not a known boot parameter";;
  881.   esac
  882.  done
  883. fi
  884.  
  885. [ "$PRAMONLY" != "yes" ] && [ -f /BOOT_SPECS ] && . /BOOT_SPECS
  886.  
  887. if [ "$PSAVEMENU" ] ; then
  888.  #MENU_MAX_PUPSAVES=number
  889.  MENU_MAX_PUPSAVES=$(echo "$PSAVEMENU" | grep -o '[0-9]' | tr '\n' ' ' | sed 's| ||g')
  890. fi
  891.  
  892. [ "$TZ" ] && export TZ
  893. hwclock -l -s
  894.  
  895. [ "$PDEBUG" ] && echo "0: PMEDIA=$PMEDIA PDRV=$PDRV PSUBDIR=$PSUBDIR pfix=$pfix"
  896.  
  897. #100915 technosaurus recommendation (see above)...
  898. [ "$PDRV" ] && { decode_spec "$PDRV"; P_BP_ID="$ONE_BP_ID"; P_BP_FN="$ONE_BP_FN"; PDRV=""; }
  899. [ "$ZDRV" ] && { decode_spec "$ZDRV"; Z_BP_ID="$ONE_BP_ID"; Z_BP_FN="$ONE_BP_FN"; ZDRV=""; }
  900. [ "$FDRV" ] && { decode_spec "$FDRV"; F_BP_ID="$ONE_BP_ID"; F_BP_FN="$ONE_BP_FN"; FDRV=""; }   
  901. [ "$ADRV" ] && { decode_spec "$ADRV"; A_BP_ID="$ONE_BP_ID"; A_BP_FN="$ONE_BP_FN"; ADRV=""; }
  902. [ "$YDRV" ] && { decode_spec "$YDRV"; Y_BP_ID="$ONE_BP_ID"; Y_BP_FN="$ONE_BP_FN"; YDRV=""; }
  903. [ "$PSAVE" ] && { decode_spec "$PSAVE"; SAVE_BP_ID="$ONE_BP_ID"; SAVE_BP_FN="$ONE_BP_FN"; }
  904. SAVE_BP_DIR=""
  905. [ "$SAVE_BP_FN" ] && [ "${SAVE_BP_FN:$((${#SAVE_BP_FN} - 1))}" = "/" ] && SAVE_BP_DIR="$SAVE_BP_FN" #last char
  906.  
  907. #first look inside initrd...
  908. #unset x_DEF_FN so that find_onepupdrv() won't look for it
  909. [ -f /${P_DEF_FN} ] && { PDRV="rootfs,rootfs,/$P_DEF_FN"; P_DEF_FN=""; }
  910. [ -f /${Z_DEF_FN} ] && { ZDRV="rootfs,rootfs,/$Z_DEF_FN"; Z_DEF_FN=""; }
  911. [ -f /${F_DEF_FN} ] && { FDRV="rootfs,rootfs,/$F_DEF_FN"; F_DEF_FN=""; }
  912. [ -f /${A_DEF_FN} ] && { ADRV="rootfs,rootfs,/$A_DEF_FN"; A_DEF_FN=""; }
  913. [ -f /${Y_DEF_FN} ] && { YDRV="rootfs,rootfs,/$Y_DEF_FN"; Y_DEF_FN=""; }
  914.  
  915. get_part_info
  916. grep -v '^sr' /tmp/ALLDRVS0 > /tmp/ATADRIVES0
  917. ATAOPTICALDRIVES="$(grep '^sr' /tmp/ALLDRVS0 | tr '\n' ' ')"
  918.  
  919. PUP_SAVES=""
  920. KEEPMOUNTED=""
  921. FSCKDPARTS=""
  922. BLKIDOUT=""
  923. LO_OPT="-r"
  924.  
  925. [ "$PDEBUG" ] && echo "1: PDRV=$PDRV P_BP_ID=$P_BP_ID P_BP_FN=$P_BP_FN"
  926.  
  927. #establish PDRV
  928. P_PART=""; LOOK_PUP=""; LOOK_SAVE=""
  929. if [ "$P_BP_ID" ];then #specified as parameter
  930.  decode_id "$P_BP_ID"
  931.  [ "$ONE_PART" ] && { P_PART="$ONE_PART"; P_BP_ID=""; }
  932.  if [ "$P_PART"  = "" ];then
  933.   wait_for_usb
  934.   decode_id "$P_BP_ID"
  935.   [ "$ONE_PART" ] && { P_PART="$ONE_PART"; P_BP_ID=""; }
  936.  fi
  937.  find_onepupdrv "$P_PART" "$P_BP_FN" "$P_DEF_FN" "p"
  938.  [ "$ONE_FN" ] && { PDRV="$ONE_PART,$ONE_FS,$ONE_FN"; P_MP="$ONE_MP"; }
  939.  [ "$PDEBUG" ] && echo "2: ONE_PART=$ONE_PART ONE_FN=$ONE_FN ONE_MP=$ONE_MP"
  940. elif [ "$PDRV" = "" ];then #not specified anywhere
  941.  #determine what to search for
  942.  [ "$PMEDIA" = "cd" ] && LOOK_SAVE="yes"
  943.  [ "$SAVE_BP_ID" -o "$PSAVEMARK" ] && LOOK_SAVE=""
  944.  LOOK_PUP=yes
  945.  [ "$PDEBUG" ] && echo "2: LOOK_PUP=$LOOK_PUP LOOK_SAVE=$LOOK_SAVE PMEDIA=$PMEDIA"
  946. fi
  947. if [ "$LOOK_PUP" -o "$LOOK_SAVE" ];then #something to search for
  948.  [ "${PMEDIA:0:3}" != "usb" ] && search_func
  949.  if [ "$P_PART" = "" ];then
  950.   wait_for_usb
  951.   USBDRVS="$(find /sys/block -maxdepth 1 -name 'sd*' -o -name 'sr*' | xargs -n 1 readlink 2>/dev/null | grep '/usb[0-9]' | rev | cut -f 1 -d '/' | rev | tr '\n' '|')"
  952.   [ "$PDEBUG" ] && echo "2: USBDRVS=$USBDRVS -> ${USBDRVS%|}"
  953.   if [ "$USBDRVS" ] ; then
  954.     search_func "${USBDRVS%|}"
  955.   else
  956.     search_func
  957.   fi
  958.  fi
  959. fi
  960. [ "$P_BP_ID" ] && { log_part_id "$P_BP_ID"; ONE_PART="$P_BP_ID"; }
  961. [ "$PDEBUG" ] && echo "6: ONE_PART=$ONE_PART ONE_TRY_FN=$ONE_TRY_FN PDRV=$PDRV"
  962. if [ "$PDRV" = "" ];then
  963.  [ "$ONE_TRY_FN" ] || ONE_TRY_FN="$PSUBDIR/$P_DEF_FN"
  964.  fatal_error "$ONE_PART $ONE_TRY_FN not found." "Finding puppy main sfs file."
  965. fi
  966.  
  967. #establish SAVEPART
  968. decode_other_ids
  969. if [ "$Z_BP_ID" -o "$F_BP_ID" -o "$A_BP_ID" -o "$Y_BP_ID" -o "$SAVE_BP_ID" ];then
  970.  wait_for_usb
  971.  decode_other_ids
  972. fi
  973. if [ "$P_PART" ];then
  974.  BOOTDRV="$(echo -n "$P_PART" | grep -o -f /tmp/ALLDRVS0)" #110205 ex: sda1 becomes sda.
  975.  if [ "$SAVEPART" = "" ];then #setup SAVEPART
  976.   [ "$P_MP" ] || P_MP="$(mount | grep -m1 "/dev/$P_PART " | cut -f 3 -d ' ')"
  977.   [ -f ${P_MP}${PSUBDIR}/SAVEMARK ] && PSAVEMARK="$(cat ${P_MP}${PSUBDIR}/SAVEMARK)" #partition no. that has or will-have ${DISTRO_FILE_PREFIX}save.2fs. 101020
  978.   [ "$PSAVEMARK" ] && SAVEPART="${BOOTDRV}${PSAVEMARK}" #note, PSAVEMARK could also be a kernel boot param. ex: sda2
  979.   [ "$SAVEPART" ] || SAVEPART="$P_PART"
  980.  fi
  981. fi
  982. #ensure SAVEPART will be mounted on /mnt/dev_save
  983. #if SAVEPART is the same as P_PART
  984. SAVE_MP="/mnt/dev_save"
  985. if [ "$SAVEPART" -a "$SAVEPART" = "$P_PART" ];then
  986.  #this mount move needs to be done before loading any sfs's
  987.  [ -d "${SAVE_MP}" ] || mkdir -p ${SAVE_MP}
  988.  [ "$P_MP" ] && { mount -o move $P_MP ${SAVE_MP}; P_MP="${SAVE_MP}"; }
  989. fi
  990.  
  991. #have pup...sfs, now try to load it
  992. RAMSIZE=$(free | grep -o 'Mem: .*' | tr -s ' ' | cut -f 2 -d ' ') #total physical ram (less shared video). 110405
  993.  
  994. mount -t tmpfs tmpfs /mnt/tmpfs
  995. [ -d "/mnt/tmpfs/pup_rw" ] || mkdir /mnt/tmpfs/pup_rw
  996. mount -t aufs -o udba=reval,diropq=w,br=/mnt/tmpfs/pup_rw=rw,xino=/mnt/tmpfs/.aufs.xino unionfs /pup_new
  997. [ $? -eq 0 ] || fatal_error "${L_ERROR_FAILED_AUFS_STACK}"
  998.  
  999. NEWUNIONRECORD=""
  1000. COPY2RAM=""
  1001.  
  1002. COPYMSG="${L_COPY_MESSAGE}" #purple
  1003. LOADMSG="${L_LOAD_MESSAGE}"
  1004. setup_onepupdrv "$PDRV" "p"
  1005. STATUS=$?
  1006. if [ $STATUS -gt 0 ];then
  1007.  P_PRE_MSG="${L_PRE_MESSAGE}"
  1008.  case $STATUS in
  1009.   1) fatal_error "$(printf "${L_ERR_PDRV_INCOMPLETE}" "$PDRV")" "$P_PRE_MSG" ;;
  1010.   2) fatal_error "$(printf "${L_ERR_ONEPART_NOT_MOUNTED}" "$ONE_PART")" "$P_PRE_MSG" ;;
  1011.   3) fatal_error "$(printf "${L_ERR_ONEPART_NOT_OK}" "$ONE_PART" "$ONE_REL_FN")" "$P_PRE_MSG" ;;
  1012.   4) fatal_error "$(printf "${L_ERR_ONEPART_MOUNT_SFS_FAILED}" "$ONE_PART" "$ONE_REL_FN")" "$P_PRE_MSG" ;;
  1013.   5) fatal_error "$(printf "${L_ERR_AUFS_SFS_FAILED}" "$ONE_LAYER")" "$P_PRE_MSG" ;;
  1014.  esac
  1015. fi
  1016. PUP_LAYER="$SFS_MP"
  1017.  
  1018. #all partition id's should be decoded by now
  1019. [ "$Z_BP_ID" ] && log_part_id "$Z_BP_ID"
  1020. [ "$F_BP_ID" ] && log_part_id "$F_BP_ID"
  1021. [ "$A_BP_ID" ] && log_part_id "$A_BP_ID"
  1022. [ "$Y_BP_ID" ] && log_part_id "$Y_BP_ID"
  1023. [ "$SAVE_BP_ID" ] && log_part_id "$SAVE_BP_ID"
  1024.  
  1025. #have basic system, now try to add optional stuff
  1026. find_onepupdrv "$F_PART" "$F_BP_FN" "$F_DEF_FN" "f"
  1027. [ "$ONE_FN" ] && FDRV="$ONE_PART,$ONE_FS,$ONE_FN"
  1028. [ "$FDRV" ] && { LOADMSG="fdrv"; setup_onepupdrv "$FDRV" "f"; }
  1029.  
  1030. find_onepupdrv "$Z_PART" "$Z_BP_FN" "$Z_DEF_FN" "z"
  1031. [ "$ONE_FN" ] && ZDRV="$ONE_PART,$ONE_FS,$ONE_FN"
  1032. [ "$ZDRV" ] && { LOADMSG="zdrv"; setup_onepupdrv "$ZDRV" "z"; }
  1033.  
  1034. find_onepupdrv "$Y_PART" "$Y_BP_FN" "$Y_DEF_FN" "y"
  1035. [ "$ONE_FN" ] && YDRV="$ONE_PART,$ONE_FS,$ONE_FN"
  1036. [ "$YDRV" ] && { LOADMSG="ydrv"; setup_onepupdrv "$YDRV" "y" "p"; }
  1037.  
  1038. find_onepupdrv "$A_PART" "$A_BP_FN" "$A_DEF_FN" "a"
  1039. [ "$ONE_FN" ] && ADRV="$ONE_PART,$ONE_FS,$ONE_FN"
  1040. [ "$ADRV" ] && { LOADMSG="adrv"; setup_onepupdrv "$ADRV" "a" "p"; }
  1041.  
  1042. #ensure that save partition is mounted
  1043. #if SAVEPART is not the same as P_PART
  1044. #moved up here to ensure config files are available
  1045. [ "$SAVEPART" ] && ensure_save_mounted
  1046.  
  1047. #bring back Underdog Linux...
  1048. if [ ! "$UNDERDOG" ] ; then
  1049.   [ -s "${SAVE_MP}${PSUBDIR}/underdog.lnx" ] && UNDERDOG="`cat ${SAVE_MP}${PSUBDIR}/underdog.lnx`"
  1050. fi
  1051. [ "$UNDERDOG" ] && { decode_id "$UNDERDOG"; UNDERDOG="$ONE_PART"; }
  1052. if [ "$UNDERDOG" ];then #boot parameter
  1053.  ensure_mounted "$UNDERDOG" "/pup_ud"
  1054.  if [ "$ONE_MP" ];then
  1055.   mount -o remount,append:${ONE_MP}=rr /pup_new
  1056.   #if [ $? -eq 0 ];then
  1057.    #do any necessary underdog fiddles
  1058.   #fi
  1059.  fi
  1060. fi
  1061.  
  1062. #support initmodules.txt
  1063. if [ "$PIMOD" = "" ]; then
  1064.   [ -s "${SAVE_MP}${PSUBDIR}/initmodules.txt" ] && PIMOD="$(cat ${SAVE_MP}${PSUBDIR}/initmodules.txt)"
  1065. fi
  1066. #insmod modules needed by keyboard
  1067. if [ "$PIMOD" != "" ];then
  1068.  [ -d /lib/modules ] && mv -f /lib/modules /lib/modules.bak
  1069.  ln -sv /pup_new/lib/modules /lib/modules
  1070.  [ -d /lib/firmware ] && mv -f /lib/firmware /lib/firmware.bak
  1071.  ln -sv /pup_new/lib/firmware /lib/firmware
  1072.  MODSPATH="/lib/modules/$KERNELVER"
  1073.  for ONEMOD in `echo -n "$PIMOD" | tr ',' ' '`;do
  1074.   CURMOD=""
  1075.   if [ -f "${MODSPATH}/${ONEMOD}" ];then
  1076.    CURMOD="$ONEMOD"
  1077.   else
  1078.    CURMOD="`grep -m1 $ONEMOD /pup_new/etc/modules/modules.order-${KERNELVER}`"
  1079.    if [ "$CURMOD" = "" ];then
  1080.     MODPATN="`echo -n "$ONEMOD" | tr '_' '-'`"
  1081.     CURMOD="`grep -m1 "$MODPATN" /pup_new/etc/modules/modules.order-${KERNELVER}`"
  1082.    fi
  1083.    [ -f "${MODSPATH}/${CURMOD}" ] || CURMOD=""
  1084.   fi
  1085.   if [ "$CURMOD" != "" ];then
  1086.    echo -n "$(printf "${L_ADDING_MODULE}" "$CURMOD")" > /dev/console
  1087.    insmod "${MODSPATH}/${CURMOD}" > /dev/console 2>&1
  1088.    check_status $?
  1089.   fi
  1090.  done
  1091.  rm -f /lib/modules
  1092.  [ -d /lib/modules.bak ] && mv /lib/modules.bak /lib/modules
  1093.  rm -f /lib/firmware
  1094.  [ -d /lib/firmware.bak ] && mv /lib/firmware.bak /lib/firmware
  1095. fi
  1096.  
  1097. #find PUPSAVE, sortout pupmode
  1098. PUPMODE=5
  1099.  
  1100. #debug
  1101. echo --------------------
  1102. echo "SAVE_MP=${SAVE_MP}"
  1103. echo "PRAMONLY=${PRAMONLY}"
  1104. echo "BOOTDRV=${BOOTDRV}"
  1105. mount
  1106. echo --------------------
  1107.  
  1108. PUPSAVE=""
  1109. if [ "${SAVE_MP}" != "" -a "$PRAMONLY" != "yes" ];then #have mounted save? partition
  1110.  #check if save partition is linux
  1111.  set_fs_linux "$SAVE_FS"
  1112.  #check for cd multisession
  1113.  if [ "$SAVE_FS" = "iso9660" ];then #booting on optical, is it multisession?...
  1114.   BKFOLDERS="$(find $SAVE_MP -maxdepth 1 -xdev -type d -name '20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]' | sed -e s%^${SAVE_MP}/%% | sort -r)"
  1115.   if [ "$BKFOLDERS" ];then #multisession cd/dvd
  1116.    FND_MULTIFOLDER="/$(echo "$BKFOLDERS" | head -n 1)"
  1117.    if [ "$FND_MULTIFOLDER" ];then #multisession cd/dvd
  1118.     PUPMODE=77
  1119.     PUPSAVE="${SAVEPART},${SAVE_FS},${FND_MULTIFOLDER}"
  1120.    fi
  1121.   fi
  1122.  fi
  1123.  echo "FND_MULTIFOLDER=${FND_MULTIFOLDER}" #debug
  1124.  #check for save to partition
  1125.  if [ "$ONE_FS_IS_LINUX" = "yes" -a "$PSUBDIR" = "" -a -f "${SAVE_MP}/etc/rc.d/PUPSTATE" ];then
  1126.   PUPMODE=6
  1127.   PUPSAVE="${SAVEPART},${SAVE_FS},/"
  1128.  fi
  1129.  #not sorted yet, may be pupmode=12
  1130.  if [ $PUPMODE -eq 5 ];then
  1131.   #check boot spec
  1132.   if [ "$SAVE_BP_FN" -a "$SAVE_BP_DIR" = "" ];then
  1133.    if [ -d "${SAVE_MP}${SAVE_BP_FN}" ];then
  1134.     [ "$ONE_FS_IS_LINUX" = "yes" ] && PUPSAVE="$SAVEPART,$SAVE_FS,$SAVE_BP_FN"
  1135.    else
  1136.     [ -s "${SAVE_MP}${SAVE_BP_FN}" ] && PUPSAVE="$SAVEPART,$SAVE_FS,$SAVE_BP_FN"
  1137.    fi
  1138.    [ "$PUPSAVE" ] || echo "$SAVEPART, $SAVE_BP_FN file not found."
  1139.   else
  1140.    #have to find savefile/savefolder
  1141.    [ "$PUP_SAVES" ] || find_save_file "${SAVE_MP}" "$SAVEPART" "$SAVE_FS"
  1142.    echo "PUP_SAVES=${PUP_SAVES}" #debug
  1143.    if [ "$PUP_SAVES" ];then
  1144.     NUMPUP_SAVES=0
  1145.     for ONE_SAVE in $PUP_SAVES;do
  1146.      NUMPUP_SAVES=$(expr $NUMPUP_SAVES + 1)
  1147.     done
  1148.     echo "NUMPUP_SAVES=${NUMPUP_SAVES}" #debug
  1149.     if [ $NUMPUP_SAVES -eq 1 ];then
  1150.      PUPSAVE="$(echo -n $PUP_SAVES)"
  1151.     elif [ $NUMPUP_SAVES -gt 1 ];then
  1152.      CNTSAVE=1
  1153.      echo -e "\\033[1;36m" >/dev/console #36=aquablue
  1154.      echo "${L_ERR_TYPE_PUPSAVE}" > /dev/console
  1155.      echo "${L_0_NONE}" > /dev/console
  1156.      for ONETRY in $PUP_SAVES
  1157.      do
  1158.       ONE_PART="$(echo -n "$ONETRY" | cut -f 1 -d ',')"
  1159.       ONE_FILE="$(echo -n "$ONETRY" | cut -f 3 -d ',')"
  1160.       echo -e "${CNTSAVE}  ${ONE_PART}\\033[10G${ONE_FILE}" > /dev/console #10 means move to that column.
  1161.       CNTSAVE=$(expr $CNTSAVE + 1)
  1162.      done
  1163.      echo -en "\\033[0;39m" >/dev/console
  1164.      read NUMSAVE
  1165.      #--  $NUMSAVE -ne 0 = have selected a PUPSAVE ...
  1166.      if [ $NUMSAVE -ne 0 ] ; then
  1167.       echo -e "\n----" #debug
  1168.       echo "Have selected pupsave $NUMSAVE" #debug
  1169.       PUPSAVE="$(echo -n $PUP_SAVES | cut -f $NUMSAVE -d ' ')"
  1170.       PSPATH="${SAVE_MP}/$(echo "$PUPSAVE" | cut -f 3 -d ',')"
  1171.       echo "PSPATH=${PSPATH}" #debug
  1172.       case "$PSPATH" in *.tar.[gx]z) #compressed archive
  1173.        PSPATH_NOTGZ=${PSPATH%.tar.[gx]z} #remove trailing 'tar.[gx]z'
  1174.        echo "PSPATH_NOTGZ=${PSPATH_NOTGZ}" #debug
  1175.        case "$PSPATH" in
  1176.          *".2fs"*|*".3fs"*|*".4fs"*) savefile="yes" ;;
  1177.          *) savefolder="yes" ;;
  1178.        esac
  1179.        case "$PSPATH" in
  1180.          *.tar.gz) TAROPT="-z" ;;
  1181.          *.tar.xz) TAROPT="-J" ;;
  1182.        esac
  1183.        echo "savefile=${savefile}"     #debug
  1184.        echo "savefolder=${savefolder}" #debug
  1185.        cdir=$(pwd)
  1186.        #--
  1187.        if [ "$savefolder" = "yes" ] ; then
  1188.          mkdir -p "$PSPATH_NOTGZ"
  1189.          cd "$PSPATH_NOTGZ"
  1190.          echo "Extracting ${PSPATH##*/}..." >/dev/console #basename
  1191.          tar -x $TAROPT -f "$PSPATH" && TAROK=yes
  1192.          itsinside=$(ls -d ${DISTRO_FILE_PREFIX}save* | head -n 1)
  1193.          if [ "$itsinside" ] ; then
  1194.            cd "$cdir"
  1195.            mv -fv "$PSPATH_NOTGZ" "$PSPATH_NOTGZ".2
  1196.            sync
  1197.            mv -fv "$PSPATH_NOTGZ".2/${itsinside} "$PSPATH_NOTGZ"
  1198.            sync
  1199.            rm -rfv "$PSPATH_NOTGZ".2
  1200.          fi
  1201.        else #savefile
  1202.          cd "${PSPATH%/*}" #dirname $PSPATH
  1203.          echo "Extracting ${PSPATH##*/}..." >/dev/console #basename $PSPATH
  1204.          tar -x $TAROPT -f "$PSPATH" && TAROK=yes
  1205.        fi
  1206.        sync
  1207.        #--
  1208.        echo "TAROK=${TAROK}" #debug
  1209.        if [ "$TAROK" = "yes" ] ; then
  1210.          PUPSAVE=${PUPSAVE%.tar.[gx]z} #remove trailing 'tar.[gx]z'
  1211.          rm -fv "$PSPATH"
  1212.        else
  1213.          PUPSAVE=""
  1214.          echo "Error extracting ${PSPATH##*/}"
  1215.          echo -e "\\033[1;31mError extracting ${PSPATH##*/}\\033[0;39m" >/dev/console #31=red
  1216.          [ "$savefolder" = "yes" ] && rm -rf "$PSPATH_NOTGZ"
  1217.          [ "$savefile" = "yes" ] && rm -fv "$PSPATH_NOTGZ"
  1218.        fi
  1219.        cd $cdir
  1220.        echo -e "----\n" #debug
  1221.        ;;
  1222.       esac
  1223.      fi
  1224.      #----------------------------------------------------
  1225.     fi
  1226.    fi
  1227.   fi
  1228.   echo "PUPSAVE=${PUPSAVE}" #debug
  1229.   if [ "$PUPSAVE" ];then
  1230.    echo "Setting PUPMODE 12" #debug
  1231.    PUPMODE=12
  1232.    ONE_PART="$(echo -n "$PUPSAVE" | cut -f 1 -d ',')"
  1233.    [ "$ONE_PART" != "$SAVEPART" ] && { SAVEPART="$ONE_PART"; ensure_save_mounted; }
  1234.   fi
  1235.  fi
  1236. fi
  1237.  
  1238. SAVE_LAYER=""
  1239. if [ "$PUPSAVE" ];then #refine pupmode
  1240.  if [ $PUPMODE -eq 6 -o $PUPMODE -eq 12 ];then
  1241.   SAVE_LAYER="/pup_rw"
  1242.   echo "SAVE_LAYER=/pup_rw" #debug
  1243.   if [ "${PMEDIA:3}" = "flash" ];then
  1244.    PUPMODE=$(expr $PUPMODE + 1) #PUPMODE=7 PUPMODE=13
  1245.    echo "Flash drive: setting PUPMODE $PUPMODE, SAVE_LAYER=/pup_ro1"  #debug
  1246.    SAVE_LAYER="/pup_ro1"
  1247.   fi
  1248.  elif [ $PUPMODE -eq 77 ];then
  1249.   SAVE_LAYER="/pup_ro1"
  1250.  fi
  1251. fi
  1252.  
  1253. #load savefile if required, then setup stack
  1254. case $PUPMODE in
  1255.  77) #load folders
  1256.   copy_folders #to /pup_ro1
  1257.   prepend_dir  #prepend ro1
  1258.  ;;
  1259.  13) #prepend ro1
  1260.   setup_save_file
  1261.   [ "$PUPSAVE" ] && prepend_dir
  1262.  ;;
  1263.  12) #replace rw
  1264.   setup_save_file
  1265.   [ "$PUPSAVE" ] && replace_dir
  1266.  ;;
  1267.  7) #prepend ro1
  1268.   setup_save_part
  1269.   prepend_dir
  1270.  ;;
  1271.  6) #replace rw
  1272.   setup_save_part
  1273.   replace_dir
  1274.  ;;
  1275.  5)
  1276.   SAVE_MP=""
  1277.  ;;
  1278. esac
  1279.  
  1280. umount_unneeded
  1281.  
  1282. echo -n $TOTAL_SIZEK_SFS_RAM > /tmp/sfs_ram_sizek
  1283.  
  1284. [ "$DEV1FS" ] || DEV1FS="$(echo "$PDRV" | cut -f 2 -d ',')"
  1285. [ "$ATADRIVES" ] || ATADRIVES="$(cat /tmp/ATADRIVES0 | tr '\n' ' ')"
  1286.  
  1287. mkdir -p /pup_new/etc/rc.d
  1288. ( # > /pup_new/etc/rc.d/PUPSTATE
  1289. echo "PUPMODE=$PUPMODE"
  1290. echo "PDEV1='$P_PART'"
  1291. echo "DEV1FS='$DEV1FS'"
  1292. echo "PUPSFS='$PDRV'"
  1293. echo "PUPSAVE='$PUPSAVE'"
  1294. echo "PMEDIA='$PMEDIA'"
  1295. echo '#ATADRIVES is all internal ide/pata/sata drives, excluding optical, excluding usb...'
  1296. echo "ATADRIVES='$ATADRIVES'"
  1297. echo '#ATAOPTICALDRIVES is list of non-usb optical drives...'
  1298. echo "ATAOPTICALDRIVES='$ATAOPTICALDRIVES'"
  1299. echo '#these directories are unionfs/aufs layers in /initrd...'
  1300. echo "SAVE_LAYER='$SAVE_LAYER'"
  1301. echo "PUP_LAYER='$PUP_LAYER'"
  1302. echo "#The partition that has the ${DISTRO_FILE_PREFIX}save file is mounted here..."
  1303. echo "PUP_HOME='${SAVE_MP}'"
  1304. echo '#(in /initrd) ...note, /mnt/home is a link to it.'
  1305. echo '#this file has extra kernel drivers and firmware...'
  1306. echo "ZDRV='$ZDRV'"
  1307. echo "FDRV='$FDRV'"
  1308. echo "ADRV='$ADRV'"
  1309. echo "YDRV='$YDRV'"
  1310. echo '#Partition no. override on boot drive to which session is (or will be) saved...'
  1311. echo "PSAVEMARK='$PSAVEMARK'"
  1312. echo "PSAVEPART='$PSAVEPART'"
  1313. echo "PSAVEDIR='$SAVE_BP_DIR'"
  1314. echo "PSUBDIR='$PSUBDIR'"
  1315. [ -f /sbin/set_plang ] && plang_pupstate #echo
  1316. [ "$UNDERDOG" ] && echo "UNDERDOG='$UNDERDOG'"
  1317. ) > /pup_new/etc/rc.d/PUPSTATE
  1318.  
  1319. if [ "$PUPSAVE" ];then
  1320.  xBOOTCONFIG="$(grep -v '^PREVUNIONRECORD' /pup_new/etc/rc.d/BOOTCONFIG | sed -e 's/^LASTUNIONRECORD/PREVUNIONRECORD/')"
  1321.  echo "$xBOOTCONFIG" > /pup_new/etc/rc.d/BOOTCONFIG
  1322.  echo "LASTUNIONRECORD='$(echo -n $NEWUNIONRECORD)'" >> /pup_new/etc/rc.d/BOOTCONFIG
  1323. else
  1324.  echo "" > /pup_new/etc/rc.d/BOOTCONFIG
  1325.  echo "LASTUNIONRECORD=''" >> /pup_new/etc/rc.d/BOOTCONFIG
  1326. fi
  1327.  
  1328. echo -n "${L_SWITCH_ROOT}" > /dev/console
  1329.  
  1330. rm -r -f "/pup_new/initrd${SAVE_LAYER}"
  1331. for ONEMNT in $(mount | cut -f 3 -d ' ' | grep -v 'pup_new' | grep '^/pup_' | tr '\n' ' ');do
  1332.  mkdir -p /pup_new/initrd${ONEMNT}
  1333.  mount -o move $ONEMNT /pup_new/initrd${ONEMNT}
  1334. done
  1335. for ONEMNT in $(mount | cut -f 3 -d ' ' | grep '^/mnt/' | tr '\n' ' ');do
  1336.  mkdir -p /pup_new/initrd${ONEMNT}
  1337.  mount -o move $ONEMNT /pup_new/initrd${ONEMNT}
  1338. done
  1339.  
  1340. echo "SAVE_FN=$SAVE_FN"         #debug
  1341. echo "SAVE_LAYER=${SAVE_LAYER}" #debug
  1342.  
  1343. if [ "$PUPSAVE" ];then
  1344.  if [ "$SAVE_LAYER" -a -L "$SAVE_LAYER" ];then
  1345.   ln -sv "/initrd${SAVE_FN}" "/pup_new/initrd${SAVE_LAYER}" #for after switch
  1346.  fi
  1347. fi
  1348.  
  1349. echo -------------------- # debug
  1350. mount
  1351. echo -------------------- # debug
  1352.  
  1353. if [ -d /pup_new/initrd/mnt/tmpfs/pup_rw ] ; then
  1354.  rm -rf /pup_new/initrd/pup_rw
  1355.  ln -sv /initrd/mnt/tmpfs/pup_rw /pup_new/initrd/pup_rw #for after switch
  1356. fi
  1357. if [ -d /pup_new/initrd/mnt/tmpfs/pup_ro1 ] ; then
  1358.  rm -rf /pup_new/initrd/pup_ro1
  1359.  ln -sv /initrd/mnt/tmpfs/pup_ro1 /pup_new/initrd/pup_ro1 #for after switch
  1360. fi
  1361.  
  1362. mkdir -p /pup_new/initrd/mnt/tmpfs/tmp
  1363. [ -L /pup_new/tmp ] && rm -fv /pup_new/tmp
  1364. if [ -d "/pup_new/initrd/mnt/tmpfs/tmp" ];then
  1365.   chmod 1777 /pup_new/initrd/mnt/tmpfs/tmp
  1366.   rm -rf /pup_new/tmp
  1367.   ln -sv /initrd/mnt/tmpfs/tmp /pup_new/tmp #for after switch
  1368. fi
  1369.  
  1370. #PNOX is a boot param. /etc/profile prevents X from starting if this file exists...
  1371. [ "$PNOX" = "yes" ] && touch /pup_new/tmp/bootcnt.txt
  1372. cp -a /DISTRO_SPECS /pup_new/initrd/
  1373. cp /init* /pup_new/initrd/
  1374. chmod -x /pup_new/initrd/init
  1375. dmesg > /tmp/dmesg.txt
  1376.  
  1377. [ -d "/pup_new/initrd/tmp" ] && rm -rf /pup_new/initrd/tmp
  1378. mkdir -p /pup_new/initrd/tmp
  1379. cp -af /tmp/* /pup_new/initrd/tmp/ #keep any log files.
  1380.  
  1381. [ -f /sbin/set_plang ] && plang_copy_to_newroot #$LANG, /etc/keymap|fontmap|codepage
  1382.  
  1383. if [ "$RDSH" = "yes" ];then
  1384.  echo > /dev/console
  1385.  echo "${L_DROPPED_TO_INITRD_SHELL}" > /dev/console
  1386.  exec /bin/sh >/dev/console 2>&1
  1387. fi
  1388.  
  1389. sync
  1390. [ -d "/proc/bus/usb" ] && umount /proc/bus/usb
  1391. umount /sys
  1392. umount /dev
  1393. umount /proc
  1394.  
  1395. # make sure /pup_new/sbin/mount.exfat is not missing...
  1396. [ ! -f /pup_new/sbin/mount.exfat ] && cp -u /bin/mount.exfat* /pup_new/sbin/
  1397.  
  1398. #now using cpio archive for initramfs 'initial ramdisk'...
  1399. exec switch_root /pup_new /sbin/init
  1400.  
  1401. ###END###
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top