home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls011.1.Z / tls011.1 / usr / lib / custom / mmdfsls1.rmv
Encoding:
Text File  |  1992-02-11  |  6.3 KB  |  313 lines

  1. :
  2.  
  3. #BEGIN_CM_SCRIPTLIB
  4. #
  5. # Standard CM script function library
  6. # baselib v1.2
  7. #
  8.  
  9. PATH=/bin:/usr/bin:/etc:.
  10. LANG=english_us.ascii    # Used when scripts are internationalized.
  11. export PATH LANG
  12.  
  13. TMPFILE=/tmp/tmp$$    # Define a temporary file for use if necessary.
  14. TMPFILE1=/tmp/tmp1$$    # Define a temporary file for use if necessary.
  15. TMPFILE2=/tmp/tmp2$$    # Define a temporary file for use if necessary.
  16.  
  17. # Define return values.
  18. : ${OK=0} ${FAIL=1} ${STOP=10}
  19.  
  20. #
  21. # Print an error message.
  22. #
  23. error() {
  24.     echo "\nError: $*" >&2
  25.     return 0
  26. }
  27.  
  28. #
  29. #query the user for a responce.
  30. #a simpler system than prompt, use prompt for
  31. #more sophisticated uses.
  32. #q or Q returns fail, anything else return ok.
  33. #ARGS: <string>, string to print when asking for a responce
  34. #$OK means expression has been resolved or answer is given 
  35. #$FAIL means quit has been selected
  36. #
  37. respond() {
  38.     while    echo "\n${*}\nRespond or enter q to quit: \c" 
  39.     do    read answer
  40.         case $answer in
  41.         Q|q)    return $FAIL                    ;;
  42.         "")    # on a return key return $OK
  43.             answer="RETURNKEY"
  44.             return $OK            ;;
  45.         *)    # on anything else return $OK
  46.             return $OK                    ;;
  47.         esac
  48.     done
  49.     return $OK
  50. }
  51.  
  52. #
  53. # SHOULD BE USED WITH EVERY INSTALLATION SCRIPT
  54. #
  55. # Set the variable $prdperm to  /etc/perms/$PRDVALUE or ./tmp/perms/$PRDVALUE
  56. # If the permlist is found, the values for set, prd, ver, typ, rel,
  57. # and upd are set from the permlist.
  58. # Also determine the OS type, xenix or unix, and set systype accordingly.
  59. #
  60. # sets following information in exported variables
  61. # OSREL: x.x.xy    OSTYPE: unix|xenix    OSBUS: isa|mc
  62. # OSPRD: <prd value>    OSMCH: <os machine type>
  63. # echo "OS Release: $OSREL    OS Type: $OSTYPE    OS Bus: $OSBUS"
  64. # echo "OS PRD Value: $OSPRD    OS Machine Type: $OSMCH"
  65. #
  66. SETVARS1="Permlist not found"
  67. SETVARS2="Failed to set values from"
  68. SETVARS3="Incorrect prd value in"
  69.  
  70. # Variables set by setvars.
  71. prdperm=
  72. fixperm=fixperm
  73. brand=brand
  74. set=
  75. prd=
  76. typ=
  77. rel=
  78. ser=
  79. upd=
  80. systype=unknown
  81.  
  82. setvars() {
  83.  
  84. # Locate fixperm, brand, and the permlist.
  85.     for _i in /etc ./tmp
  86.     do
  87.         [ -f "$_i/fixperm" ] && fixperm=$_i/fixperm
  88.         [ -f "$_i/brand" ] && brand=$_i/brand
  89.         [ -f "$_i/perms/$PRDVALUE" ] && prdperm=$_i/perms/$PRDVALUE
  90.     done
  91.  
  92.     [ "$prdperm" ] || {
  93.         echo "Warning: $PRDVALUE $SETVARS1" >&2
  94.         return 1
  95.     }
  96.  
  97. # Get the operating system type:
  98.     case `uname -r` in
  99.         2.*)    systype=xenix
  100.             ;;
  101.         3.*)    systype=unix
  102.             ;;
  103.         *)    systype=unknown
  104.             ;;
  105.     esac
  106.  
  107. #
  108. # OS variables setting
  109. # OSREL: x.x.xy        OSTYPE: unix|xenix    OSBUS: isa|mc
  110. # OSPRD: <prdvalue>    OSMCH: os mch type
  111. #
  112.     OSTYPE=$systype
  113.     case "$OSTYPE" in
  114.         unix)
  115.         eval `sed -n '/^#prd=/s/#//p
  116.             /^#typ=/s/#//p
  117.             /^#rel=/s/#//p' /etc/perms/rtsmd` > /dev/null 2>&1
  118.             OSREL=$rel
  119.             OSPRD=$prd
  120.             OSMCH=$typ
  121.             if [ -r /dev/mcapos ]
  122.             then
  123.                 if grep mcapos /etc/perms/rtsmd > /dev/null 2>&1
  124.                 then
  125.                     OSBUS=mc
  126.                 fi
  127.             else
  128.                 OSBUS=isa
  129.             fi
  130.         ;;
  131.         xenix)
  132.         eval `sed -n '/^#prd=/s/#//p
  133.             /^#typ=/s/#//p
  134.             /^#rel=/s/#//p' /etc/perms/inst` > /dev/null 2>&1
  135.             OSREL=$rel
  136.             OSPRD=$prd
  137.             OSMCH=$typ
  138.             var=`expr $OSMCH : '.*\(..\)$'`
  139.             if [ "$var" = "MC" -o "$var" = "PS" ]
  140.             then
  141.                 OSBUS=mc
  142.             else
  143.                 OSBUS=isa
  144.             fi
  145.         ;;
  146.         *)
  147.             OSREL=unknown
  148.             OSTYPE=unknown
  149.             OSBUS=unknown
  150.             OSPRD=unknown
  151.             OSMCH=unknown
  152.         ;;
  153.     esac
  154.  
  155.     export OSREL OSTYPE OSBUS OSPRD OSMCH
  156.     # Clear these vars before they are used below.
  157.     prd=
  158.     rel=
  159.     typ=
  160.     
  161. # Extract product info from the permlist.
  162.     eval `sed -n '/^#set=/s/#//p
  163.         /^#prd=/s/#//p
  164.         /^#typ=/s/#//p
  165.         /^#rel=/s/#//p
  166.         /^#ser=/s/#//p
  167.         /^#upd=/s/#//p' $prdperm` || echo "\n$SETVARS2 $prdperm" >&2
  168.  
  169. # Check the prd value read from the permlist for correctness.
  170.  
  171.     case "$prd" in
  172.         "$PRDVALUE")    return 0
  173.                 ;;
  174.               *)    echo "\n$SETVARS3 $prdperm"  >&2
  175.                 return 1
  176.                 ;;
  177.     esac
  178.  
  179.     return 0
  180. }
  181.  
  182. #
  183. # Standard CM script function library
  184. # configlib V1.0
  185. # Contains: baselib, specificlib
  186. #
  187.  
  188. #
  189. # Standard CM script function library
  190. # specificlib v1.4
  191. # contains: baselib
  192. #
  193.  
  194. #
  195. # restorefiles
  196. # restores root backs that have been made during product installation
  197. # ARG1:    PRDVALUE to use to get standard backup location
  198. # Usage:    restorefiles <prdvalue>
  199. #
  200. RESTORE1_1="
  201. Files that were overwritten during installation have
  202. been backed up in: \c"
  203. RESTORE1_2="
  204. Restoring these files to their original location 
  205. will bring your system back to its prior state, 
  206. if no other products have overwritten these files.
  207. "
  208.  
  209. RESTORE2_1="Choose an option for product \c"
  210. RESTORE2_2="
  211. 1) Restore Backup Files
  212. 2) List Backup Files
  213. 3) Delete Backup Files and continue with product removal
  214. q) Quit this product removal
  215. "
  216. RESTORE3="Enter your selection: " 
  217. RESTORE4="Error: Unable to restore files"
  218. RESTORE5="<Press Return to Continue>"
  219.  
  220. RESTORE6="
  221. You must hit your Interupt Key immediately 
  222. to abort this custom removal attempt. 
  223. Continue to hit this key until you 
  224. are out of custom. 
  225. "
  226. RESTORE7="is not a valid response"
  227.  
  228. restorefiles() {
  229. PRDARG=$1
  230.     if [ -s "/usr/lib/custom/${PRDARG}/backup" ]
  231.     then
  232.         echo "$RESTORE1_1"
  233.         echo "/usr/lib/custom/${PRDARG}/backup"
  234.         echo "$RESTORE1_2"
  235.         while :
  236.         do
  237.             echo " "
  238.             echo "$RESTORE2_1"
  239.             echo $PRDARG
  240.             echo "$RESTORE2_2"
  241.             respond "$RESTORE3"
  242.             case $answer in
  243.             1)
  244.                 cd /usr/lib/custom/${PRDARG}/backup    
  245.             # First, copy across only those target directories 
  246.             # that do not exist. (This is to avoid nuking the 
  247.             # mode/uid/gid on dirs that already exist.)
  248.                 find . -type d -print | (
  249.                    cd /
  250.                    while read dnm ; do
  251.                        [ -d $dnm ] || echo $dnm
  252.                    done
  253.                 ) | cpio -pdmu  /  >/dev/null  2>&1
  254.  
  255.             # Next, copy across the files.
  256.                 find . -type f -print | cpio -pdmuv / || {
  257.                     echo "$RESTORE4"
  258.                 }
  259.                 cd /
  260.                 ;;
  261.             2)
  262.                 cd /usr/lib/custom/${PRDARG}/backup    
  263.                 find . -type f -print | pg -p "$RESTORE5"
  264.                 cd /
  265.                 ;;
  266.             3)
  267.                 cd /usr/lib/custom/${PRDARG}
  268.                 rm -rf backup
  269.                 cd /
  270.                 return 0
  271.                 ;;
  272.             q)
  273.                 echo "$RESTORE6"
  274.                 return 1
  275.                 ;;
  276.             *)
  277.                 error "$anwser $RESTORE7"
  278.                 ;;
  279.             esac
  280.         done
  281.     fi
  282.     [ -r /usr/lib/custom/${PRDARG}/backup ] && {
  283.          rm -rf /usr/lib/custom/${PRDARG}/backup
  284.     }
  285.     return 0
  286.  
  287. }
  288.  
  289. #END_CM_SCRIPTLIB
  290.  
  291. # MAIN    
  292.  
  293. # prd value
  294. PRDVALUE=mmdfsls1 ; export PRDVALUE
  295.  
  296. # assumes to be running at the
  297. # root directory.
  298. cd /
  299.  
  300. setvars
  301.  
  302. # optional restoration files that are in <prd>/backup
  303. echo "Checking for files to be restored..."
  304. restorefiles $PRDVALUE || {
  305.     echo "Warning restore action on backup"
  306.     echo "files has failed."
  307.     exit $FAIL
  308. }
  309.  
  310. rm -rf /usr/lib/custom/${PRDARG}
  311.  
  312. exit $OK
  313.