Creates umbrella commands for all Linux packages and adds support for Arch Linux' package manager pacman

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
E.Azer Koçulu 2018-02-08 03:40:24 +08:00 committed by Andrey Shovkoplyas
parent f7fd5e71d6
commit d0dff14ea6
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
2 changed files with 75 additions and 10 deletions

View File

@ -30,7 +30,7 @@ function install_and_setup_package_manager() {
)
for package in "${buildtools[@]}"; do
apt_install "$package"
linux_install "$package"
done
fi
}
@ -138,7 +138,7 @@ function install_android_sdk_linux() {
function install_maven() {
brew_install maven
apt_install maven
linux_install maven
}
function install_react_native_cli() {
@ -184,9 +184,9 @@ function install_node_via_package_manager() {
brew_install node
elif is_linux; then
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
apt_update
linux_update
apt_install nodejs
linux_install nodejs
fi
else
cecho \

View File

@ -9,6 +9,8 @@ function program_exists() {
command -v "$program" >/dev/null 2>&1
}
########
# Homebrew
########
@ -53,28 +55,68 @@ function brew_tap() {
fi
}
###############
# Linux
###############
function linux_update() {
! is_linux && return 1
if program_exists "apt"; then
apt_update
elif program_exists "pacman"; then
pacman_update
else
echo "Unsupported Linux distro."
exit 1;
fi
}
function linux_is_installed() {
! is_linux && return 1
if program_exists "apt"; then
apt_is_installed "$@"
elif program_exists "pacman"; then
pacman_is_installed "$@"
else
echo "Unsupported Linux distro."
exit 1;
fi
}
# 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() {
! is_linux && return 1
if program_exists "apt"; then
apt_install "$@"
elif program_exists "pacman"; then
pacman_install "$@"
else
echo "Unsupported Linux distro."
exit 1;
fi
}
###############
# Aptitude
###############
function apt_update() {
! is_linux && return 1
sudo apt update
}
function apt_is_installed() {
! is_linux && return 1
local package=$1
dpkg -s "$package" >/dev/null 2>&1
}
function apt_install() {
! is_linux && return 1
local package=$1
if apt_is_installed "$package"; then
@ -84,6 +126,29 @@ function apt_install() {
fi
}
###############
# Pacman
###############
function pacman_update() {
sudo pacman -Syu
}
function pacman_is_installed() {
local package=$1
pacman -Qs $package >/dev/null 2>&1
}
function pacman_install() {
local package=$1
if pacman_is_installed "$package"; then
cecho "+ $package already installed... skipping."
else
sudo pacman -S --noconfirm "$package"
fi
}
###############
# RVM
###############