home *** CD-ROM | disk | FTP | other *** search
- :
-
- #BEGIN_CM_SCRIPTLIB
- #
- # Standard CM script function library
- # baselib v1.2
- #
-
- PATH=/bin:/usr/bin:/etc:.
- LANG=english_us.ascii # Used when scripts are internationalized.
- export PATH LANG
-
- TMPFILE=/tmp/tmp$$ # Define a temporary file for use if necessary.
- TMPFILE1=/tmp/tmp1$$ # Define a temporary file for use if necessary.
- TMPFILE2=/tmp/tmp2$$ # Define a temporary file for use if necessary.
-
- # Define return values.
- : ${OK=0} ${FAIL=1} ${STOP=10}
-
- #
- # Print an error message.
- #
- error() {
- echo "\nError: $*" >&2
- return 0
- }
-
- #
- #query the user for a responce.
- #a simpler system than prompt, use prompt for
- #more sophisticated uses.
- #q or Q returns fail, anything else return ok.
- #ARGS: <string>, string to print when asking for a responce
- #$OK means expression has been resolved or answer is given
- #$FAIL means quit has been selected
- #
- respond() {
- while echo "\n${*}\nRespond or enter q to quit: \c"
- do read answer
- case $answer in
- Q|q) return $FAIL ;;
- "") # on a return key return $OK
- answer="RETURNKEY"
- return $OK ;;
- *) # on anything else return $OK
- return $OK ;;
- esac
- done
- return $OK
- }
-
- #
- # SHOULD BE USED WITH EVERY INSTALLATION SCRIPT
- #
- # Set the variable $prdperm to /etc/perms/$PRDVALUE or ./tmp/perms/$PRDVALUE
- # If the permlist is found, the values for set, prd, ver, typ, rel,
- # and upd are set from the permlist.
- # Also determine the OS type, xenix or unix, and set systype accordingly.
- #
- # sets following information in exported variables
- # OSREL: x.x.xy OSTYPE: unix|xenix OSBUS: isa|mc
- # OSPRD: <prd value> OSMCH: <os machine type>
- # echo "OS Release: $OSREL OS Type: $OSTYPE OS Bus: $OSBUS"
- # echo "OS PRD Value: $OSPRD OS Machine Type: $OSMCH"
- #
- SETVARS1="Permlist not found"
- SETVARS2="Failed to set values from"
- SETVARS3="Incorrect prd value in"
-
- # Variables set by setvars.
- prdperm=
- fixperm=fixperm
- brand=brand
- set=
- prd=
- typ=
- rel=
- ser=
- upd=
- systype=unknown
-
- setvars() {
-
- # Locate fixperm, brand, and the permlist.
- for _i in /etc ./tmp
- do
- [ -f "$_i/fixperm" ] && fixperm=$_i/fixperm
- [ -f "$_i/brand" ] && brand=$_i/brand
- [ -f "$_i/perms/$PRDVALUE" ] && prdperm=$_i/perms/$PRDVALUE
- done
-
- [ "$prdperm" ] || {
- echo "Warning: $PRDVALUE $SETVARS1" >&2
- return 1
- }
-
- # Get the operating system type:
- case `uname -r` in
- 2.*) systype=xenix
- ;;
- 3.*) systype=unix
- ;;
- *) systype=unknown
- ;;
- esac
-
- #
- # OS variables setting
- # OSREL: x.x.xy OSTYPE: unix|xenix OSBUS: isa|mc
- # OSPRD: <prdvalue> OSMCH: os mch type
- #
- OSTYPE=$systype
- case "$OSTYPE" in
- unix)
- eval `sed -n '/^#prd=/s/#//p
- /^#typ=/s/#//p
- /^#rel=/s/#//p' /etc/perms/rtsmd` > /dev/null 2>&1
- OSREL=$rel
- OSPRD=$prd
- OSMCH=$typ
- if [ -r /dev/mcapos ]
- then
- if grep mcapos /etc/perms/rtsmd > /dev/null 2>&1
- then
- OSBUS=mc
- fi
- else
- OSBUS=isa
- fi
- ;;
- xenix)
- eval `sed -n '/^#prd=/s/#//p
- /^#typ=/s/#//p
- /^#rel=/s/#//p' /etc/perms/inst` > /dev/null 2>&1
- OSREL=$rel
- OSPRD=$prd
- OSMCH=$typ
- var=`expr $OSMCH : '.*\(..\)$'`
- if [ "$var" = "MC" -o "$var" = "PS" ]
- then
- OSBUS=mc
- else
- OSBUS=isa
- fi
- ;;
- *)
- OSREL=unknown
- OSTYPE=unknown
- OSBUS=unknown
- OSPRD=unknown
- OSMCH=unknown
- ;;
- esac
-
- export OSREL OSTYPE OSBUS OSPRD OSMCH
- # Clear these vars before they are used below.
- prd=
- rel=
- typ=
-
- # Extract product info from the permlist.
- eval `sed -n '/^#set=/s/#//p
- /^#prd=/s/#//p
- /^#typ=/s/#//p
- /^#rel=/s/#//p
- /^#ser=/s/#//p
- /^#upd=/s/#//p' $prdperm` || echo "\n$SETVARS2 $prdperm" >&2
-
- # Check the prd value read from the permlist for correctness.
-
- case "$prd" in
- "$PRDVALUE") return 0
- ;;
- *) echo "\n$SETVARS3 $prdperm" >&2
- return 1
- ;;
- esac
-
- return 0
- }
-
- #
- # Standard CM script function library
- # configlib V1.0
- # Contains: baselib, specificlib
- #
-
- #
- # Standard CM script function library
- # specificlib v1.4
- # contains: baselib
- #
-
- #
- # restorefiles
- # restores root backs that have been made during product installation
- # ARG1: PRDVALUE to use to get standard backup location
- # Usage: restorefiles <prdvalue>
- #
- RESTORE1_1="
- Files that were overwritten during installation have
- been backed up in: \c"
- RESTORE1_2="
- Restoring these files to their original location
- will bring your system back to its prior state,
- if no other products have overwritten these files.
- "
-
- RESTORE2_1="Choose an option for product \c"
- RESTORE2_2="
- 1) Restore Backup Files
- 2) List Backup Files
- 3) Delete Backup Files and continue with product removal
- q) Quit this product removal
- "
- RESTORE3="Enter your selection: "
- RESTORE4="Error: Unable to restore files"
- RESTORE5="<Press Return to Continue>"
-
- RESTORE6="
- You must hit your Interupt Key immediately
- to abort this custom removal attempt.
- Continue to hit this key until you
- are out of custom.
- "
- RESTORE7="is not a valid response"
-
- restorefiles() {
- PRDARG=$1
- if [ -s "/usr/lib/custom/${PRDARG}/backup" ]
- then
- echo "$RESTORE1_1"
- echo "/usr/lib/custom/${PRDARG}/backup"
- echo "$RESTORE1_2"
- while :
- do
- echo " "
- echo "$RESTORE2_1"
- echo $PRDARG
- echo "$RESTORE2_2"
- respond "$RESTORE3"
- case $answer in
- 1)
- cd /usr/lib/custom/${PRDARG}/backup
- # First, copy across only those target directories
- # that do not exist. (This is to avoid nuking the
- # mode/uid/gid on dirs that already exist.)
- find . -type d -print | (
- cd /
- while read dnm ; do
- [ -d $dnm ] || echo $dnm
- done
- ) | cpio -pdmu / >/dev/null 2>&1
-
- # Next, copy across the files.
- find . -type f -print | cpio -pdmuv / || {
- echo "$RESTORE4"
- }
- cd /
- ;;
- 2)
- cd /usr/lib/custom/${PRDARG}/backup
- find . -type f -print | pg -p "$RESTORE5"
- cd /
- ;;
- 3)
- cd /usr/lib/custom/${PRDARG}
- rm -rf backup
- cd /
- return 0
- ;;
- q)
- echo "$RESTORE6"
- return 1
- ;;
- *)
- error "$anwser $RESTORE7"
- ;;
- esac
- done
- fi
- [ -r /usr/lib/custom/${PRDARG}/backup ] && {
- rm -rf /usr/lib/custom/${PRDARG}/backup
- }
- return 0
-
- }
-
- #END_CM_SCRIPTLIB
-
- # MAIN
-
- # prd value
- PRDVALUE=mmdfsls1 ; export PRDVALUE
-
- # assumes to be running at the
- # root directory.
- cd /
-
- setvars
-
- # optional restoration files that are in <prd>/backup
- echo "Checking for files to be restored..."
- restorefiles $PRDVALUE || {
- echo "Warning restore action on backup"
- echo "files has failed."
- exit $FAIL
- }
-
- rm -rf /usr/lib/custom/${PRDARG}
-
- exit $OK
-