Regarding hostname. I believe the problem is that importas is run in a foreground block. The foreground block is executed in a separate fork, which means the variable wont be available after the foreground block.
I.e. $HOSTNAME is always undefined on the last line:
foreground {
if { test -s /etc/hostname } backtick -n HOSTNAME { cat /etc/hostname }
importas -iu HOSTNAME HOSTNAME
}
if -n { test -z $HOSTNAME } sh -c "echo $HOSTNAME >| /proc/sys/kernel/hostname"
I'm new to execline, but played around a bit and this seems to work:
#!/usr/bin/execlineb -P
fdmove -c 2 1
if { echo -- Setting hostname }
ifelse { test -s /etc/hostname } {
backtick -n HOSTNAME { head -n1 /etc/hostname }
importas -iu HOSTNAME HOSTNAME
ifelse -n { test -z $HOSTNAME } { sh -c "echo $HOSTNAME >| /proc/sys/kernel/hostname" }
}
I'm using ifelse to avoid having the script exit with a non-zero value. The "else" clauses are empty here, but one could for example print something:
if { echo -- Setting hostname }
ifelse { test -s /etc/hostname } {
...
}
if { echo -- No (or empty) /etc/hostname file }