home *** CD-ROM | disk | FTP | other *** search
/ Chip: Linux Special / CorelLinux_CHIP.iso / VMware / etc / installer.sh
Encoding:
Linux/UNIX/POSIX Shell Script  |  1999-11-10  |  3.6 KB  |  163 lines

  1. #!/bin/sh
  2. # Tar installer object
  3. #
  4. # This file is saved on the disk when the .tar package is installed by
  5. # vmware-install.pl. It can be invoked by any installer.
  6.  
  7. #
  8. # Global variables
  9. #
  10.  
  11. vmware_db='/etc/vmware/locations'
  12. vmware_db_tmp='/etc/vmware/locations.tmp'
  13.  
  14. #
  15. # Tools
  16. #
  17.  
  18. # Load an answer from the database
  19. db_load_answer() {
  20.     id="$1"
  21.  
  22.     grep '^remove_answer '"$id"'$\|^answer '"$id"' ' "$vmware_db" | tail -1 | sed -n 's/^answer '"$id"' //p'
  23. }
  24.  
  25. # Load the database in the db_* variables
  26. db_load() {
  27.     db_answers=''
  28.     if [ -r "$vmware_db" ]; then
  29.         for i in `sed -n -e 's/^answer \(.*\) .*/\1/p' "$vmware_db"`; do
  30.             value=`db_load_answer "$i"`
  31.             if [ "$value" != '' ]; then
  32.                 eval 'db_answer_'"$i"'="$value"'
  33.                 db_answers="$db_answers"' '"$i"' '
  34.             fi
  35.         done
  36.     fi
  37. }
  38.  
  39. #
  40. # Implementation of the methods
  41. #
  42.  
  43. # Return the human-readable name of the installer
  44. installer_kind() {
  45.     echo 'tar'
  46.  
  47.     exit 0
  48. }
  49.  
  50. # Convert the installer database format to formats used by older installers
  51. # The output should be a .tar.gz containing enough information to allow a
  52. # clean "upgrade" (which will actually be a downgrade) by an older installer
  53. installer_convertdb() {
  54.     version="$1"
  55.     output="$2"
  56.  
  57.     case "$version" in
  58.         tar)
  59.             echo 'Keeping the tar installer database format.'
  60.         echo
  61.             # Same format. Nothing to do.
  62.             tar -czopf "$output" "$vmware_db" 2> /dev/null
  63.  
  64.             exit 0
  65.         ;;
  66.  
  67.         rpm)
  68.             echo 'Converting the tar installer database format'
  69.             echo '        to the rpm installer database format.'
  70.         echo
  71.             # Same format. Nothing to do.
  72.             tar -czopf "$output" "$vmware_db" 2> /dev/null
  73.  
  74.             exit 0
  75.         ;;
  76.  
  77.         old)
  78.             echo 'Converting the tar installer database format'
  79.             echo '        to the old installer database format.'
  80.         echo
  81.             db_load
  82.             # Backup the existing db
  83.             cp "$vmware_db" "$vmware_db_tmp"
  84.             # Write the converted db
  85.             rm -f "$vmware_db"
  86.             for i in $db_answers; do
  87.                 eval 'value="$db_answer_'"$i"'"'
  88.                 if [ "$i" = 'BUILDR_vmmon' ]; then
  89.                     i='BUILDR_driver'
  90.                 fi
  91.                 echo 'answer '"$i"' '"$value" >> "$vmware_db"
  92.             done
  93.             # Make the old uninstaller look good
  94.             echo 'VERSION 1.1.2' >> "$vmware_db"
  95.             # Now pack the converted db
  96.             tar -czopf "$output" "$vmware_db" 2> /dev/null
  97.             # And restore the current db
  98.             mv "$vmware_db_tmp" "$vmware_db"
  99.  
  100.             exit 0
  101.         ;;
  102.  
  103.         *)
  104.         echo 'Unknown '"$version"' installer database format.'
  105.         echo
  106.  
  107.             exit 1
  108.         ;;
  109.     esac
  110. }
  111.  
  112. # Uninstall what has been installed by the installer.
  113. # This should never prompt the user, because it can be annoying if invoked
  114. # from the rpm installer for example.
  115. installer_uninstall() {
  116.     echo 'Uninstalling the tar installation of VMware.'
  117.     echo
  118.  
  119.     bindir=`db_load_answer 'BINDIR'`
  120.     if [ "$bindir" = '' ]; then
  121.         echo 'Error: Unable to find the binary installation directory (answer BINDIR)'
  122.         echo '       in '"$vmware_db"'.'
  123.     echo
  124.  
  125.         exit 1
  126.     fi
  127.  
  128.     # Remove the package
  129.     if [ ! -x "$bindir"/vmware-uninstall.pl ]; then
  130.         exit 1
  131.     fi
  132.     "$bindir"/vmware-uninstall.pl || exit 1
  133.     
  134.  
  135.     exit 0
  136. }
  137.  
  138. #
  139. # Interface of the methods
  140. #
  141.  
  142. case "$1" in
  143.     kind)
  144.     installer_kind
  145.     ;;
  146.  
  147.     convertdb)
  148.     installer_convertdb "$2" "$3"
  149.     ;;
  150.  
  151.     uninstall)
  152.     installer_uninstall
  153.     ;;
  154.  
  155.     *)
  156.     echo 'Usage: '`basename "$0"`' {kind|convertdb|uninstall}'
  157.     echo
  158.  
  159.     exit 1
  160.     ;;
  161. esac
  162.  
  163.