Skip to content

Instantly share code, notes, and snippets.

@Tobishua
Created September 22, 2017 12:31
Show Gist options
  • Save Tobishua/e78e4c551d1e441808beb7e18c1d7532 to your computer and use it in GitHub Desktop.
Save Tobishua/e78e4c551d1e441808beb7e18c1d7532 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
#
which_cmd() {
which "${1}" 2>/dev/null || \
command -v "${1}" 2>/dev/null
}
check_cmd() {
which_cmd "${1}" >/dev/null 2>&1 && return 0
return 1
}
curl="$(which_cmd curl)"
wget="$(which_cmd wget)"
bash="$(which_cmd bash)"
git="$(which_cmd git)"
smth="$(which_cmd pypy)"
SYSTEM="$(uname -s)"
OS="$(uname -o)"
MACHINE="$(uname -m)"
SOURCE_DST="/usr/src"
if [ -z "${BASH_VERSION}" ]
then
# we don't run under bash
if [ ! -z "${bash}" -a -x "${bash}" ]
then
BASH_MAJOR_VERSION=$(${bash} -c 'echo "${BASH_VERSINFO[0]}"')
fi
else
# we run under bash
BASH_MAJOR_VERSION="${BASH_VERSINFO[0]}"
fi
HAS_BASH4=1
if [ -z "${BASH_MAJOR_VERSION}" ]
then
echo >&2 "No BASH is available on this system"
HAS_BASH4=0
elif [ $((BASH_MAJOR_VERSION)) -lt 4 ]
then
echo >&2 "No BASH v4+ is available on this system (installed bash is v${BASH_MAJOR_VERSION}"
HAS_BASH4=0
fi
if [ "${OS}" = "GNU/Linux" -o "${SYSTEM}" = "Linux" ]
then
if [ "${HAS_BASH4}" = "1" ]
then
echo 'Bash is here!'
if [ "$wget" = "" ] && [ "$curl" = "" ]
then
echo "Whoops... We can't find curl and wget on your system. Therefore we need to install this."
exit 1
else
echo 'Ok. Something is here'
fi
else
echo 'No bash in the system'
fi
fi
echo 'Ok. Continue...'
# Check which package managers are available
apk=$(which apk 2>/dev/null || command -v apk 2>/dev/null)
apt_get=$(which apt-get 2>/dev/null || command -v apt-get 2>/dev/null)
dnf=$(which dnf 2>/dev/null || command -v dnf 2>/dev/null)
emerge=$(which emerge 2>/dev/null || command -v emerge 2>/dev/null)
equo=$(which equo 2>/dev/null || command -v equo 2>/dev/null)
pacman=$(which pacman 2>/dev/null || command -v pacman 2>/dev/null)
yum=$(which yum 2>/dev/null || command -v yum 2>/dev/null)
zypper=$(which zypper 2>/dev/null || command -v zypper 2>/dev/null)
package_manager() {
[ -x "$(which $1)" ]
}
if package_manager apt-get; then
echo "Whoa! apt-get is here!"
elif package_manager yum; then
echo "Whoa! Yum is here!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment