Bind & Link a Save File using Bash into a Running Puppy

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

Bind & Link a Save File using Bash into a Running Puppy

#1 Post by s243a »

I wrote a script to take a save file and Merge it into a running version of puppy as follows:
1. Directories are binded if they don't exist, otherwise we recurse to a subdirectory.
2. Files in non bound directories are symbolically linked
3. Symbolic Links are copied.

Not Implemented is checking copied symbolic links and repairing any errors if any. The script run and successfully binds the directories via recursion. I haven't tested it yet though with running programs and it is very preliminary.

I also want to be able to create exceptions for various directories and maybe allow some special case handling of certain directors based on a configuration directory (or file).

One difficulty I had was trying to work with the "Null Character" as a field separator. This took me lots of trial and error and I still don't really understand it. I didn't find any good examples or tutorials on this but there were some stackoverflow discussions to give me hints.

What worked for me is to create a function to do string substitution in a pipe, which I made as a seperate file in my search path called removePrefix

Code: Select all

#!/bin/bash
  #bla=$IFS
  #FS=$'\0'
  while read -r -d '' a; do
    echo "a=$a">>/mnt/sdc6/removePrefixLog
    echo "${a#$1}"
    echo "${a#$1}">>/mnt/sdc6/removePrefixLog  
  done
This function is used as follows

Code: Select all

DIRS2=( $( find $SR$one -mindepth 1 -maxdepth 1 -print0 -name '*'  | removePrefix "$SR" ) )# 
I will add more to this thread later, after I do some testing.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

Re: Bind & Link a Save File using Bash into a Running Puppy

#2 Post by greengeek »

s243a wrote:I wrote a script to take a save file and Merge it into a running version of puppy as follows:
Do you mean that it adds the save file into the main puppy.sfs? (or into a zdrv or adrv or similar?)
(couldn't test your script as your root UUID did not match mine for some weird reason)
:-)

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

Re: Bind & Link a Save File using Bash into a Running Puppy

#3 Post by s243a »

greengeek wrote:
s243a wrote:I wrote a script to take a save file and Merge it into a running version of puppy as follows:
Do you mean that it adds the save file into the main puppy.sfs? (or into a zdrv or adrv or similar?)
No it just links everything from an existing puppy into your current session. The reason, that I did this that my initrd.gz got corrupted and I wanted to be able to re-use my save file without rebooting.

I could modify the shutdown script so that it copies stuff back from

Code: Select all

/initrd/pup_rw
back to a save file/folder or one of the sfs files that you mention above. A perhaps better alternative would be to modify the installation script so it does this. This way if the power fails one doesn't have a half install.
(couldn't test your script as your root UUID did not match mine for some weird reason)
:-)
Line#23 if you're inclined to change it but I presume you knew that.

If your inclined to test it then follow these steps:
1. Copy your save file to a new location
2. Boot Puppylinux from a read only CD
3. Set the following to the location of the new save file:

Code: Select all

LN#23 ROOT_UUI="ebeda76b-c7e8-d201-a020-a46bc7e8d201" 
LN#30 ROOT_REL_PATH="/tahrsave"
Make sure that you copy bot map_save and removePrefix. removePrefix, has to be in your bash search path.

I don't need testers at this point, but if anyone does please let me know how it works or fails.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#4 Post by technosaurus »

I think tiny core Linux does this.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#5 Post by nic007 »

If you use an adrv and/or ydrv (which is read-only sfs) to record your savings, you won't have any problems with corrupt files. If you are concerned with power-outage: I run a script whenever I want to save the session's changes to an adrv (and replace the previous adrv). So you can schedule to run this script automatically in intervals during a session if you like.

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#6 Post by wiak »

technosaurus wrote:I think tiny core Linux does this.
Yes, I think same or similar method instead of using aufs or overlay fs.

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#7 Post by s243a »

