Mar 112016
 

So I saw some posts on xkcd universal installer and it drove me crazy that it wasn’t done correctly…..therefore, we now have this

FYI, what if ‘two installers had packages with same name?”

 

#!/bin/bash
#===============================================================================
#
#          FILE:  universal_installer_improved.sh
# 
#         USAGE:  ./universal_installer_improved.sh 1 name
# 
#   DESCRIPTION:  based on https://imgs.xkcd.com/comics/universal_install_script.png
#                 https://xkcd.com/1654/
#       OPTION 1: passes installer type
#       OPTION 2: passes package name, url, etc 
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  Ed Wiget (), [email protected]
#       COMPANY:  
#       VERSION:  1.0
#       CREATED:  03/11/2016 11:58:15 AM EST
#      REVISION:  ---
#===============================================================================
 
if [ $# -ne 2 ]; then
	echo
	echo "    Usage: ${0} <type> {package name[1-11], dir[13], url[14]}"
	echo "       ie. ${0} 5 php-fpm"
	echo 
	echo "types follow..........."
	echo
	echo "1 pip install"
	echo "2 easy_install"
	echo "3 brew install"
	echo "4 npm install"
	echo "5 yum install"
	echo "6 dnf install"
	echo "7 docker run"
	echo "8 pkg install"
	echo "9 apt-get install"
	echo "10 sudo apt-get install"
	echo "11 steamcmd +app_update"
	echo "12 git clone"
	echo "13 make"
	echo "14 curl"
	exit 1
fi
 
if [ "$1" == "" ]; then
        echo    
        echo "types follow..........."
        echo    
        echo "1 pip install"
        echo "2 easy_install"
        echo "3 brew install"
        echo "4 npm install"
        echo "5 yum install"
	echo "6 dnf install"
        echo "7 docker run"
        echo "8 pkg install"
        echo "9 apt-get install"
        echo "10 sudo apt-get install"
        echo "11 steamcmd +app_update"
        echo "12 git clone"
        echo "13 make"
        echo "14 curl"
	echo 
	echo "What type do you wish to use?"
	read ITYPE
else
	ITYPE=$1
fi
 
case $ITYPE in
  1)
    CMD="pip install $2"
    ;;
  2)
    CMD="easy_install $2"
    ;;
  3)
    CMD="brew install $2"
    ;;
  4)
    CMD="npm install $2"
    ;;
  5)
    CMD="yum install $2"
    ;;
  6)
    CMD="dnf install $2"
    ;;
  7)
    CMD="docker run $2"
    ;;
  8)
    CMD="pkg install $2"
    ;;
  9)
    CMD="apt-get install $2"
    ;;
  10)
    CMD="sudo apt-get install $2"
    ;;
  11)
    CMD="steamcmd +app_update $2 validate"
    ;;
  12)
    CMD="git clone https://github.com/$2/$2"
    ;;
  14)
    CMD="cd $2; ./configure ; make ; make install"
    ;;
  15)
    CMD="curl $2 | bash"
    ;;
  *)
    echo "Not a valid choice luser"
    exit
    ;;
esac
 
exec ${CMD}

 

You might ask, does it really work?  Well, it did for this test ….

$ ./universal_installer_improved.sh 10 php-fpm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  php-common php7.0-cli php7.0-common php7.0-fpm php7.0-json php7.0-opcache php7.0-readline
Suggested packages:
  php-pear php-user-cache
The following NEW packages will be installed:
  php-common php-fpm php7.0-cli php7.0-common php7.0-fpm php7.0-json php7.0-opcache php7.0-readline
0 upgraded, 8 newly installed, 0 to remove and 232 not upgraded.
Need to get 4,895 kB of archives.
After this operation, 20.4 MB of additional disk space will be used.
Do you want to continue? [Y/n]