From 02d6e292e794492a9dc8d34dad413c054d673c3d Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Sat, 2 Mar 2024 19:30:15 -0500 Subject: [PATCH] library includes --- .install/includes/library.sh | 106 +++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 .install/includes/library.sh diff --git a/.install/includes/library.sh b/.install/includes/library.sh new file mode 100644 index 0000000..2c60a6b --- /dev/null +++ b/.install/includes/library.sh @@ -0,0 +1,106 @@ +#!/bin/bash +# _ _ _ +# | | (_) |__ _ __ __ _ _ __ _ _ +# | | | | '_ \| '__/ _` | '__| | | | +# | |___| | |_) | | | (_| | | | |_| | +# |_____|_|_.__/|_| \__,_|_| \__, | +# |___/ +# +# by Benjamin Palko [based on Stephan Raabe] (2023) +# ----------------------------------------------------- + +# ------------------------------------------------------ +# Function: Is package installed +# ------------------------------------------------------ +_isInstalledPacman() { + package="$1"; + check="$(sudo pacman -Qs --color always "${package}" | grep "local" | grep "${package} ")"; + if [ -n "${check}" ] ; then + echo 0; #'0' means 'true' in Bash + return; #true + fi; + echo 1; #'1' means 'false' in Bash + return; #false +} + +_isInstalledYay() { + package="$1"; + check="$(yay -Qs --color always "${package}" | grep "local" | grep "\." | grep "${package} ")"; + if [ -n "${check}" ] ; then + echo 0; #'0' means 'true' in Bash + return; #true + fi; + echo 1; #'1' means 'false' in Bash + return; #false +} + +_isInstalledBrew() { + package="$1"; + check="$(brew list | grep "${package} ")"; + if [ -n "${check}" ] ; then + echo 0; #'0' means 'true' in Bash + return; #true + fi; + echo 1; #'1' means 'false' in Bash + return; #false +} + +# ------------------------------------------------------ +# Function Install all package if not installed +# ------------------------------------------------------ +_installPackagesPacman() { + toInstall=(); + for pkg; do + if [[ $(_isInstalledPacman "${pkg}") == 0 ]]; then + echo ":: ${pkg} is already installed."; + continue; + fi; + toInstall+=("${pkg}"); + done; + + if [[ "${toInstall[@]}" == "" ]] ; then + # echo "All pacman packages are already installed."; + return; + fi; + + # printf "Package not installed:\n%s\n" "${toInstall[@]}"; + sudo pacman --noconfirm -S "${toInstall[@]}"; +} + +_installPackagesYay() { + toInstall=(); + for pkg; do + if [[ $(_isInstalledYay "${pkg}") == 0 ]]; then + echo ":: ${pkg} is already installed."; + continue; + fi; + toInstall+=("${pkg}"); + done; + + if [[ "${toInstall[@]}" == "" ]] ; then + # echo "All packages are already installed."; + return; + fi; + + # printf "AUR packags not installed:\n%s\n" "${toInstall[@]}"; + yay --noconfirm -S "${toInstall[@]}"; +} + +_installPackagesBrew() { + toInstall=(); + for pkg; do + if [[ $(_isInstalledBrew "${pkg}") == 0 ]]; then + echo ":: ${pkg} is already installed."; + continue; + fi; + toInstall+=("${pkg}"); + done; + + if [[ "${toInstall[@]}" == "" ]] ; then + echo "All brew packages are already installed."; + return; + fi; + + brew install "${toInstall[@]}"; +} +