Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #First part of this script is based on: woof-CE/woof-code/rootfs-skeleton/usr/sbin/resizepfile.sh
- export TEXTDOMAIN=resizepfile.sh
- export OUTPUT_CHARSET=UTF-8
- . gettext.sh
- . /etc/rc.d/PUPSTATE #variables created at bootup by /initrd/usr/sbin/init...
- . /etc/DISTRO_SPECS
- PUPSAVE=$1
- SAVEPATH=$1
- SAVEPATH="$(realpath "$SAVEPATH")"
- SAVEFILE="$(basename "$SAVEPATH")"
- SAVEFS="`echo -n "$SAVEFILE" | sed -r 's#^(.*)([.])([^.]*)$#\3#'`"
- SAVEPART="$(df "$SAVEPATH" | sed -r 's#^(/dev/)([^[:blank:]]*)([[:blank:]].*)$#\2#g' | tail -n1)"
- PERSISTMNTPT=$1 #This is typically the save file.
- NAMEPFILE="`basename $SAVEFILE`"
- append_mnt_id_awk='
- function get_mnt_id(mnt_pt,loop){
- if (length(mnt_pt) > 0 && length(loop)>0){
- cmd="cat /proc/self/mountinfo | sort | grep '" loop "' | grep " mnt_pt " | head -n 1"
- } else if (length(mnt_pt) > 0){
- cmd="cat /proc/self/mountinfo | sort | grep '" mnt_pt "' | head -n 1"
- } else if (length(loop)>0){
- cmd="cat /proc/self/mountinfo | sort | grep '" loop "' | head -n 1"
- }
- while ((cmd | getline )){
- mnt_id=$1
- break
- }
- close(cmd)
- return mnt_id
- }
- {
- mnt_pt=$1
- loop=$2
- mnt_id=get_mnt_id(mnt_pt,loop)
- print mnt_id "|" mnt_pt "|" loop
- }'
- SAVEPATH="$(realpath "$SAVEPATH")"
- loop=$(losetup -a | grep "${SAVEPATH}" | sed "s/:.*$//" )
- if [ ! -z "$loop" ]; then #
- PERSISTMNTPT="$(findmnt -o TARGET,SOURCE -D -n | grep 'loop5$' | awk "$append_mnt_id_awk" | sort -t '|' -k1 | cut -d'|' -f2 | head -n 1)"
- else
- PERSISTMNTPT="$2"
- if [ -z "$PERSISTMNTPT" ]; then
- PERSISTMNTPT="$(mktemp -d -p /mnt "$SAVEFILE".XXXX)"
- fi
- #mkdir -p "$PERSISTMNTPT"
- mount -r -t "$SAVEFS" ${SAVEPATH} "$PERSISTMNTPT"
- fi
- HOMELOCATION="$SAVEPATH" #"/initrd${PUP_HOME}${SAVEFILE}"
- if [ -d $HOMELOCATION ] ; then
- exec /usr/lib/gtkdialog/box_ok "$(gettext 'Resize personal storage file')" info "<b>$(gettext "Puppy is currently using a savefolder. There is no need to resize it")</b>" " "
- fi
- SIZEFREE=`df -m | grep "$PERSISTMNTPT" | tr -s " " | cut -f 4 -d " "` #free space in ${DISTRO_FILE_PREFIX}save.3fs
- ACTUALSIZK=`stat -c %s $HOMELOCATION` #total size of ${DISTRO_FILE_PREFIX}save.3fs
- ACTUALSIZE=`expr $ACTUALSIZK \/ 1024 \/ 1024`
- APATTERN="/dev/${SAVEPART} "
- PARTSIZE=`df -m | grep "$APATTERN" | tr -s " " | cut -f 2 -d " "`
- PARTFREE=`df -m | grep "$APATTERN" | tr -s " " | cut -f 4 -d " "`
- . /usr/lib/gtkdialog/svg_bar 200 "$(($(($ACTUALSIZE-$SIZEFREE))*200/$ACTUALSIZE))" "$ACTUALSIZE Mb / $SIZEFREE Mb $(gettext 'free')" > /tmp/resizepfile_pfile.svg
- . /usr/lib/gtkdialog/svg_bar 200 "$(($(($PARTSIZE-$PARTFREE))*200/$PARTSIZE))" "$PARTSIZE Mb / $PARTFREE Mb $(gettext 'free')" > /tmp/resizepfile_partition.svg
- for i in 32 64 128 256 512 1024 2048 4096 8192 12288 16384 24576 32768 65536
- do
- [ $i -lt $PARTFREE ] && MBCOMBO="$MBCOMBO <item>${i}</item>"
- done
- x='
- <window title="'$(gettext 'Resize Personal Storage File')'" icon-name="gtk-refresh" resizable="false">
- <vbox space-expand="true" space-fill="true">
- '"$(/usr/lib/gtkdialog/xml_info fixed puppy_increase.svg 60 "$(eval_gettext "<b>Your personal file is \${NAMEPFILE},</b> and this contains user data, configuration files, email, newsgroup cache, history files and installed packages...")" "$(eval_gettext "If you see that you are running low on space in \$NAMEPFILE, you can make it bigger, but of course there must be enough space in \$SAVEPART.")")"'
- <vbox space-expand="true" space-fill="true">
- <frame>
- <text height-request="5"><label>""</label></text>
- <vbox space-expand="true" space-fill="true">
- <vbox space-expand="false" space-fill="false">
- <hbox>
- <text xalign="0" use-markup="true"><label>"<b>'$(gettext 'Personal File')'</b>: '$NAMEPFILE'"</label></text>
- <text space-expand="true" space-fill="true"><label>""</label></text>
- <pixmap><input file>/tmp/resizepfile_pfile.svg</input></pixmap>
- </hbox>
- <hbox>
- <text xalign="0" use-markup="true"><label>"<b>'$(gettext 'Partition')'</b>: '$SAVEPART'"</label></text>
- <text space-expand="true" space-fill="true"><label>""</label></text>
- <pixmap><input file>/tmp/resizepfile_partition.svg</input></pixmap>
- </hbox>
- </vbox>
- <text height-request="5" space-expand="true" space-fill="true"><label>""</label></text>
- <vbox space-expand="false" space-fill="false">
- <hbox space-expand="true" space-fill="true">
- <text xalign="0" space-expand="true" space-fill="true"><label>'$(eval_gettext "Increase size of \$NAMEPFILE by amount (Mb). You cannot make it smaller.")'</label></text>
- <comboboxtext width-request="100" space-expand="false" space-fill="false">
- <variable>KILOBIG</variable>
- '${MBCOMBO}'
- </comboboxtext>
- </hbox>
- </vbox>
- <text height-request="10"><label>""</label></text>
- </vbox>
- </frame>
- </vbox>
- <hbox space-expand="false" space-fill="false">
- '"`/usr/lib/gtkdialog/xml_pixmap nb`"'
- <text xalign="0" use-markup="true" space-expand="true" space-fill="true"><label>"<b>'$(gettext 'Resizing requires a system reboot')'</b>"</label></text>
- <button space-expand="false" space-fill="false">
- <label>'$(gettext "Cancel")'</label>
- '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
- <action type="exit">EXIT_NOW</action>
- </button>
- <button space-expand="false" space-fill="false">
- <label>'$(gettext "Ok")'</label>
- '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
- <action type="exit">save</action>
- </button>
- </hbox>
- </vbox>
- </window>'
- export resize="$x"
- . /usr/lib/gtkdialog/xml_info gtk > /dev/null #build bg_pixmap for gtk-theme
- eval $(gtkdialog -p resize)
- PUPSAVERESIZENEW="$(mktemp -p /tmp pupsaveresizenew.XXXX.txt)"
- case ${EXIT} in save)
- KILOBIG=$(($KILOBIG * 1024))
- echo "KILOBIG=$KILOBIG" > "$PUPSAVERESIZENEW"
- echo "PUPSAVEFILEX=$SAVEFILE" >> "$PUPSAVERESIZENEW" #131231
- /usr/lib/gtkdialog/box_ok "$(gettext 'Resize personal storage file')" complete "$(eval_gettext "Okay, you have chosen to <b>increase \${NAMEPFILE} by \${KILOBIG} Kbytes</b>, however as the file is currently in use, it will happen at reboot.")" " " "$(gettext 'Technical notes:')" "$(eval_gettext "The required size increase has been written to file pupsaveresizenew.txt, in partition \${SAVEPART} (currently mounted on /mnt/home).")" "$(gettext 'File pupsaveresizenew.txt will be read at bootup and the resize performed then pupsaveresizenew.txt will be deleted.')" "$(eval_gettext "WARNING: If you have multiple \${DISTRO_FILE_PREFIX}save files, be sure to select the same one when you reboot.")" " " "<b>$(gettext 'You can keep using Puppy. The change will only happen at reboot.')</b>"
- ;;
- esac
- set +x
- echo "About to resize save file"
- read -p "Press Enter to continue"
- set -x
- #umount "$PERSISTMNTPT"
- mount -r -t "$SAVEFS" -o remount ${SAVEPATH} "$PERSISTMNTPT"
- source "$PUPSAVERESIZENEW" #See: https://github.com/puppylinux-woof-CE/woof-CE/blob/2caf45160363bdb804cf63055f2ba4eb769869d6/initrd-progs/0initrd/sbin/load_ext_file#L39
- dd if=/dev/zero bs=1024 count=$KILOBIG >> "${SAVEPATH}" #Appends zeros. See https://github.com/puppylinux-woof-CE/woof-CE/blob/2caf45160363bdb804cf63055f2ba4eb769869d6/initrd-progs/0initrd/sbin/load_ext_file#L52
- SAVEFILE_LOOP=$(losetup -a | grep "${SAVEPATH}" | sed "s/:.*$//" )
- resize2fs -pf "$SAVEFILE_LOOP" #See https://github.com/puppylinux-woof-CE/woof-CE/blob/2caf45160363bdb804cf63055f2ba4eb769869d6/initrd-progs/0initrd/sbin/load_ext_file#L172
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement