This shows you the differences between two versions of the page.
Next revision | Previous revision Last revision Both sides next revision | ||
packages:userscripts [2011-01-31 04:01] SamChi - very simple description |
packages:userscripts [2011-02-01 20:43] SamChi - no time to waste |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | |||
+ | |||
+ | ====== UserScripts ====== | ||
rc-scripts-user allows users to run scripts at system startup and shutdown. | 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". | Create ~/.config/init.d/script_name. It must accept one argument, it will be either "start" or "stop". | ||
- | Example ~/.config/init.d/irssi | + | |
+ | |||
+ | ====== Sample user scripts ====== | ||
+ | |||
+ | |||
+ | ==== irssi ==== | ||
+ | ~/.config/init.d/irssi | ||
+ | |||
<file>#!/bin/sh | <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 | case "$1" in | ||
start) | start) | ||
+ | [ -p "$REMOTE" ] || install_fifo_remote | ||
+ | |||
if ! pidof irssi > /dev/null; then | if ! pidof irssi > /dev/null; then | ||
screen -d -m -S irssi irssi | screen -d -m -S irssi irssi | ||
Line 14: | Line 47: | ||
;; | ;; | ||
stop) | stop) | ||
- | # assuming someone creates it | + | pidof irssi > /dev/null || exit 0 |
- | irssi_remote /quit | + | |
- | sleep 1 | + | echo "quit System shutdown" > $REMOTE |
- | killall -INT irssi | + | |
+ | 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/2/TERM/6/KILL/2 -s TERM \ | ||
+ | --pidfile $HOME/.dropbox/dropbox.pid | ||
;; | ;; | ||
esac | esac | ||
</file> | </file> | ||