updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / aldm / aldm
blob87c313593dda11e848620ea71390e5c39af410d2
1 #!/bin/bash
2 #ArchLinux Daemon Manager
4 if [ $(whoami) != "root" ]; then
5 echo 'You have to be root ;-P'
6 exit;
7 fi;
9 rc_conf='/etc/rc.conf';
10 rc_d='/etc/rc.d';
12 . "$rc_conf";
14 S=$(echo "$2" | grep -o '[^!#@]*'); #remove flags
16 list() {
17 echo "${DAEMONS[*]}" | tr ' ' "\n";
20 update_conf() {
21 NEW="DAEMONS=(${DAEMONS[*]})";
22 echo "$NEW";
24 CONF="$(cat $rc_conf)"
25 echo "$CONF" | sed -ne '1h;1!H;${;g;s/DAEMONS=([^)]*)/'"$NEW"'/g;p;}' > "$rc_conf";
28 case "$1" in
29 list)
30 list;
32 whatis)
33 if [ "$S" != '' ]; then
34 ls -1 /var/run/daemons/ | grep ^"$S"$ >/dev/null 2>&1
35 if [ $? == 0 ]; then echo -n 'running'; else echo -n 'stopped'; fi
36 whatis -l -L C "$S" | grep -o -e ' - \(.*\)$' | cut -d '-' -f 2-
37 exit;
38 fi;
40 ls -1 "$rc_d" | while read i; do
41 whatis -l -L C "$i";
42 done;
44 enable-fg)
45 DAEMONS=($(list | sed "s/^\(!\|@\)$S$/$S/"));
46 update_conf;
48 enable-bg)
49 DAEMONS=($(list | sed "s/^!\?$S$/@$S/"));
50 update_conf;
52 disable)
53 DAEMONS=($(list | sed "s/^@\?$S$/!$S/"));
54 update_conf;
56 start|stop|restart)
57 "$rc_d/$S" "$1";
60 echo "usage: $0 {list|whatis|enable-fg|enable-bg|disable|start|stop|restart} [service name]
62 Note that only daemons specified in $rc_conf can be manipulated - you must add them manually."
63 esac