nic007 wrote:If you use an adrv and/or ydrv (which is read-only sfs) to record your savings, you won't have any problems with corrupt files. If you are concerned with power-outage: I run a script whenever I want to save the session's changes to an adrv (and replace the previous adrv). So you can schedule to run this script automatically in intervals during a session if you like.
It wasn't my save file that got corrupted, it was my initrd.gz that got corrupted. Oddly so did the version that I saved to dropbox, which shouldn't be possible (I think).

It is a custom version so it would take me some time to fix it, especially given that each boot takes quite a while on this machine.

I could use an adrv, though (which is just like mounting an sfs). I could mount the adrv before applying my script. The strategy would to be to try to put in the adrv what would limit the amount of disc writes, since in my case I'm using a slow USB 2.0 (or earlier) connection to connect to a very large hard drive.

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#8 Post by s243a »

I made my first attempt at copying files back to the save file:

https://pastebin.com/kPQ51AsF

One issue I was having is that when I was doing a "for in" loop that the first entry had the "(" prepended to it and the last entry had the ")#" prepended to it.

As mentioned above the array was created via:

Code: Select all

DIRS2=( $( find $RW_ROOT$one -mindepth 1 -maxdepth 1 -print0 -name '*'  | removePrefix "$RW_ROOT" ) )# 
in the function which is now called 'save_dir_files'

Code: Select all

save_dir_files(){ #Was bind_and_link_dir in map_save
  #local -n one=$1
  if [ $# -lt 2 ]; then 
    SR="$SAVE_ROOT"
  else
    SR=$2
  fi	
  one="$1"
  echo "LN#68 one=$one"  
  [ ! `mountpoint -q "$one"` ] || return _
  mkdir -p "$SAVE_ROOT$one"
  DIRS2=( $( find $RW_ROOT$one -mindepth 1 -maxdepth 1 -print0 -name '*'  | removePrefix "$RW_ROOT" ) )# 
  echo "LN#72 DIRS2=${DIRS2[@]}"
  save_dir_array DIRS2 $2 
}
To remove this I had a little hack

Code: Select all

  one=${one[*]} #https://stackoverflow.com/questions/3348443/a-confusion-about-array-versus-array-in-the-context-of-a-bash-comple?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
  one=${one#'('} #https://stackoverflow.com/questions/16623835/remove-a-fixed-prefix-suffix-from-a-string-in-bash?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
  one=${one%')#'}
in the file "save_dir_array"

Code: Select all

save_dir_array(){ #Was bind_and_link_array in map_save
  local -n one=${1}	# https://stackoverflow.com/questions/16461656/how-to-pass-array-as-an-argument-to-a-function-in-bash
  #declair -a one=$one1
  if [ $# -lt 2 ]; then 
    SR="$SAVE_ROOT"
  else
    SR=$2
  fi
  one=${one[*]} #https://stackoverflow.com/questions/3348443/a-confusion-about-array-versus-array-in-the-context-of-a-bash-comple?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
  one=${one#'('} #https://stackoverflow.com/questions/16623835/remove-a-fixed-prefix-suffix-from-a-string-in-bash?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
  one=${one%')#'}
  echo "Ln 49 one=${one[@]}"	
  IFS_OLD=$IFS
  IFS=$'\n'
  for a in ${one[@]}; do
     echo "LN#53 save_file $a"
     save_file "$a" "$SR"
  done
  IFS=IFS_OLD
}
there should be a smarter way to loop through this array but I don't know it yet.

The script sucesfully copies the files back to my save file but now I"m going to try rebooting and see if I get any issues.

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#9 Post by s243a »

Anway, after doing bind and link one should do the following:

Code: Select all

indexgen.sh #this line might not be necessary
fixmenus
jwm -reload
As is done in petget
pearltrees pastbin github

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#10 Post by s243a »

It appears that I need to call

Code: Select all

sync
before running my "Update_Save" script so that all the changed files from the layered file system get copied to

Code: Select all

/initrd/pup_rw
also calling sync at the end of the script helps free up memory but not as much as a reboot. Eventually I'll look at the puppylinux snapmerge script to see what other ideas I can get about feeing up memory.

Post Reply