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 Wed 20 Nov 2019, 14:26
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Code not working in init script of initrd.gz. (Solved)
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [22 Posts]   Goto page: 1, 2 Next
Author Message
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Wed 03 Dec 2014, 18:34    Post subject:  Code not working in init script of initrd.gz. (Solved)
Subject description: ...but works in a script executed after X desktop appeared on the screen
 

Hi.

I got some code used to change the current wallpaper at boot up.

When executing this code from within a script in /root/Startup, it works as it is supposed to do.

But when inserting into the init script of the initrd.gz, it causes a Kernel Panic!

Here is the code (snippet) (the Line that causes Kernel Panic is marked up):
Quote:
read OLDWP_LINE < /etc/Puppybackgroundpicture-orig
OLDWP=$(echo $OLDWP_LINE|cut -d' ' -f2)
echo -n "$OLDWP" > /tmp/Puppybackgroundpicture
read OLDWP < /tmp/Puppybackgroundpicture
nlen="`echo ${#OLDWP}`"
OLDWP2=${OLDWP:1:nlen-2}
NEWWP2="/usr/share/backgrounds/$MYWALLPAPER"

As soon as I'm commenting out the Line OLDWP2=${OLDWP:1:nlen-2} there is NO Kernel Panic and the Puppy boots straight up - as is should do. But the script (function) won't work then.

Any hints?

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink

Last edited by LazY Puppy on Thu 04 Dec 2014, 21:38; edited 1 time in total
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2647

PostPosted: Thu 04 Dec 2014, 02:42    Post subject:  

During early boot there is no desktop yet and hence no wallpaper to change.
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Thu 04 Dec 2014, 19:05    Post subject:  

amigo wrote:
During early boot there is no desktop yet and hence no wallpaper to change.

No, you just did not understand the code.

I don't change a wallpaper at this stage of booting. Just collecting some information and echoing some of them refined for a later use.

This: OLDWP2=${OLDWP:1:nlen-2} is the line causing the kernel panic and it has nothing to do with a wallpaper!

Please read again my opening post as well as the quoted code and probably post a useful solution.

Thanks.

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Thu 04 Dec 2014, 19:49    Post subject:  

Probably some more detailed information will make it much more clear to understand what I am doing.

When the init script comes to the point where it is echoing Performing a 'switch_root' to the layered filesystem... I do a copy of /pup_new/etc/Puppybackgroundpicture.

Code:
cp -af /pup_new/etc/Puppybackgroundpicture /pup_new/etc/Puppybackgroundpicture-orig

Content of File /pup_new/etc/Puppybackgroundpicture is: -stretch "/usr/share/backgrounds/default.jpg" Nothing

I grab the BG image with this code:
Code:
read OLDWP_LINE < /pup_new/etc/Puppybackgroundpicture
OLDWP=$(echo $OLDWP_LINE|cut -d' ' -f2)

which returns to me "/usr/share/backgrounds/default.jpg"

Then echoing the result to a different temp file:
Code:
echo -n "$OLDWP" > /tmp/Puppybackgroundpicture

After this I'm reading out the original wallpaper and changing the content of /pup_new/etc/Puppybackgroundpicture

Code:
read OLDWP < /tmp/Puppybackgroundpicture
NEWWP='"/usr/share/backgrounds/'$MYWALLPAPER'"'
sed -i 's|'"$OLDWP"'|'"$NEWWP"'|' /pup_new/etc/Puppybackgroundpicture #>/dev/null

to get the new wallpaper into /pup_new/etc/Puppybackgroundpicture.

