@george1421 Done. It took digging deeper into BASH scripting, and thinking through what the script was attempting to do, but it finally worked. Notably, the 2-condition test in the ‘if’ statement was giving me grief until I separated it into two double brackets (two single brackets may have worked?). I know there are a dozen ways of doing this, but this worked for me. Also, the ‘$osId’ needed to be ‘$osid’, and the /etc/hostname needed to be in the mounted directory instead of in the FOS environment.
For others wanting to use this, here is the complete script as I adapted it to work, with the debugging elements removed.
#!/bin/bash . /usr/share/fog/lib/funcs.sh [[ -z $postdownpath ]] && postdownpath="/images/postdownloadscripts/" if [[ "$osid" == "50" ]] && [[ ! -z $hostname ]] then [[ ! -d /imagefs ]] && mkdir -p /imagefs mount /dev/sda5 /imagefs echo $hostname > /imagefs/etc/hostname sync umount /imagefs fi
A few more notes for others trying to make something like this work:
- For anyone else having trouble with scripting, the debugging option is a life-saver. I ended up putting a debugPause (preceded by an “echo” or similar output statement) after every line to narrow my problem down.
- It took me longer than it should have to figure out the details of the ‘if’ statements in @george1421’s sample script. The -z checks for a null value (in this case for $hostname the “!” is not, so this is saying if the $hostname variable is not null, then… Here is a good guide on these.
*@george1421 has listed the FOG variables available in FOS (FogOS) here. I didn’t find this in the wiki. In that same thread, he notes a way to get a pile of other variables from the FOG server by running a script.
*For a short primer on the post-install script concept itself, this post and a few others in that thread were the best I found.
Again, @george1421, many, many thanks for your prompt, patient help. I’ve just made a donation to the FOG project in your honor.
If I could have an account for the wiki, I’d be happy to put some of this info together in a tutorial for changing hostname and post-install scripting.
Who marks this as ‘solved’?