source "$DOTWRYN_PATH/setup/yay.setup.zsh" ################################################################################ ### Automated System Dependency Install ######################################## ################################################################################ [ $DOTWRYN_PATH ]\ && DEPENDENCY_DIR="$DOTWRYN_PATH/setup/os-dependencies" \ || DEPENDENCY_DIR="${0:a:h}/os-dependencies" function SETUP__OS_DEPENDENCY() { local ERROR=0 STATUS 'checking os dependencies' local OS_NAME=$(lsb_release -is 2>/dev/null | tr '[:upper:]' '[:lower:]') [ ! $OS_NAME ] && { OS_NAME=$(cat /etc/os-release | grep ^ID= | sed 's/^ID=//') } STATUS "detected os '$OS_NAME'" case $OS_NAME in arch ) OS_INSTALL() { OS_INSTALL__ARCH $@; } WARNING 'base-devel is required; make sure it is installed' YAY__INSTALL_FROM_SOURCE ;; debian | ubuntu ) OS_INSTALL() { OS_INSTALL__DEBIAN $@; } OS_NAME='debian' ;; * ) WARNING WARNING "no automated installer available for '$OS_NAME'" WARNING "if dependency shows a warning, install the indicated package" WARNING OS_INSTALL() { OS_INSTALL__GENERIC $@; } OS_NAME='generic' ;; esac for DEPENDENCY in $(cat "$DEPENDENCY_DIR/$OS_NAME.txt") do OS_INSTALL $DEPENDENCY || ERROR=1 done unset -f OS_INSTALL [[ $ERROR -eq 0 ]] && { SUCCESS 'all dependencies satisfied' USER_PROMPT 'continue with install? [Y/n]' READ_K yn [[ $yn =~ ^[nN] ]] && ERROR=1; true } || { WARNING 'detected errors; double check warnings before proceeding!' USER_PROMPT 'continue with install? [y/N]' READ_K yn [[ $yn =~ ^[yY] ]] && ERROR=0 } return $ERROR } function OS_INSTALL__ARCH() { local TARGET="$1" CHECK "checking for $TARGET" pacman -Qq | grep -q "^$TARGET$\|^$TARGET-git$" && OK || { WARN "$TARGET not found" CHECK "installing $TARGET" sudo pacman -Syu --noconfirm $TARGET >>$LOG 2>&1 \ && OK || { WARN "failed to install $TARGET"; return 1; } } } function OS_INSTALL__DEBIAN() { local TARGET="$1" CHECK "checking / installing $PACKAGE" sudo apt-get install --yes $PACKAGE >>$LOG 2>&1 \ && OK || { WARN "failed to install $TARGET"; return 1; } } function OS_INSTALL__GENERIC() { local COMMAND="$1" CHECK "checking for $COMMAND" command -v $COMMAND >/dev/null 2>&1 \ && OK || { WARN; return 1; } }