View Single Post
Benson's Avatar
Posts: 4,930 | Thanked: 2,272 times | Joined on Oct 2007
#184
Writing's the hard bit, since you have to figure out what to write...

Make your config file look like:
Code:
IMAGEFILE=/media/mmc2/debian.img
MOUNTPOINT=/debian/
PARAMETER3=value3
PARAMETER4=value4
(That is to say, statements interpretable by the shell, leaving settings in shell variables; you can do actual commands and stuff as well as assignments...)
Then, in your shell script, you include the file with . like so:
Code:
#!/bin/sh
#first read our config file:
. /home/user/.debchrootrc

#now do the real work...
That causes the shell to jump over to .debchrootrc, continue reading and evaluating lines from it, and when it drops out of .debchrootrc, returns to the including script.

For writing, you wind up with something like:
Code:
#...
#By this point, all the actual values have been discovered, guessed, prompted for, or otherwise obtained, and assigned into the correct variables.
echo '#This file auto-generated by qole's debfooconfigurizer script.' > /home/user/.debchrootrc
echo 'IMAGEFILE="'"$IMAGEFILE"'"' > /home/user/.debchrootrc
echo 'MOUNTPOINT="'"$MOUNTPOINT"'"' > /home/user/.debchrootrc
echo 'PARAMETER3="'"$PARAMETER3"'"' > /home/user/.debchrootrc
echo 'PARAMETER4="'"$PARAMETER4"'"' > /home/user/.debchrootrc
 

The Following User Says Thank You to Benson For This Useful Post: