Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (2) </ [1] 2 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Creating own bootline command variable< Next Oldest | Next Newest >
beakmyn Offline





Group: Members
Posts: 63
Joined: Sep. 2004
Posted: Feb. 16 2007,16:07 QUOTE

I've been busy remastering DSL for my picture frame and I got to thinking, "What if the picture directory was a variable set at boot?"

I've got a script (not mine) that will take user input for a directory based on pre-defined initial directory

Code Sample
#!/bin/sh
#
# Script to run Digital Picture Frame using Feh
# drware@thewares.net
#

# Set display so that the script will effect
# the screen on the frame
export DISPLAY=:0

# Stop the currently running Slide show
/mnt/hda3/frame/kill.sh feh

clear
echo ""
echo -n "Enter the number of seconds for photo rotation "
echo -n "and press [ENTER]: "
read var_seconds
echo ""
echo "Available options for the directory are:"
ls /mnt/hda3/Pictures
echo ""
echo -n "Enter the directory of photos to display and "
echo -n "press [ENTER]: "
read var_dir
echo ""

/usr/bin/feh -qzrZF -D $var_seconds /mnt/hda3/Pictures/$var_dir &

exit 0


So I was looking at /etc/init.d/knoppix-autoconfig and I thought maybe it would be cool to tack on my own check for PICTURES=var_dir

which would write var_dir to a text file or some sort of global memory variable. I could then modify my scripts to query this variable.

Looking at the autoconfig I believe I can figure out the "getting the varible part" but I'm unsure on the "what to do with it" part, I.E. putting it into a global variable that another script can query and use.


Tips? Pointers?


--------------
Have you seen my Damn Small Digital Picture frame?
http://www.frontiernet.net/~pictureframe
http://rapidshare.com/files/27769266/pframedsl.iso.html
http://www.joyceandkevin.com/dslpictureframe/pframedsl.rar
Back to top
Profile PM WEB AOL MSN YIM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Feb. 16 2007,17:43 QUOTE

The boot line is stored in /proc/cmdline, so you can get the string like this:
Code Sample
CMDLINE=`cat /proc/cmdline`

From there you can use the $CMDLINE variable along with some of DSL's built-in functions to find a particular boot option. That variable is used extensively in dsl-functions.
This command will load the functions into your current script:
Code Sample
source /etc/init.d/dsl-functions

As an example, you could send "pictures=/path/to/directory" on the bootline, and then in your script do something like this:
Code Sample
source /etc/init.d/dsl-functions
CMDLINE=`cat /proc/cmdline`
PICTURES=`getbootparam pictures`


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
beakmyn Offline





Group: Members
Posts: 63
Joined: Sep. 2004
Posted: Feb. 16 2007,18:29 QUOTE

That makes sense. It looks like the "bulletproof" way would be something like:

(pulling code from a couple different files)

Code Sample

#!/bin/sh
#Sample script to query boot command line and store a
#parameter into a value to use later
#Here we just echo the path and list it's contents
#
#

. /etc/init.d/dsl-functions
CMDLINE="$(cat /proc/cmdline)"
PICTURES="$(getbootparam pictures 2>/dev/null)"
[ -n "$PICTURES" ] || PICTURES="/home/dsl"

echo "$PICTURES"
ls "$PICTURES"



Some Notes: (in case someone else reads this)

One could reasonably assume that CMDLINE would already be populated but it's best to populate it, just in case. It's also good practice to know what type ($ = string) your variable is before you act on it.

This gives either the passed boot command line variable or defaults user dsl home directory if no parameter is passed.


Thanks.


--------------
Have you seen my Damn Small Digital Picture frame?
http://www.frontiernet.net/~pictureframe
http://rapidshare.com/files/27769266/pframedsl.iso.html
http://www.joyceandkevin.com/dslpictureframe/pframedsl.rar
Back to top
Profile PM WEB AOL MSN YIM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Feb. 16 2007,19:17 QUOTE

Good thinking there.

If you always need PICTURES to be a directory, you could use "-d" instead of "-n" for your test. This allows you to drop the need to redirect stderr to /dev/null, since the output of getbootparam will be used only if it's an existing directory. The "-n" test simply checks to see if the variable's length is non-zero.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
beakmyn Offline





Group: Members
Posts: 63
Joined: Sep. 2004
Posted: Feb. 16 2007,20:02 QUOTE

Code Sample

#!/bin/sh
#Sample script to query boot command line and store a
#parameter into a value to use later
#Here we just echo the path and list it's contents
#
#

. /etc/init.d/dsl-functions
CMDLINE="$(cat /proc/cmdline)"
PICTURES="$(getbootparam pictures"
[ -d "$PICTURES" ] || PICTURES="/home/dsl"

echo "$PICTURES"
ls "$PICTURES"


I understand that ">/dev/null" is the redirect. But what's the 2 for?


--------------
Have you seen my Damn Small Digital Picture frame?
http://www.frontiernet.net/~pictureframe
http://rapidshare.com/files/27769266/pframedsl.iso.html
http://www.joyceandkevin.com/dslpictureframe/pframedsl.rar
Back to top
Profile PM WEB AOL MSN YIM 
7 replies since Feb. 16 2007,16:07 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (2) </ [1] 2 >/
reply to topic new topic new poll
Quick Reply: Creating own bootline command variable

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code