Debian Codegraph @

debian/gsm-utils.init

raw
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides: gsm-utils
4 # Required-Start: $remote_fs $syslog
5 # Required-Stop: $remote_fs $syslog
6 # Default-Start: 2 3 4 5
7 # Default-Stop: 0 1 6
8 # Short-Description: Start daemon at boot time
9 # Description: Enable service provided by daemon.
10 ### END INIT INFO
11 #
12 # /etc/init.d/gsm-utils: Controls the GSM SMS send daemon
13 #
14 # written by Matthias Goebl <[email protected]>
15
16 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
17 DAEMON=/usr/bin/gsmsmsd
18 NAME=gsmsmsd
19 DEFAULTFILE=/etc/default/gsm-utils
20 DESC="GSM SMS send daemon"
21
22 test -x $DAEMON || exit 0
23
24 . /lib/lsb/init-functions
25
26 PHONEDEV=/dev/mobilephone # or /dev/ttyS0 or /dev/ircomm0
27 BAUDRATE=9600
28 PIN="" # or 1234
29 SMSPROCESSOR="" # or /usr/bin/gsmsmsprocessor
30 SPOOLDIR=/var/spool/sms
31 PRIORITIES=3
32 STARTOPTS=""
33 SMSUSER="gsmsms:gsmsms"
34 test -r /etc/default/gsm-utils && . /etc/default/gsm-utils # for overwriting some parameters
35
36 if [ "$RUNGSMSMS" != "yes" ];then
37 echo "GSM SMS deamon not yet configured. Edit /etc/default/gsm-utils first."
38 exit 0
39 fi
40
41 OPTIONS="-d $PHONEDEV -b $BAUDRATE -L -P $PRIORITIES"
42 OPTIONS="$OPTIONS -s $SPOOLDIR/queue -S $SPOOLDIR/sent -F $SPOOLDIR/failed"
43 test -n "$SMSPROCESSOR" && OPTIONS="$OPTIONS -a $SMSPROCESSOR"
44 test -n "$SMSUSER" && STARTOPTS="$STARTOPTS --chuid $SMSUSER"
45 test -r /etc/default/gsm-utils && . /etc/default/gsm-utils # for overwriting OPTIONS
46
47 if [ ! -d /run/gsm-utils ] ; then
48 mkdir -p /run/gsm-utils || true
49 if [ -d /run/gsm-utils ] ; then
50 test -n "$SMSUSER" && chown -R gsmsms:gsmsms /run/gsm-utils
51 fi
52 fi
53
54
55 case "$1" in
56 start)
57 echo -n "Starting $DESC: "
58 if [ -n "$PIN" ];then
59 echo -n "entering PIN.. "
60 (
61 # This is ugly.. But if the PIN is already entered, the ME returns
62 # "ERROR" and makes gsmctl retrying..
63 /usr/bin/gsmctl -d $PHONEDEV -b $BAUDRATE -I "+cpin=$PIN" &
64 PID=$!
65 sleep 3
66 kill $PID 2>/dev/null
67 ) >/dev/null 2>&1
68 fi
69 echo -n "$NAME"
70 start-stop-daemon --start --quiet --pidfile /run/gsm-utils/$NAME.pid \
71 --make-pidfile --background $STARTOPTS --exec $DAEMON -- $OPTIONS
72 echo "."
73 ;;
74 stop)
75 echo -n "Stopping $DESC: $NAME "
76 start-stop-daemon --stop --quiet --pidfile /run/gsm-utils/$NAME.pid \
77 --exec $DAEMON
78 sleep 5
79 echo "."
80 ;;
81 restart|force-reload)
82 echo -n "Restarting $DESC: $NAME"
83 start-stop-daemon --stop --quiet --pidfile /run/gsm-utils/$NAME.pid \
84 --make-pidfile --exec $DAEMON -- $OPTIONS
85 sleep 5
86 start-stop-daemon --start --quiet --pidfile /run/gsm-utils/$NAME.pid \
87 --make-pidfile --background $STARTOPTS --exec $DAEMON -- $OPTIONS
88 echo "."
89 ;;
90 *)
91 N=/etc/init.d/gsm-utils
92 echo "Usage: $N {start|stop|restart|force-reload}" >&2
93 exit 1
94 ;;
95 esac
96
97 exit 0