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 15 Oct 2018, 11:23
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Bind & Link a Save File using Bash into a Running Puppy
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [10 Posts]  
Author Message
s243a

Joined: 02 Sep 2014
Posts: 1216

PostPosted: Fri 20 Apr 2018, 02:02    Post subject:  Bind & Link a Save File using Bash into a Running Puppy  

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:

#!/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:

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.
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5216
Location: Republic of Novo Zelande

PostPosted: Sat 21 Apr 2018, 04:20    Post subject: Re: Bind & Link a Save File using Bash into a Running Puppy  

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)
Smile
Back to top
View user's profile Send private message 
s243a

Joined: 02 Sep 2014
Posts: 1216

PostPosted: Sat 21 Apr 2018, 22:24    Post subject: Re: Bind & Link a Save File using Bash into a Running Puppy  

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:

/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.

Quote:

(couldn't test your script as your root UUID did not match mine for some weird reason)
Smile


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:

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.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4841
Location: Blue Springs, MO

PostPosted: Mon 23 Apr 2018, 03:53    Post subject:  

I think tiny core Linux does this.
_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
nic007


Joined: 13 Nov 2011
Posts: 2646
Location: Cradle of Humankind

PostPosted: Mon 23 Apr 2018, 04:04    Post subject:  

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.
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 951
Location: not Bulgaria

PostPosted: Mon 23 Apr 2018, 21:47    Post subject:  

technosaurus wrote:
I think tiny core Linux does this.


Yes, I think same or similar method instead of using aufs or overlay fs.
Back to top
View user's profile Send private message 
s243a

Joined: 02 Sep 2014
Posts: 1216

PostPosted: Mon 23 Apr 2018, 22:49    Post subject:  

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.
Back to top
View user's profile Send private message 
s243a

Joined: 02 Sep 2014
Posts: 1216

PostPosted: Sun 29 Apr 2018, 15:05    Post subject:  

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:

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:

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:

  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:

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.
Back to top
View user's profile Send private message 
s243a

Joined: 02 Sep 2014
Posts: 1216

PostPosted: Sun 29 Apr 2018, 18:10    Post subject:  

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

indexgen.sh #this line might not be necessary
fixmenus
jwm -reload

As is done in petget
pearltrees pastbin github
Back to top
View user's profile Send private message 
s243a

Joined: 02 Sep 2014
Posts: 1216

PostPosted: Sun 29 Apr 2018, 19:22    Post subject:  

It appears that I need to call
Code:

sync


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

/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.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [10 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
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.0681s ][ Queries: 11 (0.0068s) ][ GZIP on ]