SHARE
TWEET

Untitled

a guest Aug 18th, 2018 298 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. ###############################################################################
  4. ###############################################################################
  5. ##
  6. ## name: install.sh
  7. ## author; jim teeuwen [jimteeuwen[at]gmail.com]
  8. ##         mark mcvittie [markcwmcvittie[at]yahoo.co.uk]
  9. ## version 0.8b
  10. ##
  11. ## This script ensures the presence of a number of required packages on the
  12. ## user's system. These packages are needed to make blitzmax run properly.
  13. ##
  14. ## The script supplies (un)installation schemes for various package managers
  15. ## as well as any differences between 32 and 64 bit systems that may require
  16. ## handling.
  17. ##
  18. ## Version history:
  19. ##   [0.8b] Nov 26 2009 [markcw]
  20. ##      - Added libxpm-dev package to aptitude list.
  21. ##   [0.7b] Aug 16 2009 [markcw]
  22. ##      - Added inst_zypper.
  23. ##      - Added package list for inst_pacman.
  24. ##   [0.6b] Aug 9 2009: [markcw]
  25. ##      - Added package lists for inst_emerge, inst_yum and inst_urpmi.
  26. ##      - Added a check for root login.
  27. ##   [0.5b] Aug 6 2009:
  28. ##      - Removed support for ia32-apt-get in the inst_aptitude function.
  29. ##        Apparently this is no longer required to make blitzmax work as well
  30. ##        it causing problems with standard package management on a 64-bit
  31. ##        system.
  32. ##  
  33. ###############################################################################
  34. ###############################################################################
  35.  
  36. ###############################################################################
  37. ## Variables we will be needing later on:
  38. PKGMGRS=("aptitude" "emerge" "yum" "urpmi" "pacman" "zypper");
  39. PKGMGR=
  40. IS_64_BIT=0
  41. DO_INSTALL=1;
  42.  
  43. ###############################################################################
  44. ## usage
  45. usage() {
  46.    echo "Usage: `basename $0` [OPTIONS]";
  47.    echo "";
  48.    echo "   -i    : Install all required packages. (This is the default mode)";
  49.    echo "   -u    : Uninstall all required packages.";
  50.    echo "   -h    : Display this help.";
  51.    echo "";
  52. }
  53.  
  54.  
  55. ###############################################################################
  56. ## Package Manager-specific (un)installation schemes.
  57. inst_aptitude()
  58. {
  59.     if [ $IS_64_BIT -eq 1 ]; then
  60.         PKG_LIST="gcc-multilib g++-multilib libxxf86vm-dev libglu1-mesa-dev x11proto-core-dev x11proto-gl-dev x11proto-kb-dev libasound2-dev libidn11-dev libxft-dev x11proto-xext-dev libxpm-dev";
  61.     else
  62.         PKG_LIST="gcc g++ libxxf86vm-dev libglu1-mesa-dev x11proto-core-dev x11proto-gl-dev x11proto-kb-dev libasound2-dev build-essential libidn11-dev libxft-dev x11proto-xext-dev libxpm-dev";
  63.     fi
  64.  
  65.     if [ $DO_INSTALL -eq 1 ]; then
  66.         echo "[i] Installing...";
  67. #       if [ $IS_64_BIT -eq 1 ]; then
  68. #           ## install ia32-apt-get separately.
  69. #           ## The other packages require this one to be installed and ready.
  70. #           ## 'ia32-apt-get' serves as a 32 bit compatibility tool. It creates
  71. #           ## links to 64 bit versions of the selected packages.
  72. #           sudo apt-get install ia32-apt-get;
  73. #       fi
  74.  
  75.         ## We can pass all of the packages to aptitude in 1 go,
  76.         sudo apt-get install $PKG_LIST;
  77.     else
  78.         echo "[i] Uninstalling...";
  79.         ## We can pass all of the packages to aptitude in 1 go,
  80.         sudo apt-get --purge remove $PKG_LIST;
  81.        
  82. #       if [ $IS_64_BIT -eq 1 ]; then
  83. #           ## uninstall ia32-apt-get separately.
  84. #           sudo apt-get --purge remove ia32-apt-get;
  85. #       fi
  86.        
  87.         ## These 2 commands tell aptitude to clean up any unused packages
  88.         ## still lingering around the system. They make sure we do not leave
  89.         ## any orphaned packages behind. These orphans serve no purpose and
  90.         ## simply waste space.
  91.         echo "[i] Performing aptitude cleanup...";
  92.         sudo apt-get autoremove;
  93.         sudo apt-get autoclean;
  94.     fi
  95.     return $?;
  96. }
  97.  
  98. inst_emerge()
  99. {
  100.     PKG_LIST="libX11 mesa-progs libXft libXpm";
  101.  
  102.     if [ $DO_INSTALL -eq 1 ]; then
  103.         echo "[i] Installing...";
  104.         sudo emerge -a $PKG_LIST;
  105.     else
  106.         echo "[i] Uninstalling...";
  107.         sudo emerge -a --unmerge $PKG_LIST;
  108.     fi
  109.     return $?;
  110. }
  111.  
  112. inst_yum()
  113. {
  114.     PKG_LIST="gcc-c++ libX11-devel mesa-libGLU-devel libXft-devel libXpm-devel";
  115.  
  116.     if [ $DO_INSTALL -eq 1 ]; then
  117.         echo "[i] Installing...";
  118.         yum install $PKG_LIST;
  119.     else
  120.         echo "[i] Uninstalling...";
  121.         yum remove $PKG_LIST;
  122.  
  123.         echo "[i] Performing yum cleanup...";
  124.         yum clean all;
  125.     fi
  126.     return $?;
  127. }
  128.  
  129. inst_urpmi()
  130. {
  131.     PKG_LIST="gcc-c++ libx11_6-devel libmesaglu1-devel libxft-devel libxpm-devel";
  132.  
  133.     if [ $DO_INSTALL -eq 1 ]; then
  134.         echo "[i] Installing...";
  135.         urpmi $PKG_LIST;
  136.     else
  137.         echo "[i] Uninstalling...";
  138.         urpme $PKG_LIST;
  139.     fi
  140.     return $?;
  141. }
  142.  
  143. inst_pacman()
  144. {
  145.     PKG_LIST="gcc";
  146.  
  147.     if [ $DO_INSTALL -eq 1 ]; then
  148.         echo "[i] Installing...";
  149.         pacman -S $PKG_LIST;
  150.     else
  151.         echo "[i] Uninstalling...";
  152.         pacman -Rsn $PKG_LIST;
  153.     fi
  154.     return $?;
  155. }
  156.  
  157. inst_zypper()
  158. {
  159.     PKG_LIST="gcc-c++ xorg-x11-libX11-devel Mesa-devel";
  160.  
  161.     if [ $DO_INSTALL -eq 1 ]; then
  162.         echo "[i] Installing...";
  163.         sudo zypper install $PKG_LIST;
  164.     else
  165.         echo "[i] Uninstalling...";
  166.         sudo zypper remove $PKG_LIST;
  167.     fi
  168.     return $?;
  169. }
  170.  
  171. trap_int()
  172. {
  173.     echo "[i] SIGINT detected. Exiting script.";
  174.     echo "    Note that this may leave some operations incomplete.";
  175.     echo "    Run the script again to complete any pending operations.";
  176.     exit 0;
  177. }
  178.  
  179. ###############################################################################
  180. ###############################################################################
  181. ## Main program
  182.  
  183. ## intercept ctrl-c (SIGINT).
  184. trap trap_int INT;
  185.  
  186. clear;
  187. echo "Blitzmax Installation Script version 0.7b";
  188. echo "Please report bugs or suggestions to: jimteeuwen[at]gmail.com";
  189. echo "";
  190.  
  191.  
  192. ###############################################################################
  193. ## Check for commandline options:
  194. while getopts iuh opt; do
  195.     case "$opt" in
  196.         i) DO_INSTALL=1;;
  197.         u) DO_INSTALL=0;;
  198.         h) usage; exit 0;;
  199.         *?) usage; exit 1;;
  200.     esac
  201. done
  202. unset opt;
  203.  
  204.  
  205. ###############################################################################
  206. ## Get architecture. 64 bit systems require some extra packages
  207. ## since blitz has no 64-bit support. We need our system to provide
  208. ## symbolic links to the 64 bit modules for us.
  209. echo "[i] Checking architecture...";
  210. IS_64_BIT=0;
  211. if [ `uname -m` == "x86_64" ]; then
  212.     IS_64_BIT=1;
  213.     echo "    found: 64 bit";
  214. else
  215.     echo "    found: 32 bit";
  216. fi
  217.  
  218.  
  219. ###############################################################################
  220. ## Determine the package manager we have available.
  221. echo "[i] Identifying package manager...";
  222. PKGMGR="";
  223. for pm in ${PKGMGRS[@]}; do
  224.     if [ ! -f "`which $pm`" ]; then
  225.         continue;
  226.     fi
  227.    
  228.     PKGMGR=$pm;
  229.     echo "    found: $pm";
  230.     break;
  231. done
  232. unset pm;
  233.  
  234. if [ -z "$PKGMGR" ]; then
  235.     echo "[e] Unable to find a package manager.";
  236.     echo "    Supported are: ${PKGMGRS[@]}";
  237. fi
  238.  
  239. ###############################################################################
  240. ## Check if root login is needed.
  241. ## Some distros use su and others use sudo.
  242. ## I am assuming distros using the same package manager use the same su/sudo syntax.
  243. if [ `whoami` = "root" ]; then
  244.     echo "[i] Logged in as root user.";
  245. elif [ "$PKGMGR" = "yum" ]; then ## sudo if user in sudoers
  246.     PKGMGR=""; ## note: using PKGMGR to force root login
  247. elif [ "$PKGMGR" = "pacman" ]; then
  248.     PKGMGR="";
  249. elif [ "$PKGMGR" = "urpmi" ]; then ## no sudo
  250.     PKGMGR="";
  251. fi
  252.  
  253. if [ -z "$PKGMGR" ]; then ## no package manager found or need root login
  254.     echo "[i] Login as root and then re-run this script.";
  255.     su;
  256. fi
  257.  
  258. ###############################################################################
  259. ## perform package manager-specific setup.
  260. ## we simply append the manager name as defined in the array above to 'inst_'.
  261. ## This assumes the resulting function name exists. Note that this is case-
  262. ## sensitive. eg: 'aptitude' becomes a call to function 'inst_aptitude'.
  263. echo "[i] Performing $PKGMGR setup...";
  264. echo "[i] Building package list...";
  265. inst_$PKGMGR;
  266.  
  267.  
  268. ###############################################################################
  269. ## All done. Return control to shell with exit code of last operation.
  270. echo "[i] Done.";
  271. exit $?;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top