home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / UNIX3862.ZIP / U386-06.ZIP / U386-6.TD0 / usr / lbin / Install.sh < prev    next >
Encoding:
Text File  |  1988-06-26  |  11.2 KB  |  472 lines

  1. :
  2. #    Copyright (c) 1984, 1986, 1987, 1988 AT&T
  3. #      All Rights Reserved
  4.  
  5. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
  6. #    The copyright notice above does not evidence any
  7. #    actual or intended publication of such source code.
  8.  
  9. #    Copyright (c) 1987, 1988 Microsoft Corporation
  10. #      All Rights Reserved
  11.  
  12. #    This Module contains Proprietary Information of Microsoft
  13. #    Corporation and should be treated as Confidential.
  14.  
  15. #ident    "@(#)pkging:Install.sh    1.12.2.8"
  16. #
  17. # ----------------------------------------------------------------------
  18. # PURPOSE:  Install application software in PLUS format.
  19. # ----------------------------------------------------------------------
  20. INDIR=/usr/lib/installed
  21. CONTENTS=${INDIR}/CONTENTS
  22. PLUSDIR=/tmp/installed
  23. TMPDIR=/usr/tmp/install$$
  24. CPLOG=/tmp/cplog$$
  25.  
  26. trap "trap '' 1 2 3 9 15; cd /; rm -rf ${TMPDIR} ${CPLOG}; echo You have canceled the installation.; sync; exit 1" 1 2 3 9 15
  27.  
  28. SPACE=/etc/conf/bin/idspace
  29.  
  30. FDMESS="Please insert the floppy disk.\n\nIf the program installation \
  31. requires more than one floppy disk, be sure to insert the disks in the \
  32. proper order, starting with disk number 1.\nAfter the first floppy disk, \
  33. instructions will be provided for inserting the remaining floppy disks."
  34. ERROR2="An error was encountered while reading in the floppy disk(s).\
  35. Please be sure to insert them in the proper order, that the drive door is closed,\
  36. and wait for the notification before removing them."
  37. ERROR3="If this problem reoccurs at the same floppy disk, the floppy disk may \
  38. be bad. Please re-insert the first floppy disk of this package and try again."
  39.  
  40. # Check if root is performing the operation
  41. id | grep "(root)" > /dev/null
  42. if [ "$?" = "0" ]
  43. then
  44.     id | grep "euid=" > /dev/null
  45.     if [ "$?" = "0" ] #Did get root above; no euid string
  46.     then
  47.         id | grep "euid=0(root)" > /dev/null
  48.         if [ "$?" = 0 ]
  49.         then
  50.             UID=0
  51.         else
  52.             UID=1
  53.         fi
  54.     else
  55.         UID=0
  56.     fi
  57. else
  58.     UID=1
  59. fi
  60. if [ "$UID" != 0 ]
  61. then echo "You must be root or super-user to install software."
  62.      exit 1
  63. fi
  64.  
  65. if [ -z "$TERM" ]
  66. then TERM=AT386-M
  67. fi
  68. CLEAR=`tput clear 2>/dev/null`
  69.  
  70. if [ $# -eq 2 ]
  71. then DRIVE=$1
  72. else DRIVE=/dev/rdsk/f0
  73. fi
  74. FD=$2
  75. cd /
  76. rm -rf ${TMPDIR}
  77. mkdir ${TMPDIR}
  78. cd ${TMPDIR}
  79.  
  80. if [ ! -f ${CONTENTS} ]
  81. then    rm -rf ${CONTENTS}
  82.     >> ${CONTENTS}
  83. fi
  84.  
  85. DEVICE=q
  86. while [ 1 ]
  87. do
  88.     rm -rf Size
  89.     echo "$CLEAR"
  90.     echo "\n\nSearching for the Size file\n"
  91.  
  92.     xtract icBu Size ${DRIVE} 1>${CPLOG} 2>&1
  93.     err=$?
  94.     sync
  95.     if [ "`grep \"error - Size not found\" ${CPLOG}`" ]
  96.     then DEVICE=q
  97.     elif [ "$err" != "0" ]
  98.     then continue
  99.     fi
  100.     if [ -r Size -a -s Size ]
  101.     then 
  102.         DEVICE=w
  103.         if grep "USR=" Size 2>&1 > /dev/null ||
  104.            grep "ROOT=" Size 2>&1 > /dev/null
  105.         then
  106.             APPTYPE="386"
  107.         else
  108.             APPTYPE="PLUS"
  109.             # DENSITY is used to flag whether the application
  110.             # should by cpio'd or cpiopc'd.  All plus applications
  111.             # should be cpiopc'd regardless if they are 1.2 or 360.
  112.             DENSITY=360
  113.         fi
  114.     fi
  115.     while [ 1 ]
  116.     do
  117.     if [ $DEVICE = q ]
  118.     then
  119.         while [ 1 ]
  120.         do
  121.         flp=0
  122.         while [ $flp -lt 1 ]
  123.         do
  124.             echo "Please enter the number of floppies in the package followed by ENTER: \c"
  125.             read num
  126.             if [ -z "$num" ]
  127.             then
  128.                 echo "The number of floppies field must be filled in."
  129.             else
  130.                 expr ${num} \* 20 > /dev/null 2>/dev/null
  131.                 if  [ $? != 0 ]
  132.                     then echo "The number of floppies, is not a valid number."
  133.                 elif  [ 1 -gt "$num" ]
  134.                 then
  135.                     echo "The number of floppies must be at least 1."
  136.                 else
  137.                     flp=`expr $num`
  138.                 fi
  139.             fi
  140.         done
  141.         media=0
  142.         while [ $media -lt 1 ]
  143.         do
  144.             echo "\rPlease enter:\n\
  145.             1 (for 360 KB)\n\
  146.             2 (for 1.2 MB)\n\
  147.             3 (for 720 KB)\n\
  148.             4 (for 1.44 MB)\n\c"
  149.                 
  150.             read num
  151.             if [ -z "$num" ]
  152.             then
  153.                 echo "The disk density must be filled in."
  154.             else
  155.                 expr ${num} \* 20 > /dev/null 2>/dev/null
  156.                 if  [ $? != 0 ]
  157.                     then echo "The density number is not a valid number."
  158.                 elif  [ 1 -eq "$num" ]
  159.                 then
  160.                     media=`expr $num`
  161.                     DENSITY=360
  162.                     DEVICE=y
  163.                     BLOCKS=702
  164.                 elif  [ 2 -eq "$num" ]
  165.                 then
  166.                     media=`expr $num`
  167.                     DEVICE=z
  168.                     BLOCKS=2370
  169.                 elif [ 3 -eq "$num" ]
  170.                 then
  171.                     media=`expr $num`
  172.                     DEVICE=a
  173.                     BLOCKS=1440
  174.                 elif [ 4 -eq "$num" ]
  175.                 then
  176.                     media=`expr $num`
  177.                     DEVICE=b
  178.                     BLOCKS=2880
  179.                 else
  180.                     echo "The density number must be 1, 2, 3, or 4."
  181.                 fi
  182.             fi
  183.         done
  184.         break
  185.        done
  186.        USR=`expr ${flp} \* ${BLOCKS} `
  187.        ROOT=50
  188.     fi
  189.     if [ $DEVICE = w ]
  190.     then
  191.         linecnt=`expr \`cat Size | wc -l\``
  192.         if [ \( $linecnt -ne 1 \) -a \( $linecnt -ge 3 \) ]
  193.         then
  194.             echo "Invalid Size file found.  Cannot determine disk requirements."
  195.             DEVICE=q
  196.             continue
  197.         fi
  198.         ROOT=10
  199.         USR=10
  200.         if [ "`grep ROOT= Size`" ]
  201.         then ROOT=50
  202.              USR=50
  203.         fi
  204.         if [ "`grep USR= Size`" ]
  205.         then USR=50
  206.         fi
  207.         if [ \( \( $ROOT = 50 \) -a \( $USR != 50 \) \) -o \( \( $ROOT != 50 \) -a \( $USR = 50 \) \) ]
  208.         then
  209.             echo "Invalid Size file found.  Cannot determine disk requirements."
  210.             DEVICE=q
  211.             continue
  212.         fi
  213.         if [ "`grep USR= Size`" ]
  214.         then
  215.             ROOT=`cat Size | grep ROOT | cut -d= -f2`
  216.             USR=`cat Size | grep USR | cut -d= -f2`
  217.         elif [ "`grep ROOT= Size`" ]
  218.         then
  219.             ROOT=`cat Size | grep ROOT | cut -d= -f2`
  220.         else
  221.             USR=`cat Size`
  222.             ROOT=50
  223.         fi
  224.     fi
  225.     break
  226.     done
  227.     FILE_S="user (/usr) filesystem"
  228.     $SPACE -u $USR > /dev/null 2>&1
  229.     ERR=$?
  230.     if [ $ERR = 3 ]
  231.     then
  232.         FILE_S="hard disk"
  233.         ROOT=`expr $ROOT + $USR`
  234.     fi
  235.     if [ $ERR = 2 ]
  236.     then USR="user (/usr) "
  237.     else USR=
  238.     fi
  239.     $SPACE -r $ROOT > /dev/null 2>&1
  240.     if [ $? = 2 ]
  241.     then ROOT="root (/) "
  242.     else ROOT=""
  243.     fi
  244.     if [ \( $ERR = 2 \) -o \( "$ROOT" = "root (/) " \) ]
  245.     then
  246.         if [ \( $ERR = 2 \) -a \( "$ROOT" = "root (/) " \) ]
  247.         then S=s
  248.              CONJ=" and "
  249.         else S=
  250.              CONJ=
  251.         fi
  252.         if [ -z "$USR" ]
  253.         then PART="${ROOT}filesystem "
  254.         else PART="${ROOT}${CONJ}${USR}filesystem${S} "
  255.         fi
  256.         message "There is not enough room on the hard disk to \
  257. install the package.  Please remove some files from the ${PART}and try again."
  258.         echo "The Installation is canceled."
  259.         break
  260.     fi
  261.  
  262.     if [ $DEVICE != w ]
  263.     then
  264.         message -c "$FDMESS"
  265.         if [ $? != "0" ]
  266.         then
  267.             echo "The Installation is canceled."
  268.             break
  269.         fi
  270.     fi
  271.     rm -rf *
  272. ##
  273.     if [ "${APPTYPE}" = "PLUS" ]
  274.     then
  275.         cd /
  276.         rm -rf ${TMPDIR}
  277.         TMPDIR=${PLUSDIR}
  278.         mkdir ${TMPDIR}
  279.         cd ${TMPDIR}
  280.     fi
  281.     echo "$CLEAR"
  282.     echo "                        Install in progress\n\n\n\n\n\n"
  283.     if [ "$DENSITY" = "360" ]
  284.     then
  285.         /etc/.cpiopc -iBcduw$FD 2>${CPLOG}
  286.         err=$?
  287.     else
  288.         cpio -iBcdu -I${DRIVE} -M"You may remove this floppy disk.
  289. To QUIT - strike <q> followed by <ENTER>
  290. To continue - insert floppy disk number %d and strike the <ENTER> key." 2>${CPLOG}
  291.         err=$?
  292.     fi
  293.     if [ "`grep \"file header information\" ${CPLOG}`" ]
  294.     then
  295.         message -c "The floppy disk you inserted is either not the correct floppy disk, \
  296. or you inserted it in the wrong order.  ${ERROR3}"
  297.         if [ $? != "0" ]
  298.         then
  299.             echo "The Installation is canceled."
  300.             break
  301.         fi
  302.     elif [ "`grep \"annot create\" ${CPLOG}`" ]
  303.     then
  304.         message "Your ${FILE_S} is out of space.  Please remove some files and try again."
  305.         echo "Installation aborted."
  306.         break
  307.     elif [ "$err" = "4" ]
  308.     then
  309.         message -c "You have canceled the Installation.  If you wish \
  310. to try it again press ENTER, otherwise press ESC."
  311.         if [ $? != "0" ]
  312.         then
  313.             echo "The Installation is canceled."
  314.             break
  315.         fi
  316.     elif [ "$err" != "0" ] 
  317.     then
  318.         message -c "${ERROR2}  ${ERROR3}"
  319.         err1=$?
  320.         if [ $err1 != "0" ]
  321.         then
  322.             echo "The Installation is canceled."
  323.             break
  324.         fi
  325. # No need to check for ./Size since we're here
  326.     elif [ ! -f ./Install -o ! -f ./Remove -o ! -f ./Name ]
  327.     then
  328.         message -c "The software package is missing the necessary installation programs.  \
  329. Please check to make sure you have the right floppy disk(s)."
  330.         if [ "$?" != "0" ]
  331.         then    
  332.             echo "The Installation is canceled."
  333.             break
  334.         fi
  335.     else
  336.         trap '' 1 2 3 9 15
  337.         chmod +x ./Install
  338.         NAME=`cat -s Name`
  339. # Check out if previously installed
  340.         SNAME=`echo "$NAME" | sed -e 's/[ &()$#-?\\!*;|<>]/./g' -e 's/\[/./g' -e 's/\]/./g'`
  341.  
  342.         #  Warn the user if there is a xenix package already installed
  343.         #  with the same name.  
  344.         #  Use a bogus directory to check if /etc/perms is an empty 
  345.         #  directory.  Used to be guaranteed not empty in XENIX.
  346.         #  Avoids expansion of '*'.
  347.         tmp=/tmp/CUSLIST
  348.         perm_files=`cd /etc/perms; echo *`
  349.         if [ "/att/msoft/isc/*" != "/att/msoft/isc/$perm_files" ]
  350.         then
  351.             for perm in $perm_files
  352.             do
  353.                 #  Call fixperm to list the installed packages 
  354.                 #  for this set
  355.                 fixperm -iv $ignorepkgs /etc/perms/$perm |
  356.                 sed "s/^\(.*\)    .*$/s:^#!\1[     ][     ]*:    &    :p/" > $tmp.fl
  357.                 #  Get the package name in field 4 
  358.                 sed -n -f $tmp.fl /etc/perms/$perm   | 
  359.                         sed "s/^    //"  | 
  360.                         cut -f4 >> $tmp.sid
  361.             done
  362.  
  363.             KEY=`grep "$SNAME\$" $tmp.sid`
  364.             rm $tmp.sid $tmp.fl
  365.             if [ -n "$KEY" ]
  366.             then 
  367.                 message -c "A XENIX package with the same name, $NAME, \
  368.     has already been installed.  This package may overwrite the XENIX package."
  369.                  if [ "$?" != "0" ]
  370.                  then echo "The Installation is canceled"
  371.                  break
  372.                  fi
  373.             fi
  374.         fi
  375.  
  376.         KEY=`grep " $SNAME\$" $CONTENTS`
  377.         if [ -n "$KEY" ]
  378.         then message -c "The $NAME has already been installed.  \
  379. The new installation will now replace the original $NAME files."
  380.              if [ "$?" != "0" ]
  381.              then echo "The Installation is canceled"
  382.              break
  383.              fi
  384.              cd /usr/options
  385.              for i in *
  386.              do
  387.             grep "^${SNAME}$" $i > /dev/null 2>&1
  388.             if [ $? = 0 ]
  389.             then
  390.                 KEY2=$i
  391.                 break
  392.             fi
  393.              done
  394.              cd ${TMPDIR}
  395.              eval KEY=`grep " $SNAME\$" $CONTENTS | cut -f1 -d' ' `
  396.              if [ "$KEY" ]
  397.              then
  398.                mv ${INDIR}/Remove/${KEY2} /tmp/${KEY}.R
  399.                mv ${INDIR}/Files/${KEY2} /tmp/${KEY}.F > /dev/null 2>&1
  400.                mv /usr/options/${KEY2} /tmp/${KEY}.O
  401.                grep " $SNAME\$" $CONTENTS > /tmp/${KEY}
  402.                    grep -v " $SNAME\$" $CONTENTS > /tmp/$$
  403.                    mv /tmp/$$ $CONTENTS
  404.              fi
  405.         else KEY2=`echo "$NAME" | sed -e 's/ //g' | tr "[A-Z]" "[a-z]" | cut -c1-6`
  406.              if [ -f /usr/options/${KEY2}.name ]
  407.              then
  408.             num=`expr 1`
  409.             while [ -f /usr/options/${KEY2}${num}.name ]
  410.             do
  411.                 num=`expr $num + 1`
  412.             done
  413.             KEY2=${KEY2}${num}.name
  414.              else
  415.             KEY2=${KEY2}.name
  416.              fi
  417.         fi
  418.         echo "$CLEAR "
  419.         ./Install
  420.         # It is the 'Install' script's job to print an error message
  421.         # if the installation indicates the return of non-zero:
  422.         if [ "$?" != "0" ]
  423.         then
  424.             if [ -n "$KEY" ]
  425.             then
  426.                 mv /tmp/${KEY}.R ${INDIR}/Remove/${KEY2} > /dev/null 2>&1
  427.                 mv /tmp/${KEY}.F ${INDIR}/Files/${KEY2} > /dev/null 2>&1
  428.                 mv /tmp/${KEY}.O /usr/options/${KEY2} > /dev/null 2>&1
  429.                 cat /tmp/${KEY} >> $CONTENTS
  430.                 rm -f /tmp/${KEY} > /dev/null 2>&1
  431.             fi
  432.             break
  433.         else
  434.             if [ -n "$KEY" -a -s /tmp/${KEY}.un ]
  435.             then
  436.                 rm -f /tmp/${KEY}.[RFO] /tmp/${KEY}
  437.             fi
  438.             if [ ! -d $INDIR ]
  439.             then mkdir $INDIR; chmod 755 $INDIR
  440.             fi
  441.             if [ ! -d ${INDIR}/Files ]
  442.             then mkdir ${INDIR}/Files; chmod 755 ${INDIR}/Files
  443.             fi
  444.             if [ ! -d ${INDIR}/Remove ]
  445.             then mkdir ${INDIR}/Remove; chmod 755 ${INDIR}/Remove
  446.             fi
  447.             echo "$KEY2 1 $NAME" >> $CONTENTS
  448.             mv ./Remove ${INDIR}/Remove/${KEY2}
  449.             mv ./Name /usr/options/${KEY2}
  450.             if [ -f Files ]
  451.             then
  452.                 mv Files ${INDIR}/Files/${KEY2}
  453.             fi
  454.             sync; sync
  455.             if [ -f /etc/.new_unix ]
  456.             then
  457.                 sync; sync
  458.                 cd /
  459.                 rm -rf ${TMPDIR} ${CPLOG}
  460.                 exec /etc/conf/bin/idreboot
  461.             else
  462.                 message -d "The installation of the \
  463. $NAME is now complete."
  464.             fi
  465.             break
  466.         fi
  467.     fi
  468.     DEVICE=q
  469. done
  470. cd /
  471. rm -rf ${TMPDIR} ${CPLOG}
  472.