Check my upstart script code?

John Hupp ubuntu at prpcompany.com
Sat May 9 20:47:07 UTC 2015


On 5/9/2015 11:20 AM, John Hupp wrote:
> Here is the script code from an upstart job I'm trying to get working 
> (but which doesn't work yet):
>
>     # test for a fat client:
>     if [[ $(hostname | grep 'ltsp') == ltsp* ]]; then
>         sed 's/mount_removable=0/mount_removable=1/' 
> <~/.config/pcmanfm/lubuntu/pcmanfm.conf 
> >~/.config/pcmanfm/lubuntu/pcmanfm.conf
>     # test for a thin client:
>     elif [ -n "$LTSP_CLIENT" ]; then
>         sed 's/mount_removable=1/mount_removable=0/' 
> <~/.config/pcmanfm/lubuntu/pcmanfm.conf 
> >~/.config/pcmanfm/lubuntu/pcmanfm.conf
>     # machine must be the server
>     else
>         sed 's/mount_removable=0/mount_removable=1/' 
> <~/.config/pcmanfm/lubuntu/pcmanfm.conf 
> >~/.config/pcmanfm/lubuntu/pcmanfm.conf
>     fi
>
> Assuming that it was tripping on ~, I also tried:
>
>     # test for a fat client:
>     if [[ $(hostname | grep 'ltsp') == ltsp* ]]; then
>         sed 's/mount_removable=0/mount_removable=1/' 
> <$HOME/.config/pcmanfm/lubuntu/pcmanfm.conf 
> >$HOME/.config/pcmanfm/lubuntu/pcmanfm.conf
>     # test for a thin client:
>     elif [ -n "$LTSP_CLIENT" ]; then
>         sed 's/mount_removable=1/mount_removable=0/' 
> <$HOME/.config/pcmanfm/lubuntu/pcmanfm.conf 
> >$HOME/.config/pcmanfm/lubuntu/pcmanfm.conf
>     # machine must be the server
>     else
>         sed 's/mount_removable=0/mount_removable=1/' 
> <$HOME/.config/pcmanfm/lubuntu/pcmanfm.conf 
> >$HOME/.config/pcmanfm/lubuntu/pcmanfm.conf
>     fi
>
> I'm guessing that my file identification strings need fixing up, but 
> I'm such a poor scripter that this could only be one of several mistakes.
>
> Check my homework?

Here is an improved upstart job (/etc/init/pcmanfm-ltsp.conf).  The 
script code is tested as working when run manually as a script, but it 
was not effective as an upstart job.  Perhaps environment variables like 
$HOME are not available to upstart jobs even though this one doesn't run 
until after the desktop session has started and $HOME should be defined 
at that point.

But given that the code works as a script, I can probably get what I 
want by setting that up with a desktop shortcut in an autostarting location.

# Edit pcmanfm Volume Management preferences at startup
#
# Set prefs based on whether the machine is a thin client or a 
server/fat client

description "Edit pcmanfm Volume Management preferences based on machine 
type"

start on desktop-session-start

script
# test for a fat client:
if [[ $(hostname | grep 'ltsp') == ltsp* ]]; then
     sed -i 's/mount_removable=0/mount_removable=1/' 
"$HOME/.config/pcmanfm/lubuntu/pcmanfm.conf"
# test for a thin client:
elif [ -n "$LTSP_CLIENT" ]; then
     sed -i 's/mount_removable=0/mount_removable=0/' 
"$HOME/.config/pcmanfm/lubuntu/pcmanfm.conf"
# machine must be the server
else
     sed -i 's/mount_removable=0/mount_removable=1/' 
"$HOME/.config/pcmanfm/lubuntu/pcmanfm.conf"
fi
end script



More information about the ubuntu-users mailing list