|
DataMuseum.dkPresents historical artifacts from the history of: Regnecentalen RC-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Regnecentalen RC-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T e
Length: 15980 (0x3e6c) Types: TextFile Names: »etc/tsdbadm «
└─⟦3d8f416b2⟧ Bits:30004042/core2.imd SW95705I 386/ix Multi-user Release 1.2 └─⟦this⟧ »etc/tsdbadm «
# @(#)tsdbadm.sh 1.2 - 86/11/15 # ######################################################################## # # tsdbadm - tty server administration is a shell script that # modifies and maintains the tty server database ttyserv.db # ######################################################################## ##### # full path name of the ttyserver database file ##### LISTENDIR=/usr/net/nls filename=$LISTENDIR/cfg/ttysrv.db #set flag for the first time through the shell script First=YES Serv_SZ=14 # max size of service name Nserv_SZ=15 # next size of servoce name Desc_SZ=60 # max size of description line Ndesc_SZ=61 # next size of description line ##### # make a temporary file to do all of the editing/modifying to # when exiting the script user is queried if all modifications # made should be officially implemented # yes - temporary file is copied to official file # no - temporary file is removed ##### cp ${filename} /tmp/$$tempfile if [ $? -ne 0 ] then echo "error in accessing ${filename}" exit 2 fi tempfile=/tmp/$$tempfile ############################# ############################# while true do # Set variables to NO Quit=NO Change=NO Delete=NO Edit=NO List=NO Maint=NO Done=NO while true do ######## # Main Menu ######## echo "\n\t\t\tMAIN MENU" echo "\n\tEnter the letter that corresponds to the desired action\n" echo "\tc - Change the default service" echo "\td - Delete an entry " echo "\te - Edit/Update the TTY Server database" echo "\tl - List the entries in the TTY Server database" echo "\tm - Maintenance (remove the ??tsdb.save files)" echo "\tq - Quit" echo "\nPlease enter [c, d, e, l, m or q]: \c" read Response if [ "${Response}" != "q" ] then if [ "${Response}" = "c" ] # Change the Default service then First=NO Change=YES break fi if [ "${Response}" = "d" ] # Delete an Entry then First=NO Delete=YES break fi if [ "${Response}" = "e" ] # Edit/Update the file then First=NO Edit=YES break fi if [ "${Response}" = "l" ] # List the Entries then List=YES break fi if [ "${Response}" = "m" ] # Maintenance then Maint=YES break fi echo "\ninvalid response: please try again" continue fi Quit=YES break done ########## # Changing the Default Service ########## if [ "${Change}" = YES ] then # set servname to a list of service names # cut the list and set curdef to the current default # entry (the first entry) servname=`sed -n "/^S:/p" ${tempfile} | cut -d: -f2` curdef=`echo $servname | cut -d" " -f1` # print the current default entry echo echo "Current Default Service is:" echo # find service entry; join with description # strip "S:"; replace "D:" with tab # replace "C:" with 3 spaces; end with blank line # newform to get column to line up sed -n "/^S:${curdef}$/,/^\.$/ { /^S:/N s/^S:// s/\nD:/ / s/^C:/ / s/^\.// p }" $tempfile | newform -i-16 # find the line number of the first service entry first=`fgrep -nx "S:${curdef}" ${tempfile} | cut -d: -f1` while true do echo "What Service Do You Want to Be the New Default ( q - to quit)? \c" read Name Rest if [ "$Name" = q ] then Done=YES break fi if [ x"$Name" = x ] then echo "\ninvalid response: please try again\n" continue fi if [ x"$Rest" != x ] then echo "\ninvalid response (entry cannot contain embedded blanks): please try again\n" continue fi #if valid response then go on break done # return to main menu if [ "${Done}" = YES ] then Done=NO continue fi line=`fgrep -nx "S:${Name}" ${tempfile} | cut -d: -f1` if [ "${line}" -lt 10 ] then echo "\nNo entry exists for service: ${Name}" echo "You must make an entry for that service first" echo "Add an entry using option 'e' - Edit/Update" echo "Of the Main Menu" continue fi # move the four line entry of the New default service # to the line before the Current default service ed - ${tempfile} << ! ${line},${line}+3m${first}-1 w q ! # Print out the New Default Entry (first entry) # # find service entry; join with description # strip "S:"; replace "D:" with tab # replace "C:" with 3 spaces; end with blank line # newform to get column to line up echo "\nThe New Default Service Entry is:\n" sed -n "/^S:${Name}$/,/^\.$/ { /^S:/N s/^S:// s/\nD:/ / s/^C:/ / s/^\.// p }" $tempfile | newform -i-16 continue fi ########## # Deleting and Entry ########## if [ "${Delete}" = YES ] then while true do echo "\nEnter name of service to be deleted( q - to quit): \c" read Name Rest if [ x"$Name" = x ] then echo "\ninvalid response: please try again" continue fi if [ x"$Rest" != x ] then echo "\ninvalid response (entry cannot contain embedded blanks): please try again\n" continue fi if [ "$Name" = q ] then break fi fgrep -x "S:${Name}" ${tempfile} > /dev/null if [ "$?" != 0 ] then echo "\nNo entry exists for service: ${Name}\n" break fi echo "\nThe entry for ${Name} is:\n" # find service entry; join with description # strip "S:"; replace "D:" with tab # replace "C:" with 3 spaces; end with blank line # newform to get column to line up sed -n "/^S:${Name}$/,/^\.$/ { /^S:/N s/^S:// s/\nD:/ / s/^C:/ / s/^\.// p }" $tempfile |newform -i-16 while true do echo "\nAre you sure you want to delete the ${Name} entry? [y, n] \c" read Sure if [ "${Sure}" != "y" ] && [ "${Sure}" != "n" ] then echo "\ninvalid response: please try again" continue fi break done if [ ${Sure} = "y" ] then echo "\nRemoving the ${Name} entry" ed - ${tempfile} > /dev/null << ! /^S:${Name}$/ .,+3d w q ! break fi echo "\nThe ${Name} entry was not removed" break done continue fi ########## # Editing/Updating the File ########## if [ "${Edit}" = YES ] then while true do echo "\nEnter services full name ( q - to quit)" echo "($Serv_SZ characters maximum): \c" read Name Rest if [ x"$Name" = x ] then echo "\ninvalid response: please try again" continue fi if [ x"$Rest" != x ] then echo "\ninvalid response (entry cannot contain embedded blanks): please try again\n" continue fi if [ "$Name" = q ] then break fi Length=`echo $Name| wc -c` if [ "$Length" -gt $Nserv_SZ ] then echo "Service name must be $Serv_SZ characters or less" continue fi # check if an entry for this file already exists fgrep -x "S:${Name}" ${tempfile} > /dev/null if [ "$?" -eq 0 ] then # an entry for that service already exists while true do echo "\nAn entry for ${Name} already exists: \n" echo # find service entry; join with description # strip "S:"; replace "D:" with tab # replace "C:" with 3 spaces; end with blank line # newform to get column to line up sed -n "/^S:${Name}$/,/^\.$/ { /^S:/N s/^S:// s/\nD:/ / s/^C:/ / s/^\.// p }" $tempfile |newform -i-16 echo "Do you want to modify that entry [y,n] \c" read MODIFY if [ "${MODIFY}" != "y" ] && [ "${MODIFY}" != "n" ] then echo "\ninvalid response: please try again" continue fi break done if [ "${MODIFY}" = "n" ] then while true do echo "\nDo you want to add/modify another entry? [y, n] \c" read Again if [ "${Again}" != "y" ] && [ "${Again}" != "n" ] then echo "\ninvalid response: please try again" continue fi break done if [ "${Again}" = "n" ] then break fi continue fi ########## # Modifying an existing entry ########## while true do echo "\nModify the:" echo "\tc - Command Line " echo "\td - Description " echo "\tq - Quit (Modifying the Entry)" echo "\n Please enter [c, d or q]: \c" read Choice if [ "${Choice}" != "q" ] then line=`fgrep -nx "S:${Name}" ${tempfile} | cut -d: -f1` ########## # Modify the Description ########## if [ "${Choice}" = "d" ] then while true do echo "\nEnter description" echo "($Desc_SZ characters maximum): \c" read Descrip if [ x"$Descrip" = x ] then echo "\ninvalid response: please try again" continue fi Length=`echo $Descrip| wc -c ` if [ "$Length" -gt $Ndesc_SZ ] then echo "The description must be $Desc_SZ characters or less" continue fi break done ed - ${tempfile} > /dev/null << ! /S:${Name}$ /D:/d i D:${Descrip} . w q ! echo "\nDescription modified for the ${Name} entry" # find service entry; join with description # strip "S:"; replace "D:" with tab # replace "C:" with 3 spaces; end with blank line # newform to get column to line up echo "\nThe entry for ${Name} is:\n" sed -n "/^S:${Name}$/,/^\.$/ { /^S:/N s/^S:// s/\nD:/ / s/^C:/ / s/^\.// p }" $tempfile |newform -i-16 continue fi ########## # Modify the Command Line ########## if [ "${Choice}" = "c" ] then while true do echo "\nEnter command line (specify full path & options): \c " read Full if [ x"$Full" = x ] then echo "\ninvalid response: please try again" continue fi break done line=${line}-1 ed - ${tempfile} > /dev/null << ! /S:${Name}$ /C:/d i C:${Full} . w q ! echo "\nCommand Line modified for the ${Name} entry" # find service entry; join with description # strip "S:"; replace "D:" with tab # replace "C:" with 3 spaces; end with blank line # newform to get column to line up echo "\nThe entry for ${Name} is:\n" sed -n "/^S:${Name}$/,/^\.$/ { /^S:/N s/^S:// s/\nD:/ / s/^C:/ / s/^\.// p }" $tempfile |newform -i-16 continue fi echo "\ninvalid response: please try again" continue fi break done continue fi while true do echo "\nEnter command line (specify full path & options): \c " read Full if [ x"$Full" = x ] then echo "\ninvalid response: please try again" continue else break fi done while true do echo "\nEnter description" echo "($Desc_SZ characters maximum): \c" read Descrip if [ x"$Descrip" = x ] then echo "\ninvalid response: please try again" continue fi Length=`echo $Descrip | wc -c ` if [ "$Length" -gt $Ndesc_SZ ] then echo "The description must be $Desc_SZ characters or less" continue fi break done while true do echo "\nVerify the new entry\n" echo "Service: $Name" echo "Description: $Descrip" echo "Command: $Full" echo "\nEnter letter that corresponds to desired action:" echo echo "\ta - Add this entry to the database" echo "\ti - Ignore this entry" echo "\tq - Quit (return to Main Menu)" echo "\nPlease enter [ a, i or q ]: \c" read Verify case $Verify in a|add) #appending a new entry to the file echo "\nUpdating the File" echo S:${Name} >> ${tempfile} echo D:${Descrip} >> ${tempfile} echo C:${Full} >> ${tempfile} echo . >> ${tempfile} break ;; i|ignore) break ;; q|quit) Done=YES break ;; *) echo "\ninvalid response: please try again" continue ;; esac done if [ "${Done}" = YES ] then Done=NO break fi done continue fi ########## # Listing the Entries ########## if [ "${List}" = YES ] then while true # display until asked to quit do echo echo "Enter letter that corresponds to desired output:" echo echo "\td [service ...] - Display All or [specific] Service Entries" echo "\tl - List of All Services" echo "\tq - Quit (return to Main Menu)" echo "\nPlease enter [ d, d service...., l or q ]: \c" read Command Services case $Command in l) # list only the service names from the database echo Services=`sed -n "s/^S://p" $tempfile` # get the service names Number=`echo $Services|wc -w` # count number of names if [ $Number -gt 8 ] # if greater than 8 print in columns then echo `echo $Services|sed "s/ /\\\\\n/g"`|pr -t -4 else echo `echo $Services|sed "s/ /\\\\\n/g"` fi echo echo "(the first entry is the default service)" ;; d) # display one or more service entries echo for Service in ${Services:=""} # if $Services is not set go through do # loop once with null value # select one or more entries # join with description # strip S: # replace D: with tab # replace C: with 3 spaces # end with blank line # newform to get column to line up sed -n -e "1 { s/.*/No entry exists for $Service / H }" \ -e "/^S:${Service:-.*}$/,/^\.$/ { /^S:/N s/^S:// s/\nD:/ / s/^C:/ / s/^\.// p s/.*// x }" \ -e "$ { x p }" $tempfile |newform -i-16| pg -e -15 -p " Return for next page:" done # pg to handle long outputs ;; q) # for q break out of loop break ;; *) # any other command just prompt again echo "\ninvalid response: please try again" ;; esac done continue fi ########## # Maintenance ########## if [ "${Maint}" = YES ] then ########## READ THIS COMMENT ########## # these lines are description out because the maintenance # routine currently only removes the savefiles # ($LISTENDIR/tmp/??tsdb.save) # # if it is ever modified to do more these lines of # code may be used #while true #do # echo "\nDo you want to remove the $LISTENDIR/tmp/??tsdb.save files? [y, n] \c" # read Clean # if [ "${Clean}" != "y" ] && [ "${Clean}" != "n" ] # then # echo "\ninvalid response: please try again" # continue # fi # break #done #if [ "${Clean}" = "y" ] #then echo "\nRemoving the $LISTENDIR/tmp/??tsdb.save files" rm -f $LISTENDIR/tmp/*tsdb.save #fi continue fi ########## # Quit ########## if [ "${Quit}" = YES ] then if [ "${First}" = NO ] then while true do echo "\nDo you want to implement the changes made during this session? [y, n] \c" read Implement if [ "${Implement}" != "y" ] && [ "${Implement}" != "n" ] then echo "\ninvalid response: please try again" continue fi break done if [ "${Implement}" = "y" ] then while true do echo "\nDo you want to save a copy of the original TTY Server database? [y, n] \c" read Save if [ "${Save}" != "y" ] && [ "${Save}" != "n" ] then echo "\ninvalid response: please try again" continue fi break done if [ "${Save}" = "y" ] then cp ${filename} $LISTENDIR/tmp/$$tsdb.save if [ $? -ne 0 ] then echo "error in accessing ${filename}" echo "no changes made during this session will be implemented" exit 2 fi echo "\nCopy of Original TTY Server database is $LISTENDIR/tmp/$$tsdb.save" fi echo "\nImplementing Changes into the TTY Server database" mv ${tempfile} ${filename} break fi fi rm ${tempfile} break fi done