📄 addmodems.sh
字号:
#!/bin/sh5# @(#)addmodems.sh 4.1 ULTRIX 7/2/90## addmodems - configure new modems for uucp and tip## copyright at end of file#STDSIGS="1 2 3 15"trap '' $STDSIGS # Ignore until we setup fault handlercase "`echo -n`" in # handle sh or sh5 echo's"-n") MN= BC='\c' ;; *) MN='-n' BC= ;;esac#DEBUG=y; export DEBUGcase "$DEBUG" iny) MYROOT="/usr/staff1/XXX" ; UULIB=$MYROOT ACUCAP=$MYROOT/acucap ; FILECMD=$MYROOT/file ; TMP=$MYROOT/tmp DEV=$MYROOT/dev ; TTYS=$MYROOT/ttys ; NULL=dev.null REMOTE=$MYROOT/remote ;;*) UULIB=/usr/var/uucp ; ACUCAP=/etc/acucap ; FILECMD=/usr/bin/file TMP=/tmp ; DEV=/dev ; TTYS=/etc/ttys ; NULL=/dev/null REMOTE=/etc/remote ;;esacPATH=:/etc:/usr/ucb:/bin:/usr/bin:$UULIB:MODEMDB=$UULIB/modemdbMDDBTMP=$UULIB/modemdb.tmpTTYDB=$UULIB/ttydbMYNAME=$UULIB/addmodemsLDEVICES=$UULIB/L-devicesDIALUP="dialup"AorD="ACU" #if direct then this changes to DIRDIALERS=`sed -n '/^[a-zA-Z]/s/|.*//p' < $ACUCAP` DIALERS="$DIALERS direct" # direct connect lines ## Pager macro PAGER='eval echo $MN "-- Press RETURN to continue --"$BC; read JUNK'## Fault routinesREPEATORDIE=' echo $MN "Interrupt !!! "$BC while : doecho $MN "Enter \"q\" to quit, or \"c\" to start over [q]: "$BC read buff case "$buff" in "" | q*) rm -f $MDDBTMP exit 5 ;; c) echo "Starting over..." rm -f $MDDBTMP exec $MYNAME $* #NOTREACHED# ;; esac done'IGNORE=':'# Setup fault handlerONINTR=$REPEATORDIEtrap 'eval "$ONINTR"' $STDSIGS## Allowable modem speeds. If there is a modem we don't know about then we## allow any of the speeds under DEFAULTSPEED. The first entry is the default## speed for the given modem type.#### SPEEDS ############# MODEM NAME ######DF02SPEED="300" # df02DF03SPEED="1200 300" # df03DF112SPEED="1200 300" # df112*DF124SPEED="2400 1200" # df124*DF224SPEED="2400 1200" # df224*HAYESSPEED="2400 1200 300" # hayesVENTELSPEED="1200 300" # ventel#DEFAULTSPEED="1200 300 2400" # unknown modem typeDEFAULTSPEED="9600 4800 2400 1200 300 150 19200" # unknown and direct linescd $UULIB## Build database of available terminal special files## This next part is dependent on the new devioctl code and the supporting## user level changes to the file command. If it ain't there ...## the following sed bandaid was necessary due to a last minute change# in the file command. such is life...#$FILECMD $DEV/tty* | sed 's/terminal/junk &/' | awk ' NF >= 9 { if ($8 != "terminal") continue if ($5 == "LAT") continue # skip LAT devices if ($5 ~ /^VCB/) continue # skip QDSS devices term_name = substr($1,6,5) if (term_name == "tty:") continue # skip /dev/tty if (term_name ~ /^ttyd.$/) continue # skip existing dialers cntrl_type = $5 split($6,junk,","); split(junk[1],junk2,"#");cntrl_num = junk2[2] split($9,junk,"#"); cntrl_line = junk[2] if (NF >= 10 && $10 == "modem_control") modemctrl="yes" else modemctrl="no" printf "%-6s %-10s %-2s %-2s %-7s\n", term_name, cntrl_type, cntrl_num, cntrl_line, modemctrl }' > $TTYDB[ ! -s $TTYDB ] && # Check that file exists and is of non-zero length{ echo "There are no available tty lines on your system." exit 1} set ""`wc -l $TTYDB`NTTYLINES="$1" # Number of ttylines available## find valid ttyd? names we can usecd $DEVecho "ttyd0 ttyd1 ttyd2 ttyd3 ttyd4 ttyd5 ttyd6 ttyd7 ttyd8 ttyd9 ttyda ttydb ttydc ttydd ttyde ttydf ttydg ttydh ttydi ttydj ttydk ttydl ttydm ttydn ttydo ttydp ttydq ttydr ttyds ttydt ttydu ttydv ttydw ttydx ttydy ttydz" | tr ' ' '\012' > $TMP/getmodems.tmp1$$ls ttyd? > $TMP/getmodems.tmp2$$ 2>/dev/nullTTYDNAMES=`comm -23 $TMP/getmodems.tmp1$$ $TMP/getmodems.tmp2$$`rm -f $TMP/getmodems.tmp1$$ $TMP/getmodems.tmp2$$cd $UULIB## DEBUG echo "TTYDNAMES --> "$TTYDNAMES[ ! -s $MODEMDB ] && # Make sure the modemdb exists{ echo \"# Modem Datebase - built by uucpsetup## tty cntrl cntrl line modem modem modem out/in old tty# name name number number control type speed shared name#===== ====== ===== ====== ======= ====== ===== ====== =======" \ >> $MODEMDB chown uucp $MODEMDB 2>$NULL chgrp daemon $MODEMDB 2>/$NULL}rm -f $MDDBTMP [ -f $MDDBTMP ] &&{ echo "Can't remove temporary modem database." exit 1}touch $MDDBTMP ||{ echo "Can't create temporary modem database." exit 1}# Set 19 as the maximum number of modems anyone can setup at once[ "$NTTYLINES" -gt 19 ] && NTTYLINES=19 ## Get number of modems to be configuredwhile :do echo $MN "How many modems are you adding to this system [1]? "$BC read NMODEMS case "$NMODEMS" in [0-9]|[1][0-9]) # < 20 is reasonable [ "$NMODEMS" -gt "$NTTYLINES" ] && { echo " " echo "You only have $NTTYLINES tty lines available." echo " " continue } break ;; "") NMODEMS=1 break ;; *) echo " " echo "Please enter a number between 0 and $NTTYLINES." echo " " continue ;; esacdoneecho " "## Build a list of available modemsMODEMHELPTABLE=`echo "The following is a table of modem types you may choose from. Pleasepick a name from the column entitled \"MODEM TYPE\". MODEM TYPE DESCRIPTION---------- -----------"sed -n '/^[a-zA-Z]/s/\([^|:]*\).*|\([^|:]*\):.*/\1 \2/p' < $ACUCAPecho "direct Direct connect tty line (no modem)"echo " "`MODEMHELP='eval echo "$MODEMHELPTABLE"'## Build a list of tty lines and their physical locations to aid the## user in deciding where to place the modems.TTYHELPTABLE=`echo 'The following is a table of tty lines and their physical locations. Picka tty line from the column entitled "TTY LINE". If the word "--More--"is displayed at the bottom of the screen you may press the SPACEBAR to displaythe next page of information or type "q" if you want to stop viewing the table and wish to continue answering the questions.'echo ""echo "TTY LINE CNTRL NAME CNTRL NUMBER LINE NUMBER TYPE OF CONNECTION ALLOWED"awk '{ if ((NR-1) % 4 == 0) print "-------- ---------- ------------ ----------- --------------------------" if ($5 == "yes") connect="shared line support" else connect="incoming or outgoing only" printf "%-8s %-10s %-12s %-12s %-12s\n",$1,$2,$3,$4,connect}' $TTYDBecho " "` # in case user is used to typing SIGINTR to more(1) we temporarily ignore faultsTTYHELP='eval ONINTR="$IGNORE"; echo "$TTYHELPTABLE" | more; ONINTR="$REPEATORDIE"'## Start collecting info on the modemsi=1 while [ $i -le "$NMODEMS" ]do ## Get modem type done=no while : do echo $MN \ 'Enter the MODEM TYPE of modem number '$i', "?" for help: '$BC read MDTYPE case "$MDTYPE" in "") continue ;; "?") $MODEMHELP continue ;; esac # check that modem is a known type echo "$DIALERS" | grep -ws "$MDTYPE" && { # Matched break : }||{ # No match, try again echo " " echo "That modem type is not known." $MODEMHELP continue } done ## Find out where to put modem echo "" while : do echo $MN \ 'Enter the TTY LINE to attach modem number '$i' to, "?" for help: '$BC read MDLINE case "$MDLINE" in "") continue ;; "?") $TTYHELP continue ;; esac # First make sure the line wasen't already specified. # The tty line name is remembered in the 9'th field. BUFF=`awk ' $9 == "'$MDLINE'" {print ; exit}' $MDDBTMP` case "$BUFF" in "") : # ok ;; *) echo "That line has already been used, please try another." continue ;; esac # extract tty record from tty database TTYRECORD=` awk '$1 == "'$MDLINE'" {print ; exit}' $TTYDB` case "$TTYRECORD" in "") echo "There is no tty line by that name, please pick another." continue ;; esac set ""$TTYRECORD case "$#" in # sanity check 5) : # ok ;; *) echo "There is something wrong with the tty database for that line." echo "Please pick another." continue ;; esac ## break out stuff from TTYRECORD MDCTRLTYPE=$2 MDCTRLNUM=$3 MDLINENUM=$4 MDMODEMCTRL=$5 # Remove line from TTYHELP TTYHELPTABLE=`echo "$TTYHELPTABLE" | grep -wv "$MDLINE"` break done ## What speed will modem run at echo "" case "$MDTYPE" in df02) SPEEDS="$DF02SPEED" ;; df03) SPEEDS="$DF03SPEED" ;; df112*) SPEEDS="$DF112SPEED" ;; df124*) SPEEDS="$DF124SPEED" ;; df224*) SPEEDS="$DF224SPEED" ;; hayes) SPEEDS="$HAYESSPEED" ;; hayes-p) SPEEDS="HAYESSPEED" ;; ventel) SPEEDS="$VENTELSPEED" ;; *) SPEEDS="$DEFAULTSPEED" ;; esac set ""$SPEEDS while : do echo $MN "Enter the SPEED (baud rate) modem $i runs at, "'"?" for help.'" [$1]: "$BC read MDSPEED case "$MDSPEED" in "?") echo " " echo "Valid SPEEDS are: $SPEEDS" echo " " continue ;; "") MDSPEED=$1 ;; esac echo "$SPEEDS" | grep -ws $MDSPEED && { break # was a valid speed : }||{ echo "That is not a valid speed for MODEM TYPE \"$MDTYPE\""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -