Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 25 Mar 2019, 10:11
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
alt-pupsave-create, version 9c
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [1 Post]  
Author Message
musher0

Joined: 04 Jan 2009
Posts: 13768
Location: Gatineau (Qc), Canada

PostPosted: Mon 10 Dec 2018, 18:10    Post subject:  alt-pupsave-create, version 9c
Subject description: Edited Alternative Script to Create Pupsaves
 

Hello all.

Sorry if this is repetitive, I couldn't find my original thread on the subject.

This script can create a pupsave for a good number of Pups.
Code:
bionic CE      dpup    kdpup   lupu    polar   precise quirky  racy    raring slacko   sulu    wary    wheezy  wolx
Sure, every Pup can create a pupsave at the end of first boot. But I find it
handy to have an independent script in a Pup that can create a
pupsave for another Pup.


E.g., I met with a real snafu eqrlier today. I made an error testing my
RAMdisk script and zram occupied all the pupsave space, haha. Creating
a new pupsave was the only way out. And then copying into it the
contents from a back-up I had.

Another example is when you want to reduce the size of a pupsave. The
only way is to create a new, smaller pupsave, and then copy the old
contents into the new pupsave. Reference.

Thirdly, you may wish to have specialized pupsaves, say one pupsave
focusing on Wine programs, one for development, one for usual use.
This script will indeed make things much simpler for you in such a case.

Yes, this script has limited usefulness, but it's still worth having, I think.

~~~~~~~~

So this version is an update: in addition to what the former one did, it
allows the user to
-- choose the filesystem (2fs, 3fs, or 4fs) and
-- presents more choices for pupsave sizes (from 96M to 960 M in
increments of 96M). The usual Pup utility for this does not have all of
those sizes.
-- it also can supply three secondary names: arf, wouf and yap, as in
xenialsave-yap.?fs, xenialsave-wouf.?fs, xenialsave-arf.?fs.

Thus, theoretically, you can run this script nine (9) times, creating a
series of pupsaves of different sizes and filesystems, before the script
says "Uh-oh, you can't anymore." I.e. before you have to go down in Rox
or console and start copying these new pupsave files in the Puppy
directories where they belong.

If this feature is not clear to you, try it. If it's still unclear after you dirtied
your hands, ask below!!

~~~~~~~~~

I have tested this script extensively, I believe, but if you find any bugs,
please report them below. I'll try to solve them as best I can.

IHTH. Enjoy!

TWYL.

.~~~~~~~~~~~
Code:
#!/bin/bash
# alt-pupsave-create9c.sh
# Purpose: alternative pupsave creation and extension
# by musher0, Nov. 29-30, Dec. 2 and 7, 2013.
# Revisions:
# Dec. 2, 2013. Added structure for discovery of
# ------------- current Puppy's name. musher0
# Dec. 7, 2013. Added "satellite" routine. musher0
# Dec. 10. 2018. Added arf, wouf, yap and 2fs, etc., sub-routines.
# Thanks to Karl_Godt and L18L for feedback at initial stage.
####
# Variables
unset DRV;unset NOM;unset taille;unset THISPUP;unset DOG;unset FICH;unset PART
#
DRV="sda1"
DOG="`grep YSF /etc/DISTRO_SPECS | cut -d_ -f3-4 | cut -d. -f1-2`"

