home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 April / Chip_2001-04_cd2.bin / Linux / CorelPHOTOPAINT9LnxRPM.tar.gz / CorelPHOTOPAINT9LnxRPM.tar / remove-graphics9 < prev    next >
Text File  |  2000-06-22  |  10KB  |  332 lines

  1. #!/bin/sh
  2. # uninstaller for Graphics 9
  3. # Copyright 1999-2000 Corel Corporation
  4.  
  5. # Original Author: M Dickson.
  6. # Ongoing Authors: <recorded in CVS>
  7. # $Id: remove-graphics9,v 1.6 2000/06/22 19:24:36 albertd Exp $
  8.  
  9. # Thanks to:
  10. #    J Aston for the disk space detection
  11. #    A denHaan for feedback and help with dpkg and apt-get
  12. #    D Meisenheimer for showing me how cool unattended ftp can be
  13. #    J Tranter for an easier way of determining the c library
  14. #    C Gorman for a more stable way of determining the c library 
  15. #    C James for giving me a kick in the pants
  16. #    K Wong and his team for finding all the "undesired features"
  17. #-----------------------------------------------------------------------
  18. # Caveats
  19. #    Eterm seems not to like the way I clear lines
  20. #    the grep on the filename for rpm is a bit globbish
  21. #------------------------------------------------------------------------
  22.  
  23. #------------------------------------------------------------------------
  24. currentVersion="0.9"
  25. #------------------------------------------------------------------------
  26. #------G L O B A L   V A R I A B L E S-----------------------------------
  27.     # A listing of all the packages in beta 1.
  28. betaOnePackageList="graphics graphics9-help-draw graphics9-help-paint \
  29.     graphics9-help-techsupport libwine-dev-gfx9 libwine-dev-gfx9 \
  30.     wine-gfx9 wine-tools-gfx9 libwine-gfx9 wine-doc-gfx9"
  31.  
  32.     # A listing of all the packages in beta 2
  33. betaTwoPackageList="graphics9-draw graphics9-help-common \
  34.     graphics9-help-draw graphics9-help-paint graphics9-help-techsupport \
  35.     graphics9-help-writingtools graphics9-paint graphics9-common \
  36.     libwine-dev-graphics9 wine-graphics9 wine-tools-graphics9 \
  37.     libwine-graphics9 wine-doc-graphics9 "
  38.  
  39.     # the amalgamated list
  40. fullPkgRemoveList="$betaOnePackageList $betaTwoPackageList"
  41.  
  42.     # How many packages are listed above?
  43.     # 13beta2 + 10beta1
  44. numPkgs=23
  45.  
  46.     # these are the packages that have a glibc version attached
  47. libcDepList="wine-graphics9 libwine-dev-graphics9 libwine-graphics9 fonttastic \
  48.     wine-tools-graphics9 libwine-dev-gfx9 libwine-dev-gfx9 libwine-gfx9 \
  49.     wine-gfx9 wine-tools-gfx9 "
  50.  
  51.     # rpm or dpkg?
  52. type=none;
  53.  
  54.     # this gets set to dontRemoveIfWPO2000List if wpo2000 is not installed.
  55. alsoRemove=" ";
  56.  
  57.     # these files should not be removed if WPO2000 is also on the system.
  58. dontRemoveIfWPO2000List=" libaps-dev fonttastic wpo2000-fonts-core "
  59.  
  60.     # How many files are listed above?
  61. dontRemoveNum=3;
  62.  
  63.     # This flag indicates whether a whack of directories should be removed.
  64.     # Set to 0 (no) by defualt, only reset to 1 if wpo2000 is not found
  65. cleanSystem=0;
  66.  
  67.     # These two turn bold text on and off
  68. bon="\33[1m"
  69. boff="\33[0m"
  70.  
  71.     # Error Strings
  72.     # Each error condition is given a string here.  Then, when
  73.     #  error() is used, the correct string is printed.
  74. error2="You must be root to install this software."
  75. error3="No package manager found."
  76. error4="libc6 is not installed."
  77. error8="This is not a Linux system!"
  78. error13="Only libc6 versions 2.0 and 2.1 are supported.  Neither are installed."
  79. error99="Unknown error has occured.  Please call Albert at x5318"
  80.  
  81.     # realias echo to handle special characters, which it doesn't
  82.     #  do by default
  83. ECHO="echo -e"
  84.  
  85. currentUID=""
  86. #---------------------------------------------------------------------------
  87. #-----F U N C T I O N S-----------------------------------------------------
  88. # clearLine
  89. clearLine ()
  90.     {
  91.     clearCount=80;
  92.     if [ ! -z "$1" ] ; then
  93.         clearCount=$1;
  94.     fi
  95.     clearStatus=`expr $clearCount \> 0`
  96. #    while [ $clearStatus -eq 1 ] ; do
  97. #        echo -en "\b \b"
  98. #        clearCount=`expr $clearCount - 1`
  99. #        clearStatus=`expr $clearCount \> 0`
  100. #    done
  101.     while [ $clearCount -gt 0 ] ; do
  102.         echo -en "\b \b"
  103.         clearCount=`expr $clearCount - 1`
  104.     done
  105.     }
  106.  
  107.  
  108. #---------------------------------------------------------------------------
  109. #generic error handler. Takes 1 required and 1 optional arguement
  110. # First arguement is a number, corresponding to an error message as listed
  111. #  above.
  112. # Second arguement is one of:
  113. #    blank : nothing happens
  114. #    usage : usage message gets printed out
  115. #    text  : the supplied text gets printed out  
  116. error ()
  117.     {
  118.     t=error$1
  119.     eval $ECHO "\${bon}*****\\\nERROR\${boff}\\\n\$$t"
  120.     if [ ! -z  "$2" ] ; then
  121.         if [ $2 = "usage" ] ; then 
  122.             $ECHO $usage ; 
  123.         fi
  124.     else
  125.         eval $ECHO "$2";
  126.     fi
  127.     exit 1
  128.     } 
  129.  
  130. #-----------------------------------------------------------------------------
  131. # Performs all the required system checks:
  132. #    user is root
  133. #    system is Linux
  134. #    libc6 is installed
  135. #    a package manager is installed
  136. # If any of these fail, the whole script fails.
  137. systemChecks ()
  138.     {
  139.     $ECHO "${bon}Beginning System Checks:${boff}"
  140.     #-----Check for Linux system---------
  141.     $ECHO -n "  Checking for a Linux system..."
  142.     if [ ! `uname -s | egrep -e "inux"` ] ; then
  143.         error 8 '`uname -s` was found';
  144.     fi
  145.     $ECHO " OK Found one.  Whew!! ;)"
  146.  
  147.     #-----Check for root---------
  148. #    $ECHO -n "  Checking for root UID..."
  149. #    id | egrep "root" > /dev/null 2>/dev/null;
  150. #    if [ "$?" != 0 ]; then
  151. #        error 2
  152. #    fi
  153. #    $ECHO " OK (Current user is root)"
  154.     
  155.     #-----Check for WPO2000---------------
  156.     $ECHO -n "  Checking for WPO2000...";
  157.     if [ -f /usr/lib/corel/bin/wpolauncher ] || [ -d /usr/lib/corel/wpo ] ; then
  158.         $ECHO "found. $dontRemoveIfWPO2000List will not be removed."
  159.     else
  160.         alsoRemove=$dontRemoveIfWPO2000List;
  161.         numPkgs=`expr $numPkgs + $dontRemoveNum` ;
  162.         cleanSystem=1;
  163.         $ECHO "not found."
  164.     fi
  165.     
  166.     #-----Check for Package Manager-------
  167.     $ECHO -n "  Checking for package manager...";
  168.     
  169.     dpkg -h > /dev/null 2>/dev/null;
  170.     if [ $? -eq 0 ] ; then
  171.         type=dpkg;
  172.     else
  173.         rpm -v > /dev/null 2>/dev/null;
  174.         if [ $? -eq 0 ] ; then
  175.             type=rpm;
  176.         fi
  177.     fi
  178.     if [ $type = "none" ] ; then
  179.         error 3
  180.     fi
  181.  
  182.     $ECHO " OK (found $type at `which $type`)";
  183.  
  184.     #-----Check for correct libc ------
  185.     $ECHO -n "  Checking for proper C library..."
  186.     if [ -f /lib/libc.so.6 ] ; then
  187.         versionNumber=`strings /lib/libc.so.6 | grep "GNU C Library" | awk '{print $7}' | cut -c 1-3`;
  188.         if [ $versionNumber != "2.0" -a $versionNumber != "2.1" ] ; then 
  189.             error 13;
  190.         else 
  191.             libcVer="glibc-$versionNumber";
  192.             $ECHO " OK (found $libcVer)";
  193.         fi
  194.     else
  195.         error 4
  196.     fi
  197.  
  198.  
  199.     $ECHO "  System checks passed."
  200.     }
  201.  
  202. #-----------------------------------------------------------------------------
  203. # Remove the packages from your system.  Very brute force and unoptomized.
  204. # Also removes the directories /usr/lib/corel, /var/lib/corel and 
  205. # /usr/doc/wpohelpfiles
  206. removePackages ()
  207.     {
  208.     $ECHO "${bon}Removing Corel Graphics 9, $numPkgs packages to check.${boff}"
  209.     $ECHO  "  Removal Progress:"
  210.     num=$numPkgs;
  211.     if [ $type = "rpm" ] ; then
  212.         for pkg in $fullPkgRemoveList $alsoRemove; do
  213. #            $ECHO -n "."
  214.             for test in $libcDepList ; do
  215.                 if [ $test = $pkg ] ; then
  216. #                    echo -n "$pkg ->";
  217.                     pkg="$pkg-$libcVer";
  218. #                    echo "$pkg"
  219.                 fi
  220.             done;
  221. #            clearLine
  222.             $ECHO -n "\n    Checking for #${num}: ${bon}$pkg${boff}..."
  223.              $type -qa | grep "^$pkg"  > /dev/null 2>&1
  224.             if [ "$?" -eq 0 ] ; then
  225.                 $ECHO -n "Found. Removing it."
  226.                 $type $REMOVE $pkg > /dev/null 2>&1
  227.             fi
  228.             num=`expr $num - 1`;
  229. #        $ECHO "";
  230.         done
  231.     else
  232.         for pkg in  $fullPkgRemoveList $alsoRemove; do
  233.             for test in $libcDepList ; do
  234.                 if [ $test = $pkg ] ; then
  235. #                    echo -n "$pkg ->";
  236.                     pkg="$pkg-$libcVer";
  237. #                    echo "$pkg"
  238.                 fi
  239.             done;
  240.             $ECHO -n "."
  241. #            $ECHO "$pkg"
  242. #            clearLine
  243.             $ECHO -n "\n    Removing #${num}: ${bon}$pkg${boff} if installed."
  244.             $type $REMOVE $pkg $pkg > /dev/null 2>&1
  245.             num=`expr $num - 1`;
  246.         done
  247.     fi
  248. #    clearLine
  249.     $ECHO "\n  Package removal complete.";
  250.  
  251.     if [ -n "$BRUTALLY_REMOVE_GRAPHICS9" ]
  252.     then
  253.         $ECHO -n "  Cleaning up leftover directories..."    
  254.         rm -rf /usr/lib/corel/wine-graphics9
  255.         if [ $cleanSystem -eq 1 ] ; then
  256.             rm -rf /usr/lib/corel
  257.             rm -rf /var/lib/corel
  258.             rm -rf /usr/doc/wpohelpfiles
  259.             rm -rf /etc/fonttastic
  260.             $ECHO "done."
  261.             sleep 1;
  262.         fi
  263.     fi
  264. #    clearLine
  265.     $ECHO "Corel Graphics Application removal complete."
  266.     }
  267.  
  268.  
  269. #
  270. #-----------------------------------------------------------------------------
  271. # get the current username based on the UID
  272. checkUID () 
  273.     {
  274.     grep "^[^:]*:[^:]*:$1" /etc/passwd | cut -f1 -d:
  275.     }
  276.  
  277. #==============================================================================
  278. #=====S C R I P T   S T A R T==================================================
  279. clear
  280. $ECHO "remove-graphics9 v$currentVersion\n"
  281. $ECHO "This script will remove all Corel Graphics 9 packages from this system."
  282.     #-----Check for root---------
  283. currentUID=$(checkUID $(id -u))
  284.  
  285. if [ $currentUID != "root" ] ; then
  286.     $ECHO "\n  ****************************************************"
  287.     $ECHO "  * You will require the root password to complete   *"
  288.     $ECHO "  * the removal of the Corel Graphics Suite.  If you *"
  289.     $ECHO "  * don't know the root password, hit ctrl-c now to  *"
  290.     $ECHO "  * cancel this script.                              *"
  291.     $ECHO "  ****************************************************\n"
  292.     $ECHO "\n  Please enter the root password at the prompt."
  293.     while ! xterm -e su root -c "$0" ; do
  294.         clearLine
  295.         $ECHO -n "Incorrect password.  Try again? (y/n) >"
  296.         read response;
  297.         if [ $response != "y" ] && [ $response != "Y" ]  ; then
  298.             clearLine
  299.             $ECHO "Please try again when you know the root password."
  300.             exit;
  301.         fi
  302.         clearLine
  303.         $ECHO "\n  Please enter the root password at the prompt."
  304.         done
  305.     exit;
  306. fi
  307.  
  308. $ECHO "hit <ctrl-c> now to abort."
  309. for i in 5 4 3 2 1 ; do
  310.     $ECHO -n "$i "
  311.     sleep 1
  312. done;
  313. clearLine 10
  314. $ECHO "Onward..."
  315.  
  316.     #perform all system checks
  317. systemChecks;
  318.  
  319. if [ $type = "rpm" ] ; then
  320.     REMOVE="-e --allmatches --nodeps";
  321. elif [ $type = "dpkg" ] ; then
  322.     REMOVE="--purge --ignore-depends"
  323. fi
  324.  
  325. removePackages;
  326.  
  327. if [ -x /usr/bin/update-menus ] ; then /usr/bin/update-menus ; fi
  328.  
  329. $ECHO "\n\n${bon}All Done!${boff}\n"
  330.  
  331. exit;
  332.