📄 setld.orig
字号:
#!/bin/sh# SCCSID %W% (ULTRIX) %G%## setld.sh# load, unload, and inventory software subsets.## 000 ccb 12-mar-1987# Digital Equipment Corporation# Many thanks to robin, rnf, and afd# new version for 2.2## 001 ccb 02-mar-1988# Set UMASK to 22 so that ris can read the images.## 002 06-APR-1988 ccb# Fix DEVICE parsing bug.# A NOTE ABOUT CODING STYLE AND CONVENTIONS.## setld uses a few features of the shell that my not be immediately# obvious to persons not heavily involved in shell use and# maintenance.## {} curly braces for statement grouping. statements in# curlies are treated as single statements in compound# statements.# || logical or. throughout the code, this is used to mean# 'execute the second if the first fails'. The cheif burden# of command error checking and recovery falls to the# use of this construct.# && logical and. used to mean execute the second if the first# succeeds. These bind more tightly ( have higher precedence )# than '||' so: false && echo false || echo true# will cause 'true' to be printed.# : no op, always true. "while :" in shell is the same as# for(;;) in 'C'# [ the 'test' command. used in [ stuff ] && command constructs# as a one-branched 'if'.## IFS internal feild separator. twiddled to speed parsing.[ -t 1 ] && stty -tabsPATH=:/install.tmp:/etc:/bin:/usr/bin:/usr/adm/bin:/usr/ucbexport PATHSTAT=1PROG=$0DIFS="$IFS"DATE=`date +19%y.%m.%T`HT=" "NL=""# let's get verbosity from tar?VBSE=case "$-" in*x*) VBSE=v echo VERBOSITY ON!esac# mag tape record skipT_0=3CURVOL=1# dummy some pathnamesD=/dev V=usr/var U=usr A=adm T=tmp E=etcNUL=$D/nullUAS=$U/$E/subsetsLOGFILE=/$E/setldlogTDIR=/$V/$T/stltmpTMP1=/$V/$T/tmp$$TMPS="$TDIR $TMP1"umask 22WHOAMI=`whoami`case "$WHOAMI" inroot) ;;*) LOGFILE=/dev/nullesacDECOMP=catecho -n "SETLD $$ $DATE " >> $LOGFILEtrap 'EMESG="Interupt Signal Received";exit' 2trap 'cd $ROOTPATH;DATE=`date +19%y.%m.%d.%T`wait;echo "SETLD $$ $DATE $ROOTPATH $ACT $STAT $EMESG" >> $LOGFILE;rm -rf $TMPS;echo "$EMESG";exit $STAT' 0# message stringsE_NOSUPP="not supported for installations."E_NODEV="$NLPlease be certain that device special file"E_FAIL="$NLFile copy to system disk failed."E_READ="$NLAttempt to read from your distribution media failed."E_MKDIR="$NLCannot create directory"E_NORECOVER="Cannot recover"E_NOINST="not currently installed"E_UNKNOWN="Unknown subset"E_STARS="*** Subset"E_TPOS="Tape positioning error."E_CFCPTN="$NLControl file is corrupt or obsolete: subset"IC="Installation Control"USAGE="${NL}Setld Usage Examples:$NLAdd previously initialized subset(s) from device:${HT}setld [dir] -a device subset [subset ...]$NLSend a configuration message to an installed subset:${HT}setld [dir] -c subset message$NLDelete subset(s):$NL${HT}setld [dir] -d subset [subset ...]$NLList all subsets:$NL${HT}setld [dir] -i$NLList contents of installed subset(s):${HT}setld [dir] -i subset [subset ...]$NLLoad layered product from device:$NL${HT}setld [dir] -l device$NLVerify setld on-disk data integrity:$NL${HT}setld [dir] -v$NLVerify integrity of subset(s):$NL${HT}setld [dir] -v subset [subset ...]$NLExtract media images from device for network distribution:${HT}setld -x device$NL$NL"ROOTPATH=/DEFPATH=1case "$1" in"") echo "$USAGE" & EMESG="Setld Argument Error" exit ;;-*) ;;/*) DEFPATH=0 ROOTPATH=$1 [ -d $ROOTPATH ] || { EMESG="$ROOTPATH: no such directory" ROOTPATH=/ STAT=1 exit } shift ;;*) EMESG="setld: $1: path argument must begin with '/'" STAT=1;exit ;;esacecho -n "$ROOTPATH " >> $LOGFILE &# CREATE NEEDED DIRECTORIES#(cd $ROOTPATH rm -rf $TDIR for X in $U $V $V/$A $V/$T $U/$E $UAS $TDIR { [ -d $X ] || mkdir $X || { EMESG="$E_MKDIR $X" STAT=1 exit } })# get function code.OPT=$1IFS=-ACT=`echo $1|dd conv=ucase 2> $NUL`IFS="$DIFS"case "$ACT" in # all options except -i are super-user only.[ACDLVX]) case "$WHOAMI" in root) ;; *) echo "Sorry $WHOAMI, setld $OPT can be used by super-user only." exit 1 esac ;;esaccase "$ACT" in[IV]) ;; # may have zero args.[ACDLX]) case "$#" in 1) echo "$USAGE" & EMESG="Setld Argument Error" exit esac ;;*) # this covers case of short args echo "$USAGE" & EMESG="Setld Argument Error" exitesacecho "$ACT" >> $LOGFILE &shift# break up arglist and make re-entrance check.case $ACT in[AXL]) [ -f $ROOTPATH/$TDIR ] && { EMESG="Setld Busy, please try again later" STAT=1 exit } DEVICE=$1 shift ;;esacSBS=`echo $*|dd conv=ucase 2> $NUL`# THE NEXT STRETCH OF CODE DEALS WITH THE C-D-I-V OPTIONS#case $ACT inC) CONFARG=$2 set xx $SBS _S=$2 cd $ROOTPATH LOG="$_S ($CONFARG)" [ -f $UAS/$_S.lk ] || { echo "$LOG FAILED: $E_NOINST" >> $LOGFILE & EMESG="$_S $E_NOINST, cannot configure." STAT=1 exit } [ -f $UAS/$_S.scp ] || { echo "$LOG FAILED (no scp)" >> $LOGFILE & EMESG="$_S: missing control program, cannot configure." STAT=1 exit } # all clear echo "Configuring $_S" ACT=C $UAS/$_S.scp $CONFARG STAT=$? case "$STAT" in 0) LOG="$LOG SUCCEEDED" ;; *) LOG="$LOG FAILED: scp status $STAT" esac echo "$LOG" >> $LOGFILE & exit ;;D) # delete named subsets. cd $ROOTPATH LOG= [ -d $TDIR ] || mkdir $TDIR || { echo "$NL$E_MKDIR $TDIR" & exit } for _S in $SBS do LOG="$LOG$_S" TZAK=$UAS/$_S # do we know this subset [ -f $TZAK.ctrl ] || { LOG="$LOG FAILED: $E_NOCTRL$NL" echo "$NL$E_STARS $_S: $E_NOCTRL" & continue } # is it installed? [ -f $TZAK.lk -o -f $TZAK.dw ] || # ica-12459 { LOG="$LOG FAILED: $E_NOINST$NL" echo "$NL$E_STARS $_S: $E_NOINST" & continue } # read in the control file. . $TZAK.ctrl || { LOG="$LOG FAILED: control file error.$NL" echo "Error reading control file for subset $_S, cannot delete." & continue } case "~$NAME~$DESC~$NVOLS~$MTLOC~$DEPS~$FLAGS~" in *~~*) LOG="$LOG FAILED: $E_CFCPTN$NL" echo "$E_CFCPTN $_S" & continue ;; esac case `expr $FLAGS % 2` in 1) LOG="$LOG FAILED: subset is permanent$NL" echo "Sorry, You may not delete the $DESC ($_S) subset" & continue ;; esac [ -s $TZAK.lk ] && { echo "The following subsets need the subset you are trying to deleteto operate correctly:$NL" cat $TZAK.lk | sed 's/^/ /' while : do echo -n "Are you sure you wish to delete the $_S subset? (y/n): " read X case "$X" in [Yy]*) LOG="$LOG WARNING: locked$NL" break ;; [Nn]*) LOG="$LOG FAILED: locked$NL" continue 2 ;; esac done } if [ -f $TZAK.lk ]; then { ACT=PRE_D $TZAK.scp || { LOG="$LOG FAILED: scp declined." echo " Subset $_S has declined it's deletion message. Cannot delete subset $_S" & continue } ACT=C $TZAK.scp DELETE }; fi # all of the deletion dragons have been slain... echo "Deleting $DESC ($_S)." & # create n lists of files to be deleted. # each list contains max 50 files awk '{if ($9 != "d") print $10}' $TZAK.inv | split -50 - $TDIR/del$$. # little rotor machine sets off up to 4 'rm's in # parallel, great for VAX/MP machines X= CMD="rm -rf \`cat \$K\`" for K in $TDIR/del$$.?? do # cover case of no files to delete. (?!?) case "$K" in *'??') break esac X=1$X case "$X" in 1) _B="&" ;; 1111) X= _B= esac eval $CMD $_B done wait [ -f $TZAK.lk ] && { ACT=POST_D $TZAK.scp case "$DEPS" in ".") ;; *) # remove dependency lock file info for K in $DEPS { [ -f $UAS/$K.lk ] && { grep -v $_S $UAS/$K.lk > $TMP1 mv $TMP1 $UAS/$K.lk } } ;; esac } # mark subset as uninstalled rm -f $TZAK.lk $TZAK.dw LOG="$LOG SUCCEEDED$NL" done echo "$LOG" >> $LOGFILE STAT=0;exit ;;I) # inventory named subsets. cd $ROOTPATH/$UAS case "$SBS" in "") # list names of all subsets known to system. RAWLIST=`echo *.ctrl|sed 's/\.ctrl//g'` case "$RAWLIST" in '*') EMESG="Error - cannot find any control files" exit esac # read note about text formatting in Subset Selection # part of setld. FW16=".............." # 14, really. SP16=" " echo "Subset Status Description====== ====== ===========" & OUTLIST= for K in $RAWLIST { STATUS=" " [ -f $K.lk ] && STATUS="installed " [ -f $K.dw ] && STATUS="corrupt " # ica-12459 . $K.ctrl { PSTR=`expr "$K$SP16" : '\('$FW16'\).*'`; echo "$PSTR $STATUS$DESC"; } & } ;; *) # inventory named subsets for _S in $SBS { [ -f $_S.inv ] && awk '{print $10}' $_S.inv } ;; esac STAT=0;exit ;;V) # on the fly verify... #! this is the place in the code where a full consistency #! check of all of setld's data files is taken. cd $ROOTPATH LOG= echo "Checking setld data files." & for _S in $SBS { LOG="$LOG$_S" [ -f $UAS/$_S.lk ] || { LOG="$LOG FAILED: $E_NOINST$NL" echo "$NL$_S: $E_NOINST" continue } ACT=V $UAS/$_S.scp || { LOG="$LOG FAILED: scp status $?$NL" echo "$_S: ivp failed." continue } LOG="$LOG SUCCEEDED$NL" } echo "$LOG" >> $LOGFILE STAT=0;exit ;;esac# END CODE FOR OPTIONS C-D-I-V# ALL OF THE REST OF THE CODE DEALS WITH INPUT FROM SOME DEVICE.## the parts:# CREATE NEEDED DIRECTORIES# PARSE DEVICE NAME# LOAD CONTROL INFORMATION (-l,-x only)# EXTRACT FOR RIS (-x only)# USER SUBSET SELECTION (-l only)# INSTALL SUBSETS FROM MEDIA#**************************************# PARSE DEVICE NAME#MEDIA=# 002 Put if/else around the 2 device parse blocksif [ -d $DEVICE ]; then{ MEDIA=DISK _U=$DEVICE}else{ # get the media type. case "$DEVICE" in *:) # TCP network installation MEDIA=network # the 'unit-number' is the server hostname IFS=: _U=`echo $DEVICE` IFS="$DIFS" # validate. # beware yp. CAT=cat HOSTS=/etc/hosts [ -f usr/bin/domainname ] && { case `domainname` in "") ;; *) CAT=ypcat HOSTS=hosts ;; esac } $CAT $HOSTS | egrep -s "$_U" || { EMESG="No hosts entry for server $_U" exit } # is it out there? #! error case should be handled with retries for goodies like #! no network ports, login limit reached. ERROR=`rsh $_U -l ris -n "echo hello" 2>&1` || { EMESG="Error contacting server $U: $ERROR" exit } ;; *mt*[lmh]) # some sort of tape device, get unit number and verify # access to nrmt?h. MEDIA=tape _U=`expr $DEVICE : '.*mt\([0-9][0-9]*\).*'` ;; *mt*) # tape device naming obsolete - xlate to 2.0 MEDIA=tape _U=`expr $DEVICE : '.*mt\([0-9][0-9]*\).*'` _U=`expr $_U % 4` # this gets unit plug number. ;; *ra*) # ra, rx50 diskettes # get unit number _U=`expr $DEVICE : '.*ra\([0-9][0-9]*\).*'` MEDIA=rx50 ALTOP=+ ALT=`expr $_U $ALTOP 1` # validate the existence of device files for # both the primary and alternate rx50's [ -f $D/rra${_U}a -a -f $D/rra${ALT}a ] || { EMESG="$E_NODEV: /dev/rra${U}a, /dev/rra${ALT}a" exit } ;; esac}; ficase "$MEDIA" in"") # bogus device. EMESG="Device $DEVICE $E_NOSUPP" exit ;;tape) # do code for old and new style tapes RAW=$D/nrmt${_U}h [ -f $RAW ] || { EMESG="Cannot access $RAW" exit } echo "Please make sure your installation tape is mounted and on-line." ready # position tape for the first read. { mt -f $RAW rew && mt -f $RAW fsf $T_0; } & MTPID=$! POS=0 ;;esacecho "Loading from device $DEVICE unit $_U" >> $LOGFILE## END PARSE DEVICE NAME# case actmedia#case "$ACT$MEDIA" inLrx50) echo -n "Insert the $IC diskette for the softwareyou wish to load on your system in $MEDIA unit $_U.$NL" ready (cd $TDIR;tar xpf $D/rra${_U}a) > $TMP1 || { echo "Attempt to read from diskette drive $_U failed.$NLRemove your diskette from $MEDIA unit $_U." # flip unit numbers _U=`expr $_U $ALTOP 1` case "$ALTOP" in +) ALTOP=- ;; -) ALTOP=+ ;; esac echo -n "Insert the $IC diskette for the softwareyou wish to load in $MEDIA unit $_U.NOTE: we are trying the SAME DISKETTE again but in $MEDIA unit $_U.$NL" ready (cd $TDIR;tar xpf $D/rra${_U}a) || { EMESG="Cannot read control information" exit } } ;;[LX]DISK) # directory on system contains subsets [ -d $_U/instctrl ] || { EMESG="Cannot read control information" exit } TDIR=$_U/instctrl ;;[ALX]tape) echo -n "Positioning tape..." EMESG="Tape Positioning Error" wait || { mt -f $RAW rew & exit } case "$ACT" in [XL]) EMESG="Error reading control information" && (cd $TDIR;tar xpbf 20 $RAW && mt -f $RAW fsf) || exit POS=1 ;; A) mt -f $RAW fsf && mt -f $RAW bsf || exit esac EMESG= echo "done." & ;;[AL]network) cd $ROOTPATH cp /etc/hosts /hosts IAM=`hostname` rcp $_U.ris:clients/$IAM $TMP1 || { EMESG="Error reading control information" exit } # drag over all of the control info. SL="*.comp" for K in `cat $TMP1` do SL="$SL $K.scp $K.ctrl $K.inv" done case "$ACT" in A) # update subsets directory in case of client file changes X=$UAS ;; X|L) # set up temp directory for later processing X=$TDIR SL="$SL *.image" esac rsh $_U -l ris -n "cd instctrl;tar cf - $SL" | (cd $X;tar xpf -) || { EMESG="Error reading control information" exit } ;;Xrx50) EMESG="Setld -x supports tape, ra60 and rrd40 only." exit ;;A*) ;;*) EMESG="Internal error" exit ;;esac# check to see if we're looking at a v1.2 workstation tapecase "$ACT" inL|X) X= [ -f $TDIR/X-WINDOWS-WS.ctrl ] && # qdss 32w v1.0 { X=UWD rm -f $TDIR/*-WS* & } [ -f $TDIR/X,V.ctrl ] && # qvss 32w v1.0 { X=UWV rm -f $TDIR/*,V* & } case "$X$MEDIA" in UW[VD]tape|UW[VD]network) cp /sys/dist/$X*.* $TDIR ;; UW[VD]*) EMESG="Cannot install workstation from $MEDIA" exit ;; esacesac# copy control files to $UAScase "$ACT" inL) (cd $TDIR;tar cf - *) | (cd $ROOTPATH/$UAS;tar xpf -)esac & # in the background...# set up SBS.case "$ACT$MEDIA$ADVFLAG" inLnetwork[01]) # build restricted SBS list. SBS=`egrep "ULT|UWS|UWV|UWD" $TMP1` ;;Lnetwork*) # get general SBS from clients file. SBS=`cat $TMP1` ;;L*[01]) SBS=`egrep 'UWS|ULT' $TDIR/*.image|awk '{print $3}'` ;;[LX]*) # alls fair, use *.image
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -