Creating own bootline command variableForum: Other Help Topics Topic: Creating own bootline command variable started by: beakmyn Posted by beakmyn on Feb. 16 2007,16:07
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
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? Posted by mikshaw on Feb. 16 2007,17:43
The boot line is stored in /proc/cmdline, so you can get the string like this:
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:
As an example, you could send "pictures=/path/to/directory" on the bootline, and then in your script do something like this:
Posted by beakmyn on Feb. 16 2007,18:29
That makes sense. It looks like the "bulletproof" way would be something like:(pulling code from a couple different files)
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. Posted by mikshaw on Feb. 16 2007,19:17
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. Posted by beakmyn on Feb. 16 2007,20:02
I understand that ">/dev/null" is the redirect. But what's the 2 for? Posted by ^thehatsrule^ on Feb. 16 2007,22:30
2 is used for stderr, without anything defaults to 1 (stdout).You can look up linux file descriptors if you want more info. Posted by mikshaw on Feb. 17 2007,03:45
you'll probably want to fix the PICTURES="$(getbootparam pictures" (add a closing ")" to it) if you haven't already noticed that.
Posted by beakmyn on Feb. 17 2007,11:58
Yep, got it fixed. Thanks for the "file descriptors" without out know what it was it's kinda difficult to search google for 2> to figure out what it is.
|