File: init

package info (click to toggle)
alsadriver 0.2.0-pre8-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 2,808 kB
  • ctags: 6,550
  • sloc: ansic: 43,490; sh: 916; makefile: 759; perl: 54
file content (120 lines) | stat: -rw-r--r-- 2,869 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#
# alsasound     This shell script takes care of starting and stopping
#               ALSA sound driver.
#
# Copyright (c) by Jaroslav Kysela <perex@jcu.cz> 
#
# Slightly modified for Debian GNU/Linux by Wichert Akkerman.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# For RedHat 5.0:
# chkconfig: 2345 87 14
# description: ALSA driver
#

maxcards=8
maxmixers=2

function start() {
  #
  # insert all sound modules
  #
  cat /etc/conf.modules | \
    grep -E "^alias.+snd-card-[[:digit:]]" | \
    awk '{print $3}' | \
    while read line; do \
      echo -n "Starting sound driver: $line "; \
      /sbin/modprobe $line; \
      echo "done."; \
    done
  #
  # restore mixer settings
  #
  idx=0
  while [ $idx -lt $maxcards ]; do
    if [ -d /etc/sound/$idx ] && [ -d /proc/asound/$idx ]; then
      idx1=0
      while [ $idx1 -lt $maxmixers ]; do
        if [ -r /etc/sound/$idx/mixer$idx1 ] && [ -w /proc/asound/$idx/mixer$idx1 ]; then
          cat /etc/sound/$idx/mixer$idx1 > /proc/asound/$idx/mixer$idx1
        fi
        idx1=$[$idx1+1]
      done
    fi
    idx=$[$idx+1]
  done
}

function stop() {
  #
  # save mixer settings
  #
  idx=0
  while [ $idx -lt $maxcards ]; do
    if [ -d /proc/asound/$idx ]; then
      idx1=0
      while [ $idx1 -lt $maxmixers ]; do
        if [ -r /proc/asound/$idx/mixer$idx1 ]; then
          mkdir -p /etc/sound/$idx
          cat /proc/asound/$idx/mixer$idx1 > /etc/sound/$idx/mixer$idx1
        fi
        idx1=$[$idx1+1]
      done
    fi
    idx=$[$idx+1]
  done
  #
  # remove all sound modules
  #
  /sbin/lsmod | grep -E "^snd" | while read line; do \
     /sbin/rmmod `echo $line | cut -d ' ' -f 1`; \
  done
}

# See how we were called.
case "$1" in
  start)
        # Start driver.
	if [ ! -d /proc/asound ]; then
	  start
	else
	  echo "ALSA driver is already running."
	fi
        ;;
  stop)
        # Stop daemons.
	if [ -d /proc/asound ]; then
          echo -n "Shutting down sound driver: "
	  stop
 	  echo "done."
	else
	  echo "ALSA driver isn't running."
	fi
        ;;
  restart)
	$0 stop
	$0 start
	;;
  force-reload)
  	$0 restart
	;;
  *)
        echo "Usage: /etc/init.d/alsa {start|stop|restart}"
        exit 1
esac

exit 0