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 / removepkg.r < prev   
Encoding:
Text File  |  1988-06-26  |  4.9 KB  |  228 lines

  1. :
  2. #
  3. #ident    "@(#)pkging:removepkg.r    1.2.2.7"
  4. #
  5. # PURPOSE: Delete installed software
  6. # ----------------------------------------------------------------------
  7. FILE=/tmp/R$$
  8. trap 'rm -rf ${FILE}; exit 1' 1 2 3 9 15
  9.  
  10. # Check if root is performing the operation
  11. id | grep "(root)" > /dev/null
  12. if [ "$?" = "0" ]
  13. then
  14.     id | grep "euid=" > /dev/null
  15.     if [ "$?" = "0" ] #Did get root above; no euid string
  16.     then
  17.         id | grep "euid=0(root)" > /dev/null
  18.         if [ "$?" = 0 ]
  19.         then
  20.             UID=0
  21.         else
  22.             UID=1
  23.         fi
  24.     else
  25.         UID=0
  26.     fi
  27. else
  28.     UID=1
  29. fi
  30. if [ "$UID" != 0 ]
  31. then echo "You must be root or super-user to remove software."
  32.      exit 1
  33. fi
  34.  
  35. if [ -z "$TERM" ]
  36. then TERM=AT386-M
  37. fi
  38. CLEAR=`tput clear 2>/dev/null`
  39.  
  40. ERROR5="There are currently no software applications installed that can be removed."
  41.  
  42. CONTENTS=/usr/lib/installed/CONTENTS
  43. INDIR=/usr/lib/installed
  44.  
  45. if [ ! -d /usr/options ]
  46. then
  47.     echo "$ERROR5"
  48.     exit 1
  49. fi
  50. cd /usr/options
  51.  
  52. if [ $# = 0 ]
  53. then
  54.     list=`ls *.name 2>/dev/null`
  55.     if [ -z "$list" ]
  56.     then
  57.         echo "$ERROR5"
  58.         exit 1
  59.     fi
  60.     for i in *
  61.     do
  62.         echo "$i\t\c"
  63.         cat $i | sed -e "/^$/d"
  64.     done > ${FILE}
  65.     max=`expr \`cat $FILE | wc -l\``
  66.     if [ $max -lt 1 ]
  67.     then
  68.         echo "$ERROR5"
  69.         exit 1
  70.     fi
  71.     while [ 1 ]
  72.     do
  73.         pr -n -l1 -t ${FILE} | cut -d'    ' -f1,3-
  74.         max=`expr \`cat $FILE | wc -l\``
  75.         echo "\nSelect a number (1 - $max) from this list to remove: \c"
  76.         read index
  77.         expr $index \* 20 > /dev/null 2>&1
  78.         if [ $? != 0 ]
  79.         then echo "That number is invalid.  Please specify a number between 1 and $max."
  80.              continue
  81.         elif [ $index -gt $max ]
  82.         then echo "That number is too large.  Please specify a number between 1 and $max."
  83.              continue
  84.         elif [ $index -lt 1 ]
  85.         then echo "That number is too small.  Please specify a number between 1 and $max."
  86.              continue
  87.         else break
  88.         fi
  89.     done
  90.     PROG=`sed -n "${index}p" $FILE | cut -d'    ' -f1 | sed -e "s/\.name//`
  91.     rm -rf ${FILE}
  92. else
  93.     NAME=`echo ${1} | tr "[A-Z]" "[a-z]"`
  94.     if [ -f ${NAME}.name ]
  95.     then PROG=$NAME
  96.     else
  97.         for i in *
  98.         do
  99.             grep -i "$NAME" $i > /dev/null 2>&1
  100.             if [ $? = 0 ]
  101.             then PROG=`echo $i | sed -e 's/\.name//'`
  102.                  break
  103.             fi
  104.         done
  105.         if [ -z "$PROG" ]
  106.         then echo "\nThere is no software package currently installed\nresembling: $1\n"
  107.              exit 1
  108.         fi
  109.     fi
  110. fi
  111.  
  112. cd /
  113. KEY=${PROG}.name
  114. NAME=`cat /usr/options/${PROG}.name`
  115. grep $PROG $CONTENTS > /dev/null 2>&1
  116. if [ $? = 0 ]
  117. then
  118.  
  119. message -c "Do you really want to remove $NAME?"
  120. if [ "$?" != "0" ]; then exit; fi
  121.     trap '' 1 2 3 9 15
  122. export KEY NAME
  123.  
  124. UNFILE=${INDIR}/Remove/${KEY}
  125. if [ -r "$UNFILE" ]
  126. then
  127.     chmod +x $UNFILE
  128.     echo "$CLEAR "
  129.     $UNFILE
  130.     if [ $? = "0" ]
  131.     then
  132.         sync; sync
  133.         grep -v "^$KEY " $CONTENTS > /tmp/$$
  134.         mv /tmp/$$ $CONTENTS
  135.         rm $UNFILE
  136.         rm -f ${INDIR}/Files/${KEY} /usr/options/${KEY}
  137.         sync; sync; sync
  138.         echo "$CLEAR "
  139.         if [ -f /etc/.new_unix ]
  140.         then
  141.             sync; sync
  142.             exec /etc/conf/bin/idreboot
  143.         else
  144.             message -d "The $NAME is now removed."
  145.         fi
  146.         exit
  147.     fi
  148.     exit
  149. else
  150.     if [ -f ${INDIR}/Files/${KEY} ]
  151.     then FILES_MESS="  The file ${INDIR}/Files/${KEY} contains a list of the \
  152. files and directories installed or created by the package.  You may wish to use this \
  153. file to help in removing the package."
  154.     fi
  155.     message -d "Cannot find removal script for $NAME.  You will have to \
  156. remove this package manually using UNIX System tools from the UNIX System Shell.${FILES_MESS}"
  157. fi
  158. else
  159.  
  160. /etc/mount | grep "^/install" > /dev/null 2>&1
  161. if [ $? = 0 ]
  162. then
  163.     message -d "Cannot remove ${NAME}.  The /install directory is currently \
  164. mounted.  Please unmount /install and then try again."
  165.     exit 1
  166. fi
  167.  
  168. MES1=
  169. MSG=
  170. /bin/dd if=/dev/rdsk/f1t count=1 2>&1 |     \
  171.     grep "No such device" 2>&1 > /dev/null
  172. if [ $? != 0 ]
  173. then
  174.     while true
  175.     do
  176.         echo "\nThis system has two floppy drives.\n\
  177. Strike ENTER to remove from drive 0\n\
  178. or 1 to remove from drive 1.  \c"
  179.         read ans
  180.         if [ "$ans" = 1 ]
  181.         then
  182.             DRIVE=/dev/dsk/f1
  183.             break
  184.         elif [ "$ans" = "" -o "$ans" = 0 ]
  185.         then
  186.             DRIVE=/dev/dsk/f0
  187.             break
  188.         fi
  189.     done
  190. else
  191.     DRIVE=/dev/dsk/f0
  192. fi
  193. while [ 1 ]
  194. do
  195. message -c "${MSG}Insert the removable medium for the $NAME you wish to remove."
  196. if [ "$?" != "0" ]; then exit; fi
  197. /etc/mount $DRIVE /install -r > /dev/null 2>&1
  198. if [ $? = 0 ]
  199. then 
  200.      /etc/umount /install > /dev/null 2>&1
  201.      break
  202. fi
  203.  
  204. MSG="Cannot determine the type of floppy.\n"
  205. done
  206. /etc/mount ${DRIVE} /install -r > /dev/null 2>&1
  207. if [ ! -r /install/install/UNINSTALL ]
  208. then echo >&2 '\tThis package will not remove itself.  Consult the instructions \
  209. that came with the medium.'
  210.      /etc/umount /install > /dev/null 2>&1
  211. fi
  212. trap "trap '' 1 2 3 9 15; cd /; rm -rf /tmp/$$UNINSTALL; /etc/umount /install; exit 1" 1 2 3
  213. cd /tmp
  214. cp /install/install/UNINSTALL $$UNINSTALL
  215. chmod +x $$UNINSTALL
  216. /tmp/$$UNINSTALL ${DRIVE} /install "`basename ${DRIVE}` drive" ||
  217.     echo 'WARNING:  Package removal may not have completed properly.'
  218. trap '' 1 2 3
  219. cd /
  220. rm -rf /tmp/$$UNINSTALL
  221. /etc/umount /install > /dev/null 2>&1
  222. if [ -f /etc/.new_unix ]
  223. then
  224.     sync; sync
  225.     exec /etc/conf/bin/idreboot
  226. fi
  227. fi
  228.