File: rc.serial

package info (click to toggle)
setserial 2.17-52
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 776 kB
  • sloc: sh: 2,127; ansic: 1,008; makefile: 150; csh: 2
file content (195 lines) | stat: -rwxr-xr-x 5,214 bytes parent folder | download | duplicates (2)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#! /bin/sh
# /etc/rc.serial 
#	Initializes the serial ports on your system
### BEGIN INIT INFO
# Provides:		setserial
# Required-Start:	$remote_fs
# Required-Stop:	$remote_fs
# Default-Start:	S
# Default-Stop:		0 1 6
# Short-Description:	controls configuration of serial ports
# Description:		Set and/or report the configuration information
#			associated with a serial port. This information
#			includes what I/O port and which IRQ a particular
#			serial port is using.
### END INIT INFO
# chkconfig: 2345 50 75
# description: This initializes the settings of the serial port
#
# Distributed with setserial version 2.15
# 
# XXXX note: as of 2.15, the autosave feature doesn't work if you are
# using the multiport feature; it doesn't save the multiport configuration
# (for now).  Autosave also doesn't work for the hayes devices.  
#Will fix later...
#
#
# Note that this has been changed so that if /etc/serial.conf exists,
# this script does not configure the ports. It uses
# /var/lib/setserial/autoserial.conf # instead, which is handled by another
# init.d script. However, the script is still used for module loads and
# unloads, even if serial.conf exists.
#

# added due to request of linitian
. /lib/lsb/init-functions

SETSERIAL=/bin/setserial
modconf=/var/run/setserial.conf
autoconfig=/var/lib/setserial/autoserial.conf
etcconfig=/etc/serial.conf

# If the serial executable has been removed abort the configuration
[ -x ${SETSERIAL} ] || exit 0

#
# make sure that a serial device is loaded...
# insmod -k serial 2>/dev/null
#

#
# Support devfs when it arrives.
#
if /bin/ls /dev/tts 2> /dev/null 1>&2 ; then
	ALLDEVS="/dev/tts/*"
else
	# No devfs - old naming scheme
	ALLDEVS="/dev/ttyS?"
	if /bin/ls /dev/ttyS?? 2> /dev/null 1>&2 ; then
		ALLDEVS="$ALLDEVS /dev/ttyS??"
	fi
fi

#
# Handle System V init conventions...
#
case $1 in
start | restart | force-reload )
	action="start";
	[ -f ${etcconfig} ] && exit 0
	;;
stop)
	action="stop";
	[ -f ${etcconfig} ] && exit 0
	;;
status)
	action="status";
	;;
modload)
	action="modload";
	;;
modsave)
	action="modsave";
	;;
*)
	action="start";
	[ -f ${etcconfig} ] && exit 0
esac

if test $action  = modload ; then
  echo "Restoring persistent state of serial.o module due to module reload... "
  if test -f ${modconf} ; then
        while read device args
        do
               case "$device" in
                   ""|\#*)
                       continue
                       ;;
               esac
           ${SETSERIAL} -z $device $args
        done < ${modconf}
  else
    echo "Warning - no module state found (ok if this is at bootup)"
    echo "Using the bootup configuration instead."
    action="start";
  fi
  exit 0
fi

if test $action  = stop ; then
	if [ -e ${etcconfig} ]; then
		#nothing to do
		dummy=0;
	elif test "`sed 1q $autoconfig`X" = "###AUTOSAVE###X" ; then
		echo -n "Saving state of known serial devices... "
		grep "^#" $autoconfig > ${autoconfig}.new
		${SETSERIAL} -G -g ${ALLDEVS} | grep -v "uart unknown\|pcmcia" >> ${autoconfig}.new
		echo -n "backing up $autoconfig"
		mv $autoconfig ${autoconfig}.old
		mv ${autoconfig}.new $autoconfig
		echo " done."
	elif test "`sed 1q $autoconfig`X" = "###AUTOSAVE-FULL###X" ; then
		echo -n "Saving state (including unknowns) of serial devices... "
		grep "^#" $autoconfig > ${autoconfig}.new
		${SETSERIAL} -G -g ${ALLDEVS} | grep -v "pcmcia" >> ${autoconfig}.new
		echo -n "backing up $autoconfig"
		mv $autoconfig ${autoconfig}.old
		mv ${autoconfig}.new $autoconfig
		echo " done."
	elif test "`sed 1q $autoconfig`X" = "###AUTOSAVE-ONCE###X" ; then
		echo -n "Saving state of known serial devices... "
		echo "###PORT STATE GENERATED USING AUTOSAVE-ONCE###" > ${autoconfig}.new
		grep "^#" $autoconfig >> ${autoconfig}.new
		${SETSERIAL} -G -g ${ALLDEVS} | grep -v "uart unknown\|pcmcia" >> ${autoconfig}.new
		echo -n "backing up $autoconfig"
		mv $autoconfig ${autoconfig}.old
		mv ${autoconfig}.new $autoconfig
		echo " done."
	fi
	exit 0
fi

#
# Is it Start
#

if test $action  = start ; then
  outmsg=""
  echo "Loading the saved-state of the serial devices... "
  rm -f ${modconf}

  if test -f $etcconfig ; then
    readfrom=$etcconfig;
  else
    readfrom=$autoconfig;
  fi
  if test -f $readfrom ; then
        while read device args
        do
               case "$device" in
                  "#KERNEL")
                       outmsg="... handled by kernel"
                       continue
                       ;;
                   ""|\#*)
                       continue
                       ;;
               esac
           outmsg=""
           ${SETSERIAL} -z $device $args
           ${SETSERIAL} -bg $device
        done < $readfrom
        if test ! "$outmsg" = "" ; then
          echo $outmsg
        fi

  else
	echo "###AUTOSAVE###" > $autoconfig
  fi
fi

if test $action  = modsave ; then
	echo -n "Saving serial.o state to emulate module data persistence... "
	rm -f ${modconf}
	${SETSERIAL} -G -g ${ALLDEVS} | grep -v "uart unknown\|pcmcia" > ${modconf}
	echo "done."
	exit 0
fi

if test $action  = status ; then
	echo "Status of serial devices: ${ALLDEVS}"
       for d in ${ALLDEVS}; do
	  ${SETSERIAL} -a ${d}
       done
	exit 0
fi