~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/sl-modem-daemon

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
### BEGIN INIT INFO
 
4
# Provides:          softmodem sl-modem-daemon
 
5
# Default-Start:     2 3 4 5
 
6
# Default-Stop:      0 1 6
 
7
# Required-Start:    $local_fs $remote_fs
 
8
# Required-Stop:     $local_fs $remote_fs
 
9
# Short-Description: Setup the SmartLink modem daemon
 
10
# Description:       Starts the modem daemon emulating a serial device and
 
11
#                    links the result to /dev/modem.
 
12
### END INIT INFO
 
13
 
 
14
 
 
15
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
16
DAEMON=/usr/sbin/slmodemd
 
17
NAME=slmodemd
 
18
PIDFILE=/var/run/$NAME.pid
 
19
DESC="SmartLink modem daemon"
 
20
modprobe="$(cat /proc/sys/kernel/modprobe 2>/dev/null || echo modprobe)"
 
21
 
 
22
. /lib/lsb/init-functions
 
23
 
 
24
test -x $DAEMON || exit 0
 
25
 
 
26
# there may be old options there...
 
27
test -r /etc/default/slmodemd && . /etc/default/slmodemd
 
28
 
 
29
# but most likely they are here
 
30
test -r /etc/default/sl-modem-daemon && . /etc/default/sl-modem-daemon
 
31
 
 
32
ALSADEVPREFIX=modem
 
33
driverlist="snd-intel8x0m snd-via82xx-modem snd-atiixp-modem"
 
34
 
 
35
# must match the names in /proc/modules with the underscores etc., includes slamr too
 
36
unloadllist="snd_intel8x0m snd_via82xx_modem snd_atiixp_modem slamr"
 
37
 
 
38
alsaload() {
 
39
 
 
40
    unset aplay_grep_line;
 
41
    unset proc_grep;
 
42
 
 
43
    # first check for situation when there is modem subdevice (aplay -l output have "(M|m)odem" string, and /proc/asound/cards doesn't).
 
44
    # this one doesn't need modprobe (modem is part of sound card chip)
 
45
 
 
46
    if ! proc_grep=$(grep -i "\[Modem   " /proc/asound/cards) ; then
 
47
    # if there is aplay output, get card and device numbers and form SLMODEMD_DEVICE as hw:a,b
 
48
        if aplay_grep=$(LC_ALL=C aplay -l | egrep '^card [0-9].*(M|m)odem') ; then
 
49
            aplay_grep_line=$(echo "$aplay_grep" | sed -r 's/^card ([[:digit:]]+).*device ([[:digit:]]+).*$/\1 \2/')
 
50
 
 
51
            # Let's configure subdevice
 
52
            if [ -n "$aplay_grep_line" ] ; then
 
53
                set $aplay_grep_line
 
54
                # This one needs hw as prefix
 
55
                ALSADEVPREFIX="hw"
 
56
                SLMODEMD_DEVICE="$ALSADEVPREFIX:$1,$2"
 
57
                ALSA=yes
 
58
                return 0
 
59
            fi
 
60
       # if there is no aplay and proc output, try to modprobe and then check for modem cards again
 
61
        else
 
62
            # first check to not do unneccessary modprobe calls. Some people even put
 
63
            # it into the kernel image
 
64
 
 
65
            for x in $driverlist ; do $modprobe $x 2>/dev/null ; done
 
66
 
 
67
            for start_reps in `seq 100` ; do
 
68
                test -e /proc/asound/cards && proc_grep=$(grep -i "\[Modem   " -i /proc/asound/cards) && (LC_ALL=C aplay -l | egrep '^card [0-9]*\: Modem ' >/dev/null) && break
 
69
                sleep 0.1
 
70
            done
 
71
 
 
72
        fi
 
73
    fi
 
74
        
 
75
    # if we got proc_grep (already existed or from previous if), let's use it to form SLMODEMD_DEVICE as modem:a
 
76
    if [ -n "$proc_grep" ] ; then
 
77
        # ALSA driver is loaded, use it
 
78
        set $proc_grep
 
79
        SLMODEMD_DEVICE=$ALSADEVPREFIX:$1
 
80
        ALSA=yes
 
81
        return 0
 
82
    fi
 
83
 
 
84
    return 1
 
85
}
 
