the Missing M
Group: Members
Posts: 35
Joined: Mar. 2007 |
|
Posted: May 11 2007,03:11 |
|
Well it's clunky, but it works. I'm probably unduly proud of it, because this is my first attempt at a `structured' sh script. Anything before that was just a simple list of commands, which could just as easily be typed into a terminal. Of course, they have saved me the trouble of typing those same lines over and over again.
My main reason for writing it was to perform a few basic actions as root, without getting hassled for a password every time. Not really an issue in DSL, at least not from the live CD.
You don't necessarily need to have the referenced apps installed, but it might come in handy for automating other things you'd like to automate, whether they require root privs or not. That's why I'm posting it here. Oh, and because I'm unduly proud of it. ;-)
Code Sample | #!/bin/sh
echo Starting r00t_l00p...
# This script adds some super-user functionality to regular # old Wendy Whitebread accounts. # # What it does is check for certain directory names in /tmp, # then acts on whatever it finds there. So other programs, and # the user, can communicate with it via `mkdir' or a launcher # button that runs a simple `mikdir /tmp/r00t/foo' command.
mkdir -p /tmp/r00t/run chmod -R 777 /tmp/r00t sleep 11 rm -rf /tmp/r00t/run # # If the `run' folder exists, this indicates that a r00t script # has just been started, and other instances should quit now. # # Avoids multiple instances piling up from one login to the next.
while : do if [ -x /tmp/r00t/run ] then echo Ending r00t_l00p. exit 0 # What did I just say?
elif [ -x /tmp/r00t/shutdown ] #### Unused, but I might need these sometime... then rm -rf /tmp/r00t/shutdown killall sleep sudo -u moi xmms -s sleep 2 shutdown -P now "Thassal, Folks!"
elif [ -x /tmp/r00t/reboot ] then rm -rf /tmp/r00t/reboot killall sleep sudo -u moi xmms -s sleep 2 shutdown -r now "Back in a bit..."
elif [ -x /tmp/r00t/hibernate ] #### But I do need this, because the standard #### `Hibernate' button never works in Xubuntu... then rm -rf /tmp/r00t/hibernate sudo -u moi xmms -s sleep 1 umount /dev/sda1
/etc/acpi/hibernate.sh # # Requires the addition of an `&' in # /etc/acpi/hibernate.sh # # Here, on the last line; # . /etc/acpi/resume.sh & # # Otherwise, the hibernate script will just sit there # and wait, long after it's finished its work, and so # will r00t_l00p; waiting for hibernate.sh to exit.
# And on resume; # sudo -u moi mount /dev/sda1 mount /dev/sda1 sleep 7 sudo -u moi xmms -p
elif [ -x /tmp/r00t/insomnia ] #### Makes `sleep'-deferred actions happen now #### In other words; `Procrastinate Later'. then rm -rf /tmp/r00t/insomnia killall sleep
elif [ -x /tmp/r00t/ftp-stat ] #### Server status then rm -rf /tmp/r00t/ftp-stat
if [ -x /tmp/r00t/ftp-on ] then xterm -title '::0N::' \ -geometry 28x3 -e 'echo && echo \ " FTP Server is ON." && echo -n \ " " && sleep 3' & # # Woohoo! GUI notification dialogs # from a shell script!
elif [ -x /tmp/r00t/ftp-off ] then xterm -title '::0FF::' \ -geometry 28x3 -e 'echo && echo \ " FTP Server is OFF." && echo -n \ " " && sleep 3' &
# " [press any key to " && echo -n \ # " close window] " && read -n 1' &
fi
elif [ -x /tmp/r00t/ftp-switch ] #### Turn the server on or off then rm -rf /tmp/r00t/ftp-switch
if [ -x /tmp/r00t/ftp-on ] #### If it's on, stop it then xterm -title '::0FF::' \ -geometry 28x3 -e 'echo && echo \ " Stopping FTP Server." && echo -n \ " " && sleep 3' &
mv /tmp/r00t/ftp-on /tmp/r00t/ftp-off
/etc/init.d/proftpd stop /etc/init.d/proftpd force-stop sleep 3 killall -s 9 proftpd
elif [ -x /tmp/r00t/ftp-off ] #### If it's off, start it then xterm -title '::0N::' \ -geometry 28x3 -e 'echo && echo \ " Starting FTP Server." && echo -n \ " " && sleep 3' &
mv /tmp/r00t/ftp-off /tmp/r00t/ftp-on
/etc/init.d/proftpd start
elif [ -x /tmp/r00t ] #### And if you don't know, stop it anyway then mkdir -p /tmp/r00t/ftp-off
/etc/init.d/proftpd stop /etc/init.d/proftpd force-stop sleep 3 killall -s 9 proftpd fi fi
sleep 3 done |
Probably insecure as hell, because it does rely on a world-writable directory to take instructions, but that's fine with me because the only remote file access I've got going is FTP, and even that is usually turned off [does come in handy though, for transferring files between a Mac, PC and my currently favourite Linux box]. Besides, it's all sitting behind a router.
However, since this is a laptop, I do want to be sure the FTP daemon's really, truly and completely shut down when I head out to an internet cafe or something.
Blah, foo, bar, etc [and please excuse another long post],
Patrick.
-------------- Q: What is the difference between a joke, and a lie? A: A lie tends to obscure the truth, while a joke often reveals it.
|