This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
packages:userscripts [2011-02-01 19:23] SamChi - added dropbox example |
packages:userscripts [2011-02-02 21:37] SamChi - note about restart and reload |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | |||
- | |||
- | ====== UserScripts ====== | ||
- | rc-scripts-user allows users to run scripts at system startup and shutdown. | ||
- | |||
- | |||
- | |||
- | ===== how to use ===== | ||
- | Create ~/.config/init.d/script_name. It must accept one argument, it will be either "start" or "stop". | ||
- | |||
- | |||
- | |||
- | ====== Sample user scripts ====== | ||
- | |||
- | |||
- | ==== irssi ==== | ||
- | ~/.config/init.d/irssi | ||
- | |||
- | |||
- | |||
- | <file>#!/bin/sh | ||
- | |||
- | # TODO: replace pidof with something that takes into account | ||
- | # only processes from this user | ||
- | |||
- | # download fifo_remote.pl irssi script to control it remotelly | ||
- | REMOTE="$HOME/.irssi/remote-control" | ||
- | install_fifo_remote() | ||
- | { | ||
- | install -d ~/.irssi/scripts/autorun | ||
- | cd ~/.irssi/scripts | ||
- | wget http://ep09.pld-linux.org/~sparky/fifo_remote.pl | ||
- | cd autorun | ||
- | ln -s ../fifo_remote.pl . | ||
- | rm $REMOTE | ||
- | mkfifo $REMOTE | ||
- | chmod 600 $REMOTE | ||
- | } | ||
- | |||
- | case "$1" in | ||
- | start) | ||
- | [ -p "$REMOTE" ] || install_fifo_remote | ||
- | |||
- | if ! pidof irssi > /dev/null; then | ||
- | screen -d -m -S irssi irssi | ||
- | fi | ||
- | ;; | ||
- | stop) | ||
- | pidof irssi > /dev/null || exit 0 | ||
- | |||
- | echo "quit System shutdown" > $REMOTE | ||
- | |||
- | usleep 10000 | ||
- | if pidof irssi > /dev/null; then | ||
- | sleep 1 | ||
- | killall -INT irssi | ||
- | fi | ||
- | ;; | ||
- | install) | ||
- | install_fifo_remote | ||
- | ;; | ||
- | esac | ||
- | </file> | ||
- | |||
- | |||
- | ==== dropbox ==== | ||
- | ~/.config/init.d/dropbox | ||
- | |||
- | |||
- | |||
- | <file>#!/bin/sh | ||
- | |||
- | case "$1" in | ||
- | start) | ||
- | exec /sbin/start-stop-daemon --start --background \ | ||
- | --pidfile $HOME/.dropbox/dropbox.pid \ | ||
- | --exec /usr/bin/dropboxd | ||
- | ;; | ||
- | stop) | ||
- | exec /sbin/start-stop-daemon --stop \ | ||
- | --retry TERM/10/TERM/60/KILL/10 -s TERM \ | ||
- | --pidfile $HOME/.dropbox/dropbox.pid | ||
- | ;; | ||
- | esac | ||
- | </file> | ||