Skip to content

Commit

Permalink
Creates umbrella commands for all Linux packages and adds support for…
Browse files Browse the repository at this point in the history
… Arch Linux' package manager pacman

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
  • Loading branch information
E.Azer Koçulu authored and flexsurfer committed Feb 9, 2018
1 parent f7fd5e7 commit d0dff14
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 10 deletions.
8 changes: 4 additions & 4 deletions scripts/lib/setup/installers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function install_and_setup_package_manager() {
)

for package in "${buildtools[@]}"; do
apt_install "$package"
linux_install "$package"
done
fi
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 \
Expand Down
77 changes: 71 additions & 6 deletions scripts/lib/setup/packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function program_exists() {
command -v "$program" >/dev/null 2>&1
}



########
# Homebrew
########
Expand Down Expand Up @@ -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
Expand All @@ -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
###############
Expand Down

0 comments on commit d0dff14

Please sign in to comment.