File: rc.serial

package info (click to toggle)
setserial 2.17-24
  • links: PTS
  • area: main
  • in suites: woody
  • size: 412 kB
  • ctags: 190
  • sloc: sh: 2,727; ansic: 993; makefile: 123; csh: 2
file content (141 lines) | stat: -rwxr-xr-x 3,797 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#! /bin/sh
# /etc/rc.serial 
#	Initializes the serial ports on your system
#
# 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...
#
#

SETSERIAL=/bin/setserial
modconf=/var/run/setserial.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";
	;;
stop)
	action="stop";
	;;
modload)
	action="modload";
	;;
modsave)
	action="modsave";
	;;
*)
	action="start";
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 test "`head -1 /etc/serial.conf`X" = "###AUTOSAVE###X" ; then
		echo -n "Saving state of known serial devices... "
		grep "^#" /etc/serial.conf > /etc/.serial.conf.new
		${SETSERIAL} -G -g ${ALLDEVS} | grep -v "uart unknown\|pcmcia" >> /etc/.serial.conf.new
		echo -n "backing up serial.conf"
		mv /etc/serial.conf /etc/.serial.conf.old
		mv /etc/.serial.conf.new /etc/serial.conf
		echo " done."
	elif test "`head -1 /etc/serial.conf`X" = "###AUTOSAVE-FULL###X" ; then
		echo -n "Saving state (including unknowns) of serial devices... "
		grep "^#" /etc/serial.conf > /etc/.serial.conf.new
		${SETSERIAL} -G -g ${ALLDEVS} | grep -v "pcmcia" >> /etc/.serial.conf.new
		echo -n "backing up serial.conf"
		mv /etc/serial.conf /etc/.serial.conf.old
		mv /etc/.serial.conf.new /etc/serial.conf
		echo " done."
	elif test "`head -1 /etc/serial.conf`X" = "###AUTOSAVE-ONCE###X" ; then
		echo -n "Saving state of known serial devices... "
		echo "###PORT STATE GENERATED USING AUTOSAVE-ONCE###" > /etc/.serial.conf.new
		grep "^#" /etc/serial.conf >> /etc/.serial.conf.new
		${SETSERIAL} -G -g ${ALLDEVS} | grep -v "uart unknown" >> /etc/.serial.conf.new
		echo -n "backing up serial.conf"
		mv /etc/serial.conf /etc/.serial.conf.old
		mv /etc/.serial.conf.new /etc/serial.conf
		echo " done."
	fi
	exit 0
fi

#
# Is it Start
#

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

  if test -f /etc/serial.conf ; then
        while read device args
        do
               case "$device" in
                   ""|\#*)
                       continue
                       ;;
               esac
           ${SETSERIAL} -z $device $args
           ${SETSERIAL} -bg $device
        done < /etc/serial.conf
  else
	echo "###AUTOSAVE###" > /etc/serial.conf
  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