Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ###############################################################################
- ###############################################################################
- ##
- ## name: install.sh
- ## author; jim teeuwen [jimteeuwen[at]gmail.com]
- ## mark mcvittie [markcwmcvittie[at]yahoo.co.uk]
- ## version 0.8b
- ##
- ## This script ensures the presence of a number of required packages on the
- ## user's system. These packages are needed to make blitzmax run properly.
- ##
- ## The script supplies (un)installation schemes for various package managers
- ## as well as any differences between 32 and 64 bit systems that may require
- ## handling.
- ##
- ## Version history:
- ## [0.8b] Nov 26 2009 [markcw]
- ## - Added libxpm-dev package to aptitude list.
- ## [0.7b] Aug 16 2009 [markcw]
- ## - Added inst_zypper.
- ## - Added package list for inst_pacman.
- ## [0.6b] Aug 9 2009: [markcw]
- ## - Added package lists for inst_emerge, inst_yum and inst_urpmi.
- ## - Added a check for root login.
- ## [0.5b] Aug 6 2009:
- ## - Removed support for ia32-apt-get in the inst_aptitude function.
- ## Apparently this is no longer required to make blitzmax work as well
- ## it causing problems with standard package management on a 64-bit
- ## system.
- ##
- ###############################################################################
- ###############################################################################
- ###############################################################################
- ## Variables we will be needing later on:
- PKGMGRS=("aptitude" "emerge" "yum" "urpmi" "pacman" "zypper");
- PKGMGR=
- IS_64_BIT=0
- DO_INSTALL=1;
- ###############################################################################
- ## usage
- usage() {
- echo "Usage: `basename $0` [OPTIONS]";
- echo "";
- echo " -i : Install all required packages. (This is the default mode)";
- echo " -u : Uninstall all required packages.";
- echo " -h : Display this help.";
- echo "";
- }
- ###############################################################################
- ## Package Manager-specific (un)installation schemes.
- inst_aptitude()
- {
- if [ $IS_64_BIT -eq 1 ]; then
- 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";
- else
- 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";
- fi
- if [ $DO_INSTALL -eq 1 ]; then
- echo "[i] Installing...";
- # if [ $IS_64_BIT -eq 1 ]; then
- # ## install ia32-apt-get separately.
- # ## The other packages require this one to be installed and ready.
- # ## 'ia32-apt-get' serves as a 32 bit compatibility tool. It creates
- # ## links to 64 bit versions of the selected packages.
- # sudo apt-get install ia32-apt-get;
- # fi
- ## We can pass all of the packages to aptitude in 1 go,
- sudo apt-get install $PKG_LIST;
- else
- echo "[i] Uninstalling...";
- ## We can pass all of the packages to aptitude in 1 go,
- sudo apt-get --purge remove $PKG_LIST;
- # if [ $IS_64_BIT -eq 1 ]; then
- # ## uninstall ia32-apt-get separately.
- # sudo apt-get --purge remove ia32-apt-get;
- # fi
- ## These 2 commands tell aptitude to clean up any unused packages
- ## still lingering around the system. They make sure we do not leave
- ## any orphaned packages behind. These orphans serve no purpose and
- ## simply waste space.
- echo "[i] Performing aptitude cleanup...";
- sudo apt-get autoremove;
- sudo apt-get autoclean;
- fi
- return $?;
- }
- inst_emerge()
- {
- PKG_LIST="libX11 mesa-progs libXft libXpm";
- if [ $DO_INSTALL -eq 1 ]; then
- echo "[i] Installing...";
- sudo emerge -a $PKG_LIST;
- else
- echo "[i] Uninstalling...";
- sudo emerge -a --unmerge $PKG_LIST;
- fi
- return $?;
- }
- inst_yum()
- {
- PKG_LIST="gcc-c++ libX11-devel mesa-libGLU-devel libXft-devel libXpm-devel";
- if [ $DO_INSTALL -eq 1 ]; then
- echo "[i] Installing...";
- yum install $PKG_LIST;
- else
- echo "[i] Uninstalling...";
- yum remove $PKG_LIST;
- echo "[i] Performing yum cleanup...";
- yum clean all;
- fi
- return $?;
- }
- inst_urpmi()
- {
- PKG_LIST="gcc-c++ libx11_6-devel libmesaglu1-devel libxft-devel libxpm-devel";
- if [ $DO_INSTALL -eq 1 ]; then
- echo "[i] Installing...";
- urpmi $PKG_LIST;
- else
- echo "[i] Uninstalling...";
- urpme $PKG_LIST;
- fi
- return $?;
- }
- inst_pacman()
- {
- PKG_LIST="gcc";
- if [ $DO_INSTALL -eq 1 ]; then
- echo "[i] Installing...";
- pacman -S $PKG_LIST;
- else
- echo "[i] Uninstalling...";
- pacman -Rsn $PKG_LIST;
- fi
- return $?;
- }
- inst_zypper()
- {
- PKG_LIST="gcc-c++ xorg-x11-libX11-devel Mesa-devel";
- if [ $DO_INSTALL -eq 1 ]; then
- echo "[i] Installing...";
- sudo zypper install $PKG_LIST;
- else
- echo "[i] Uninstalling...";
- sudo zypper remove $PKG_LIST;
- fi
- return $?;
- }
- trap_int()
- {
- echo "[i] SIGINT detected. Exiting script.";
- echo " Note that this may leave some operations incomplete.";
- echo " Run the script again to complete any pending operations.";
- exit 0;
- }
- ###############################################################################
- ###############################################################################
- ## Main program
- ## intercept ctrl-c (SIGINT).
- trap trap_int INT;
- clear;
- echo "Blitzmax Installation Script version 0.7b";
- echo "Please report bugs or suggestions to: jimteeuwen[at]gmail.com";
- echo "";
- ###############################################################################
- ## Check for commandline options:
- while getopts iuh opt; do
- case "$opt" in
- i) DO_INSTALL=1;;
- u) DO_INSTALL=0;;
- h) usage; exit 0;;
- *?) usage; exit 1;;
- esac
- done
- unset opt;
- ###############################################################################
- ## Get architecture. 64 bit systems require some extra packages
- ## since blitz has no 64-bit support. We need our system to provide
- ## symbolic links to the 64 bit modules for us.
- echo "[i] Checking architecture...";
- IS_64_BIT=0;
- if [ `uname -m` == "x86_64" ]; then
- IS_64_BIT=1;
- echo " found: 64 bit";
- else
- echo " found: 32 bit";
- fi
- ###############################################################################
- ## Determine the package manager we have available.
- echo "[i] Identifying package manager...";
- PKGMGR="";
- for pm in ${PKGMGRS[@]}; do
- if [ ! -f "`which $pm`" ]; then
- continue;
- fi
- PKGMGR=$pm;
- echo " found: $pm";
- break;
- done
- unset pm;
- if [ -z "$PKGMGR" ]; then
- echo "[e] Unable to find a package manager.";
- echo " Supported are: ${PKGMGRS[@]}";
- fi
- ###############################################################################
- ## Check if root login is needed.
- ## Some distros use su and others use sudo.
- ## I am assuming distros using the same package manager use the same su/sudo syntax.
- if [ `whoami` = "root" ]; then
- echo "[i] Logged in as root user.";
- elif [ "$PKGMGR" = "yum" ]; then ## sudo if user in sudoers
- PKGMGR=""; ## note: using PKGMGR to force root login
- elif [ "$PKGMGR" = "pacman" ]; then
- PKGMGR="";
- elif [ "$PKGMGR" = "urpmi" ]; then ## no sudo
- PKGMGR="";
- fi
- if [ -z "$PKGMGR" ]; then ## no package manager found or need root login
- echo "[i] Login as root and then re-run this script.";
- su;
- fi
- ###############################################################################
- ## perform package manager-specific setup.
- ## we simply append the manager name as defined in the array above to 'inst_'.
- ## This assumes the resulting function name exists. Note that this is case-
- ## sensitive. eg: 'aptitude' becomes a call to function 'inst_aptitude'.
- echo "[i] Performing $PKGMGR setup...";
- echo "[i] Building package list...";
- inst_$PKGMGR;
- ###############################################################################
- ## All done. Return control to shell with exit code of last operation.
- echo "[i] Done.";
- exit $?;
Add Comment
Please, Sign In to add comment