But to get the new wallpaper also into /pup_new/root/Choices/ROX-Filer/PuppyPin I need to get rid of the double quotes (") at the beginning and end of "/usr/share/backgrounds/default.jpg".

This is to be done by the line causing the Kernel Panic: OLDWP2=${OLDWP:1:nlen-2}

The exactly equal code (without the /pup_new) is working from a normal script after X desktop appeared on the screen.

Again, this is causing the Kernel Panic: OLDWP2=${OLDWP:1:nlen-2}

No wallpaper changed or even touched at this stage of booting. Only collecting and echoing information. No desktop needed at all to do such collecting and echoing of information.

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
greengeek


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

PostPosted: Thu 04 Dec 2014, 19:52    Post subject:  

LazY Puppy wrote:
This: OLDWP2=${OLDWP:1:nlen-2} is the line causing the kernel panic and it has nothing to do with a wallpaper!

I'm bad at coding but I'm going to take a stab in the dark:
Shouldnt there ba a $ sign directly in front of the OLDWP?
OLDWP2=${$OLDWP:1:nlen-2}
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Thu 04 Dec 2014, 20:00    Post subject:  

No, this gives a bad substitution.
Terminal Output wrote:
line 14: ${$OLDWP:1:nlen-2}: bad substitution

Also this:
Terminal Output wrote:
line 14: ${$OLDWP:1:$nlen-2}: bad substitution

Edit:

Idea Probably I should try just to sed the double quotes in temp file, /tmp/Puppybackgroundpicture. Idea

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 935

PostPosted: Thu 04 Dec 2014, 21:09    Post subject:  

My guess is that the bash shell is not being used at the start....
That is a "bashism" parameter expansion.

Cheers,
s
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Thu 04 Dec 2014, 21:37    Post subject:  

Ha,

in Germany we do have a saying that goes:

Man sieht den Wald vor lauter Bäumen nicht.

which could be translated like:

You can't watch the forest because of too many trees. Laughing

Yes, sed did the job and it works now as it should have done already.

seaside wrote:
My guess is that the bash shell is not being used at the start....
That is a "bashism" parameter expansion.

I already feared there must be a difference between the #!/bin/sh used in the init script and the #!/bin/sh used later in the scripts, when the desktop has appeared. Just could not imagine or explain to myself.

Thanks for all the help.

Solved!

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
Sylvander

Joined: 15 Dec 2008
Posts: 4422
Location: West Lothian, Scotland, UK

PostPosted: Thu 04 Dec 2014, 22:09    Post subject:  

LazY Puppy wrote:
You can't watch the forest because of too many trees. Laughing

Is that similar to, or the same as, the following English saying:
He/I/they "cannot see the wood for the trees"?
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Thu 04 Dec 2014, 22:24    Post subject:  

Sylvander wrote:
LazY Puppy wrote:
You can't watch the forest because of too many trees. Laughing

Is that similar to, or the same as, the following English saying:
He/I/they "cannot see the wood for the trees"?

Exactly!

Ok, I got a deeper look into that.

In initrd.gz /bin/sh is a symbolic link to /bin/busybox.

In puppy_precise_5.7.1.sfs /bin/sh is a symbolic link to /bin/bash.

That's just all, but makes a HUGE difference in use.

I assume after the switch_root is executed the symbolic link to /bin/busybox is not longer existing and #!/bin/sh will work like #!/bin/bash.

Btw: almost everything in /bin inside of the initrd.gz is a symbolic link to /bin/busybox.

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2647

PostPosted: Fri 05 Dec 2014, 13:06    Post subject:  

Yeah, I was gonna suggest that the shebang was causing the problem. You could try:
Code:
echo ${OLDWP:1:$((nlen - 2))}
Back to top
View user's profile Send private message 
MinHundHettePerro


Joined: 05 Feb 2009
Posts: 855
Location: SE

PostPosted: Fri 05 Dec 2014, 20:12    Post subject:  

Perhaps jumping in a bit late ...
To just get rid of all the double-quotes in BB-ash (or in Bash)
Code:
OLDWP2=${OLDWP//\"/}

FWIW Smile/ MHHP

_________________
Celeron 2.8 GHz, 1 GB, i82845, many ptns, modes 12, 13
Dual Xeon 3.2 GHz, 1 GB, nvidia quadro nvs 285

Slackos & 214X, ... and Q6xx
Nämen, vaf.... ln -s /dev/null MHHP
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Fri 05 Dec 2014, 21:56    Post subject:  

MinHundHettePerro wrote:
Perhaps jumping in a bit late ...
To just get rid of all the double-quotes in BB-ash (or in Bash)
Code:
OLDWP2=${OLDWP//\"/}

FWIW Smile/ MHHP

I will try this, but I will never ever understand things like: //\"/ Laughing

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
technosaurus


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

PostPosted: Sat 13 Dec 2014, 05:02    Post subject:  

Code:
OLDWP2=${OLDWP:1:nlen-2} #<-WTF is that?
during bootup sh is /bin/ash but I can't believe that works in bash
Were you trying for:
Code:
OLDWP2=${OLDWP:1:$((nlen-2))}

_________________
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 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Sat 13 Dec 2014, 05:34    Post subject:  

technosaurus wrote:
Code:
OLDWP2=${OLDWP:1:nlen-2} #<-WTF is that?
during bootup sh is /bin/ash but I can't believe that works in bash
Were you trying for:
Code:
OLDWP2=${OLDWP:1:$((nlen-2))}

From where did you quoted/coded this?

I did never write or quote: OLDWP2=${OLDWP:1:nlen-2} #, all my codes are without the #. Unless I might be blind, so w(here)tf did you get this?

This code: OLDWP2=${OLDWP:1:nlen-2} is working for me in approximately 20 to 30 (or even more) of my bash script applications. I usually start them with:
Code:
#!/bin/bash -a

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [22 Posts]   Goto page: 1, 2 Next
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.0584s ][ Queries: 11 (0.0046s) ][ GZIP on ]