1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
#!/bin/bash
### How does this script operate?
#
# Script's expectations:
# - To be run on one of the supported OSes
#
# Script's arguments:
# - (none)
#
# Steps that this script performs:
# - Verifies the presence of required binaries
# - If all are present, exit
# - Detect the OS, bail out if unknown/unsupported
# - Use the OS-specific package installation method to intall all required packages
#
### Shell configuration and script bootstrap
#
set -e
set -u
set -o pipefail
BOOTSTRAP_GIT_REPO_REQUIRED="false"
. `dirname $0`/_bootstrap.sh
### Definitions
#
# NOTICE: Certain changes here must potentially be reflected
# in the ../install/install-snoopy.sh file too.
#
PROGRAM_NAMES="autoconf aclocal curl diff file find gcc git gzip hostname libtoolize m4 make ps socat tar wget"
PACKAGE_NAMES_ALPINE="autoconf automake curl diffutils file gcc git gzip libtool m4 make procps socat tar wget alpine-sdk"
PACKAGE_NAMES_ARCH="autoconf automake curl diffutils file gcc git gzip inetutils libtool m4 make procps socat tar wget"
PACKAGE_NAMES_DEBIAN="autoconf automake curl diffutils file gcc git gzip libtool m4 make procps socat tar wget"
PACKAGE_NAMES_REDHAT="autoconf automake curl diffutils file gcc git gzip hostname libtool m4 make procps socat tar wget"
PACKAGE_NAMES_SUSE="autoconf automake awk curl diffutils file findutils gcc git gzip hostname libtool m4 make procps socat tar wget"
### Software check & install functions
#
# NOTICE: Keep this code in sync in the following files:
# - dev-tools/install-dev-software.sh
# - install/install-snoopy.sh
#
_areAllRequiredProgramsPresent()
{
# NOTICE: Keep this code in sync in the following files:
# - dev-tools/install-dev-software.sh
# - install/install-snoopy.sh
REQUIRED_PROGRAMS="$1"
ALL_REQUIRED_PROGRAMS_PRESENT="true"
for REQUIRED_PROGRAM in $REQUIRED_PROGRAMS; do
if ! command -v $REQUIRED_PROGRAM > /dev/null; then
ALL_REQUIRED_PROGRAMS_PRESENT="false"
_echo "The following program is missing: $REQUIRED_PROGRAM"
fi
done
if [ "$ALL_REQUIRED_PROGRAMS_PRESENT" == "true" ]; then
true
else
false
fi
}
_detectOperatingSystem()
{
# NOTICE: Keep this code in sync in the following files:
# - dev-tools/install-dev-software.sh
# - install/install-snoopy.sh
#
# Expects:
# - Global variable OS_ID set to ""
# - Global variable OS_VERSION set to ""
#
# Sets:
# - Global variable OS_ID
# - Global variable OS_VERSION
#
# Returns:
# - (nothing)
OS_ID=""
OS_VERSION=""
. /etc/os-release
OS_ID="$ID"
OS_VERSION="${VERSION_ID:-}"
# Debian Sid quirk
if [[ $OS_ID == "debian" ]] && [[ "$OS_VERSION" == "" ]]; then
OS_VERSION="sid"
fi
}
_installPackages()
{
# NOTICE: Keep this code in sync in the following files:
# - dev-tools/install-dev-software.sh
# - install/install-snoopy.sh
#
# Expects:
# - Global variable OS_ID
# - Global variable OS_VERSION
# - Global variable PACKAGE_NAMES_ALPINE
# - Global variable PACKAGE_NAMES_ARCH
# - Global variable PACKAGE_NAMES_DEBIAN
# - Global variable PACKAGE_NAMES_REDHAT
# - Global variable PACKAGE_NAMES_SUSE
#
# Sets:
# - (nothing)
#
# Returns:
# - false on error
USE_SUDO="sudo -n"
MY_UID=`id -u`
if [ "$MY_UID" == "0" ]; then
USE_SUDO=""
fi
case "$OS_ID" in
alpine)
$USE_SUDO apk add $PACKAGE_NAMES_ALPINE
;;
arch)
$USE_SUDO sudo pacman -Syu --noconfirm $PACKAGE_NAMES_ARCH
;;
debian|ubuntu)
DEBIAN_FRONTEND="noninteractive" $USE_SUDO apt-get update -y
DEBIAN_FRONTEND="noninteractive" $USE_SUDO apt-get install -y $PACKAGE_NAMES_DEBIAN
;;
rhel|centos|almalinux)
$USE_SUDO yum install -y --allowerasing $PACKAGE_NAMES_REDHAT
;;
sles|opensuse-leap|opensuse-tumbleweed)
$USE_SUDO zypper -n install $PACKAGE_NAMES_SUSE
;;
*)
_fatalError "Unknown OS: '$OS_ID'. Install the following programs manually: $PACKAGE_NAMES_DEBIAN"
;;
esac
}
### Check programs presence
#
if _areAllRequiredProgramsPresent "$PROGRAM_NAMES"; then
_echo "All required programs are already installed, nice."
exit
fi
# Now run the OS detection
#
OS_ID=""
OS_VERSION=""
_detectOperatingSystem
if [ "$OS_ID" == "" ]; then
_fatalError "Unable to detect your OS via /etc/os-release. Install the following programs manually: $PROGRAM_NAMES"
fi
### Now install the packages
#
_installPackages
### Recheck
#
if ! _areAllRequiredProgramsPresent "$PROGRAM_NAMES"; then
_fatalError "Even after installation, at least some of the required programs are still not available. Seems like a bug in this script."
else
_echo "All required programs are now installed."
fi
|