2017-11-27 11:40:21 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
########
|
|
|
|
# Install checks
|
|
|
|
########
|
|
|
|
|
2019-01-21 16:29:33 +01:00
|
|
|
GIT_ROOT=$(git rev-parse --show-toplevel)
|
|
|
|
|
2017-11-27 11:40:21 -08:00
|
|
|
function program_exists() {
|
|
|
|
local program=$1
|
|
|
|
command -v "$program" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2019-01-10 19:32:30 +01:00
|
|
|
function program_version_exists() {
|
|
|
|
local program=$1
|
|
|
|
if ! program_exists "$program"; then
|
|
|
|
$(exit 1)
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
local required_version=$2
|
|
|
|
if echo "$($program --version)" | grep -q -wo "$required_version\|$required_version[^\.]"; then
|
|
|
|
$(exit 0)
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
$(exit 1)
|
|
|
|
}
|
|
|
|
|
2019-01-18 15:09:23 +01:00
|
|
|
function toolversion() {
|
2019-01-21 16:29:33 +01:00
|
|
|
${GIT_ROOT}/scripts/toolversion "${1}"
|
2019-01-10 19:32:30 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 03:40:24 +08:00
|
|
|
###############
|
|
|
|
# Linux
|
|
|
|
###############
|
|
|
|
|
|
|
|
# FIXME This command assumes that package names in different package managers (apt, pacman) are same.
|
|
|
|
# At this moment, it works as expected because we only call it for installing maven and nodejs.
|
|
|
|
# If this list grows, please consider adding some sort of mapping mechanism.
|
|
|
|
function linux_install() {
|
2019-02-01 11:44:51 +01:00
|
|
|
! is_linux && return 0
|
2018-02-08 03:40:24 +08:00
|
|
|
|
2019-01-10 19:32:30 +01:00
|
|
|
if program_exists "apt"; then
|
|
|
|
apt_install "$@"
|
|
|
|
elif program_exists "pacman"; then
|
|
|
|
pacman_install "$@"
|
|
|
|
else
|
|
|
|
echo "Unsupported Linux distro."
|
|
|
|
exit 1;
|
|
|
|
fi
|
2018-02-08 03:40:24 +08:00
|
|
|
}
|
|
|
|
|
2017-12-01 09:17:25 -08:00
|
|
|
|
|
|
|
###############
|
|
|
|
# Aptitude
|
|
|
|
###############
|
|
|
|
|
|
|
|
function apt_update() {
|
|
|
|
sudo apt update
|
|
|
|
}
|
|
|
|
|
|
|
|
function apt_is_installed() {
|
|
|
|
local package=$1
|
|
|
|
|
|
|
|
dpkg -s "$package" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
function apt_install() {
|
|
|
|
local package=$1
|
|
|
|
|
|
|
|
if apt_is_installed "$package"; then
|
|
|
|
cecho "+ $package already installed... skipping."
|
|
|
|
else
|
2019-01-10 19:32:30 +01:00
|
|
|
sudo apt install -y "$package" || exit 1
|
2017-12-01 09:17:25 -08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-02-08 03:40:24 +08:00
|
|
|
###############
|
|
|
|
# Pacman
|
|
|
|
###############
|
|
|
|
|
|
|
|
function pacman_update() {
|
2019-01-10 19:32:30 +01:00
|
|
|
sudo pacman -Syu
|
2018-02-08 03:40:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function pacman_is_installed() {
|
2019-01-10 19:32:30 +01:00
|
|
|
local package=$1
|
|
|
|
pacman -Qs $package >/dev/null 2>&1
|
2018-02-08 03:40:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function pacman_install() {
|
2019-01-10 19:32:30 +01:00
|
|
|
local package=$1
|
2018-02-08 03:40:24 +08:00
|
|
|
|
2019-01-10 19:32:30 +01:00
|
|
|
if pacman_is_installed "$package"; then
|
|
|
|
cecho "+ $package already installed... skipping."
|
|
|
|
else
|
|
|
|
sudo pacman -S --noconfirm "$package" || exit 1
|
|
|
|
fi
|
2018-02-08 03:40:24 +08:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:40:21 -08:00
|
|
|
###############
|
|
|
|
# RVM
|
|
|
|
###############
|
|
|
|
|
|
|
|
function load_rvm_if_available() {
|
|
|
|
[ -f ~/.rvm/scripts/rvm ] && source ~/.rvm/scripts/rvm
|
|
|
|
}
|