# Functions
function LST {
     df -H -T | awk '$7 ~ /nt\/s/ && $2 !~ /fus/ { print $0 }' | sort
} # Displays list of partitions mounted at the moment.
#
function create {
dd if=/dev/zero of="${NOM}"save-"${SeconD}"."${n}"fs bs=1k count="$taille"
[ $? = 0 ] || { echo "Sorry, unable to create savefile correctly. Press Return to exit";read;return 1; }
mkfs.ext"${n}" -q -m 0 -F "$NOM"save-"${SeconD}"."${n}"fs &
[ $? = 0 ] || { echo "Sorry, unable to create filesystem in savefile. Press Return to exit";read;return 1; }
# Thanks to Karl_Godt for suggesting this form of error checks.
}
#
function ajouter {
echo "[1] = 96M; [2]= 192M; [3] = 288M; [4]= 384M; [5] = 480M;
[6] = 576M; [7] = 672; [8] 768M; [9] = 864M; [10] = 960M;."
echo "Type a number from 1 to 5 only."
z="";read z;[ "$z" -lt "1" ] && z="1";[ "$z" -gt "10" ] && z="10"
taille="`expr $z \* 98304 `"
}
#
# Satellite script to move files.
function satellite {
# Interaction
echo
echo "These partitions are mounted and available at the moment:"
echo
LST # We display the results.
echo
echo "On which one do you want to put your pupsave file?"
echo "You need only type the last two characters (e.g. 'b1')"
echo
read PART
# Check
if [ "`LST | grep "$PART"`" = "" ];then
     echo
     echo " That partition is not available."
     echo "Please re-run the script. Exiting."
     read
     exit
     else
          if [ -f /mnt/sda1/pupsaveresize.txt ];then
               FICH="pupsaveresize.txt"
          elif [ "`ls -1 /mnt/sda1/*-arf.2fs`" != "" ];then
               cd /mnt/sda1
               ls -1 *-arf.2fs > /tmp/noms2fs
               head -n 1 /tmp/noms2fs > /tmp/nom2fs
               FICH="`cat /tmp/nom2fs`"
          else
               echo
               echo "The required files were not found. Press Return to exit."
               read
               exit
          fi
# Which file. Are mutually exclusive, make it so in AltPupsaveCreate script.
     echo "Are you sure you want to move"
     QUESTION="$FICH to /mnt/sd$PART"
     if [ "$FICH" = "pupsaveresize.txt" ];then
          echo "$QUESTION"
          echo
          else
               echo "$QUESTION/"$DOG"?"
     fi
     echo "Press Return to confirm, Ctrl-C to exit."
     read
     echo "Fine! We now proceed."
fi
#
# Action
if [ $FICH = "pupsaveresize.txt" ];then
# Top level for file pupsaveresize.txt
     [ "$PART" = "${DRV:2:2}" ] && echo "The file is already there." || mv /mnt/sda1/"$FICH" /mnt/sd"$PART"
     else
# Subfolder for other
          mkdir -p /mnt/sd"$PART"/"$DOG"
          mv /mnt/sda1/"$FICH" /mnt/sd"$PART"/"$DOG"
fi
echo
} # End of satellite

clear
echo
echo "   Alternative pupsave creation & extension script,"
echo "           V. 9c, by 'musher0', Dec. 10, 2018."
echo "     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo
echo "Do you wish to ADD to an existing pupsave file OR"
echo "CREATE a new one? Type"
echo "[A] to Add, [C] to Create, [any other key] to exit."
read M
case $M in
     A|a)echo
          echo "How much room do you need to add to your pupsave file?"
          ajouter
          echo -n $taille > /mnt/"$DRV"/pupsaveresize.txt
          echo
          echo "We need to open the partition where the target"
          echo "pupsave file is located, and move 'pupresavesize.txt'"
          echo "at the TOP LEVEL of that partition."
          echo
          echo "A sub-script can do it for you. Do you wish to run it?"
          echo "Please type [y]es or [n]o."
          read S
          case $S in
               Y|y)satellite;;
               *);;
          esac
          echo "Now, please reboot with THAT Puppy and the size"
          echo "of ITS pupsave will be increased by "$taille" Kb."
          ;;
     C|c)echo
          echo "-- Please note --  This 'alt-pupsave-create' script:"
          echo "1) will not create a pupsave file on an ntfs partition;"
          echo "2) only creates a ext2 file-system within the pupsave file;"
          echo "3) the size of which will be a multiple of 192M (up to 960M);"
          echo "4) you can't customize the file name from within this script."
          echo
          echo "If those limitations do not suit you, press Ctrl+C to exit."
          echo "Or press Return to begin."
          read
          clear
          echo
          echo "    Alternative pupsave creation script (cont'd)"
          echo "    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
          echo
          echo "A few checks will now be done. Thanks for your patience..."
# various checks
          if [ "`blkid | grep \"v/sd\"`" = "" ];then
               echo "You are on a diskless computer. Please save your Puppy"
               echo "session on CD or DVD in multi-session mode using the"
               echo "normal Puppy shutdown sequence."
          elif [ "`blkid | grep "$DRV" | grep ntfs`" ];then
               echo "Your "$DRV" partition is in ntfs format. It should not be altered"
               echo "from an outside Linux script. Alternatives are suggested at:"
               echo "http://puppylinux.info/topic/53-advice-needed."
               echo "[1]: go there; [2]: use /mnt/sdb1 instead (can be a USB drive);"
               echo "[any other key]: exit."
               read B
               case $B in
                    1)exec rox -U http://puppylinux.info/topic/53-advice-needed;;
                    2)unset DRV;DRV="sdb1"
                    echo "Please connect your formated drive (if USB);"
                    echo "press Return to continue."
                    read
                    echo "We check again... Please wait a few seconds."
                    if [ "`blkid | grep "$DRV" | grep ntfs`" ];then
                         echo "This "$DRV" partition is also in ntfs format."
                         echo "It should not be altered from a Linux script."
                         echo "This script will now exit."
                         exit
                    fi;;
                    *)exit;;
               esac
          else
               if [ "`LST | grep -m 1 $DRV`" ];then
                    echo "A Linux partition is mounted at /mnt/"$DRV". We continue."
                    else
                         mkdir -p /mnt/"$DRV"
                         mount /dev/"$DRV" /mnt/"$DRV"
               fi
               cd /mnt/"$DRV"
               echo
               echo "How big do you need your pupsave to be, in multiples of 192M?"
               ajouter
               echo "A pupsave file of "$taille" Kb will be created for you."
               echo
               echo "Here are the names of some recent Puppies:"
               echo "  CE dpup kdpup lupu polar precise quirky"
               echo "  racy raring slacko sulu wary wheezy wolx"
               echo
               grep PREFIX /etc/DISTRO_SPECS > /tmp/PuppyName
               [ $? = 0 ] || { echo "Sorry, unable to find the name of your Puppy. Press Return to exit.";read;return 1; }
               THISPUP="`cut -d\' -f2 /tmp/PuppyName`"
               echo "Your Puppy's name appear to be: "$THISPUP", BUT"
               echo "this script allows you to create pupsave"
               echo "files for other Puppies as well."
               echo
               echo "Do you wish to create a pupsave file for "$THISPUP"?"
               echo "  [y]es or [n]o? (Letter case does not matter.)"
               read Z
               case $Z in
                    Y|y)NOM="$THISPUP"
# ext2, 3 or 4
                    echo "Please specify the filesystem for this save file:
     2fs, 3fs or 4fs. Please type only the number
          (type a number from 2 to 4 only)."
                    n="";read n;[ "$n" -lt "2" ] && n="2";[ "$n" -gt "4" ] && n="4"

# arf, wouf, or yap
                    SeconD=arf
                    if [ ! -f /mnt/$DRV/${NOM}save-${SeconD}.${n}fs ];then
                         create
                    else
                         SeconD=wouf
                         if [ ! -f /mnt/$DRV/${NOM}save-${SeconD}.${n}fs ];then
                              create
                         else
                              SeconD=yap
                              if [ ! -f /mnt/$DRV/${NOM}save-${SeconD}.${n}fs ];then
                                   create
                              else
                                   echo "
                                   Sorry, all secondary names are taken. Exiting."
                                   exit
                              fi
                         fi
                    fi ;;
# With these two sub-routines, possibility of 9 different pupsaves
# for one Pup.
                    *)echo
                         echo "Type in the Puppy's name. Please check the spelling!"
                         echo "During the process, if asked, press [y]es."
                         read NOM
                         echo "~~~~~~~~~~~~~~~"
                         case $NOM in
                              bionic|CE|dpup|kdpup|lupu|polar|precise|quirky|racy|raring|slacko|sulu|wary|wheezy|wolx)create;;
                              *)echo
                                   echo "The name that you provided does not appear in"
                                   echo "the above list. Type [y] if it's ok to continue."
                                   echo "Any other key exits the script."
                                   echo
                                   read A
                                   case "$A" in
                                        Y|y)create;;
                                        *)echo
                                             echo "Please check the basic name of your pupsave"
                                             echo "and rerun this script. Press Return to exit."
                                             read
                                             exit;;
                                   esac
                              ;;
                         esac
                    ;;
               esac
          echo "~~~~~~~~~~~~~~~"
          sleep 2s
          echo
          echo "Success! You'll find your new "$NOM"save file on "$DRV"."
          echo "You can leave it there, but it is suggested that you:"
          echo "-- create a folder;"
          echo "-- name it to represent your Puppy's name; and"
          echo "-- move the "$NOM"save file in that folder,"
          echo "--    to keep things organized."
          echo "$DOG" > /tmp/dog
          if [ "`grep -o "$NOM" /tmp/dog`" ];then
               echo
               echo "Since this new "$NOM"save file will be used on this Puppy, a"
               echo "satellite script can do it for you. Do you wish to run it?"
               echo "Please type [y]es or [n]o."
               read S
               case $S in
               Y|y)satellite;;
               *);;
               esac
          fi
          echo
          echo "You can also change manually the part of the file name"
          echo "-- between the hyphen and the dot --, if you so wish."
          echo "   ------------------------------"
          echo
          echo "You can now reboot your Puppy. It will load the newly"
          echo "created "$NOM"save file automatically, OR, if you"
          echo "have more than one pupsave file for that Puppy, you"
          echo "will be able to load it from a sub-menu."
     fi
     ;;
     *)echo;;
esac
echo
echo "Have a great day!"
echo "Press Return to exit."
read
rox /mnt/"$DRV"
# Clean-up
rm -f /tmp/no*fs
rm -f /tmp/PuppyName
rm -f /tmp/dog
## 30 ##
alt-pupsave-create9c.sh.zip
Description  Same as above, but zipped. Unzip in a "bin" directory in your path and make
executable before using.
zip

 Download 
Filename  alt-pupsave-create9c.sh.zip 
Filesize  4 KB 
Downloaded  69 Time(s) 

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [1 Post]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0521s ][ Queries: 13 (0.0077s) ][ GZIP on ]