From d0dff14ea6ce412e85aa5c293f6e3219ce2bbebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=2EAzer=20Ko=C3=A7ulu?= Date: Thu, 8 Feb 2018 03:40:24 +0800 Subject: [PATCH] Creates umbrella commands for all Linux packages and adds support for Arch Linux' package manager pacman Signed-off-by: Andrey Shovkoplyas --- scripts/lib/setup/installers.sh | 8 ++-- scripts/lib/setup/packages.sh | 77 ++++++++++++++++++++++++++++++--- 2 files changed, 75 insertions(+), 10 deletions(-) diff --git a/scripts/lib/setup/installers.sh b/scripts/lib/setup/installers.sh index 6d91003fff..86c2ce29c5 100755 --- a/scripts/lib/setup/installers.sh +++ b/scripts/lib/setup/installers.sh @@ -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 \ diff --git a/scripts/lib/setup/packages.sh b/scripts/lib/setup/packages.sh index 5b683e6fc6..896068773c 100755 --- a/scripts/lib/setup/packages.sh +++ b/scripts/lib/setup/packages.sh @@ -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 ###############