86
 
 
87
config() {
 
88
   if test "$DONTSTART" = 1 ; then
 
89
      test "$BEQUIET" = 1 || echo "Not starting $DESC (options not set in /etc/default/slmodemd)"
 
90
      exit 0
 
91
   fi
 
92
 
 
93
   if test "$SLMODEMD_COUNTRY" ; then
 
94
      OPTS="$OPTS -c $SLMODEMD_COUNTRY"
 
95
   fi
 
96
 
 
97
   ALSA=`echo $SLMODEMD_DEVICE | grep :`
 
98
   
 
99
   if [ "`echo $SLMODEMD_DEVICE | grep auto`" ] ; then
 
100
 
 
101
       # carefully look for signs of loaded drivers
 
102
       if grep -i "\[Modem   " -i /proc/asound/cards ; then
 
103
           # already loaded, just pick up the device there
 
104
           alsaload;
 
105
       else
 
106
           # ALSA not loaded yet, try the smartlink driver first, then try ALSA
 
107
           # though (forced loading)
 
108
           if grep -q 'slamr\..*o' /lib/modules/`uname -r`/modules.dep ;
 
109
           then
 
110
               if $modprobe slamr 2>&1 | grep -q not.found ; then
 
111
                   alsaload;
 
112
               else
 
113
                   SLMODEMD_DEVICE=slamr0
 
114
               fi
 
115
           else
 
116
               alsaload;
 
117
           fi
 
118
       fi
 
119
   fi
 
120
 
 
121
   if [ "$ALSA" ] ; then
 
122
       # either detected or choosed by user, the driver must already be loaded
 
123
       # and the device name be picked up before
 
124
 
 
125
       OPTS=" --alsa $OPTS $SLMODEMD_DEVICE"
 
126
 
 
127
   else
 
128
 
 
129
      if test "$SLMODEMD_DEVICE" ; then
 
130
         OPTS="$OPTS /dev/$SLMODEMD_DEVICE"
 
131
      fi
 
132
      
 
133
      if uname -a | grep -q x86_64 ; then
 
134
         echo "Only access through ALSA is available on amd64 but slamr driver was chosen!"
 
135
         echo "Make sure that an ALSA driver for your chipset is available and is loaded"
 
136
         echo "and that access to SmartLink modem components is supported by it."
 
137
         exit 1
 
138
      fi
 
139
 
 
140
      # installed as module so just load it or bail out
 
141
      if MODPROBE_OPTIONS="" $modprobe slamr 2>&1 | grep -q not.found ; then
 
142
          echo "SmartLink modem driver not available for this Kernel. Please read README.Debian"
 
143
          echo "or try to install the package sl-modem-dkms. Exiting..."
 
144
          exit 1
 
145
      fi
 
146
   fi
 
147
}
 
148
 
 
149
start() {
 
150
 
 
151
    echo -n "Starting SmartLink Modem driver for: $SLMODEMD_DEVICE"
 
152
    ulimit -Hl unlimited; ulimit -Sl unlimited
 
153
    start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON --make-pidfile --background --quiet -- $OPTS
 
154
    RETVAL=$?
 
155
    if [ "$RETVAL" = 0 ] && [ "$NOSYMLINK" != 1 ] ; then
 
156
        echo "."
 
157
        echo "Creating /dev/modem symlink, pointing to: /dev/ttySL0."
 
158
        ln -sf ttySL0 /dev/modem
 
159
    fi
 
160
}
 
161
 
 
162
stop() {
 
163
    echo -n "Shutting down SmartLink Modem driver normally"
 
164
    RETVAL=0
 
165
    if [ "`pidof $NAME`" ] ; then 
 
166
        if start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON --retry 1 ; then
 
167
            echo .
 
168
        else
 
169
            echo " probably failed."
 
170
            echo "Trying it the hard way (send SIGKILL all $NAME processes): " 
 
171
            killall -KILL $NAME || RETVAL=1
 
172
        fi
 
173
    else
 
174
        echo " ... no $NAME daemon running."
 
175
    fi
 
176
    test "$RETVAL" -ne 0 || rm -f "$PIDFILE"
 
177
    echo -n "Unloading modem driver from kernel ... " 
 
178
    msg="none found."
 
179
    for x in $unloadllist ; do 
 
180
        if grep -l -q "^$x " /proc/modules ; then
 
181
            $modprobe -r $x 2>/dev/null && msg="$x." || msg="failed."
 
182
        fi
 
183
    done
 
184
    echo $msg
 
185
}
 
186
 
 
187
status() {
 
188
    echo -n "Status of $DESC: "
 
189
    if [ ! -r "$PIDFILE" ]; then
 
190
        echo "$NAME is not running."
 
191
        exit 3
 
192
    fi
 
193
    if read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
 
194
        echo "$NAME is running."
 
195
        exit 0
 
196
    else
 
197
        echo "$NAME is not running but $PIDFILE exists."
 
198
        exit 1
 
199
    fi
 
200
}
 
201
 
 
202
# See how we were called. Consider udev action too.
 
203
case "$1$ACTION" in
 
204
    
 
205
    start)
 
206
    config
 
207
    start
 
208
    ;;
 
209
 
 
210
    add)
 
211
    ALSA=""
 
212
    # slusb via udev part
 
213
    if [ "$DEVICE" ] ; then 
 
214
       SLMODEMD_DEVICE="$DEVICE"
 
215
    else
 
216
       SLMODEMD_DEVICE="$DEVNAME"
 
217
    fi
 
218
 
 
219
    if [ -r "$SLMODEMD_DEVICE" ]
 
220
    then
 
221
       # check if $GROUP really exists
 
222
       if getent group $GROUP > /dev/null; then
 
223
          chmod 660 "$SLMODEMD_DEVICE"
 
224
          chown root:$GROUP "$SLMODEMD_DEVICE"
 
225
       fi
 
226
    else
 
227
       exit 1
 
228
    fi
 
229
    start
 
230
    ;;
 
231
 
 
232
    stop|remove)
 
233
    stop
 
234
    ;;
 
235
    
 
236
    restart|reload|force-reload)
 
237
    stop
 
238
    config
 
239
    start
 
240
    ;;
 
241
    
 
242
    status)
 
243
    status
 
244
    ;;
 
245
 
 
246
    *)
 
247
    echo "Usage: /etc/init.d/sl-modem-daemon {start|stop|restart|status}"
 
248
    exit 1
 
249
esac
 
250