diff --git a/AM-INSTALLER b/AM-INSTALLER index 6585daaf1..6281c0b37 100644 --- a/AM-INSTALLER +++ b/AM-INSTALLER @@ -2,31 +2,32 @@ set -e -_away_error() { - ${1} >/dev/null 2>&1 -} - -_away_all() { - ${1} >/dev/null -} - # Colors RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m' +# For developers +AM_BRANCH="main" + +# Check dependencies for this script _check_dependency() { - program="$1" - _away_all command -v "$program" || { echo "For Installation to work, install \"$program\" first!" && exit 1; } + AMDEPENDENCES="chmod chown curl grep wget" + for dependency in $AMDEPENDENCES; do + if ! command -v "$dependency" >/dev/null 2>&1; then + printf "\n %b💀 ERROR! MISSING ESSENTIAL COMMAND \033[0m: %b\n\n Install the above and try again! \n\n" "${RED}" "$dependency" + exit 1 + fi + done } -_check_dependency 'wget' -_check_dependency 'curl' +_check_dependency # INSTALL "AM" SYSTEM-WIDE _install_am() { CACHEDIR="${XDG_CACHE_HOME:-$HOME/.cache}" mkdir -p "$CACHEDIR" || true rm -f "$CACHEDIR"/INSTALL-AM.sh || true - wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/INSTALL -O "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh + wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/INSTALL" -O "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh + #cp ./INSTALL "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh # for developers if command -v sudo >/dev/null 2>&1; then SUDOCMD="sudo" elif command -v doas >/dev/null 2>&1; then @@ -58,7 +59,7 @@ _install_appman() { printf ' export PATH="$PATH:$BINDIR"\nfi\n' >> "$ZSHRC" fi fi - wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER -O "$BINDIR"/appman && chmod a+x "$BINDIR"/appman + wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/APP-MANAGER" -O "$BINDIR"/appman && chmod a+x "$BINDIR"/appman } # CHOOSE BETWEEN "AM" AND "APPMAN" diff --git a/APP-MANAGER b/APP-MANAGER index e6166d98b..83b4c315a 100755 --- a/APP-MANAGER +++ b/APP-MANAGER @@ -1,6 +1,6 @@ #!/usr/bin/env bash -AMVERSION="9.3-2" +AMVERSION="9.3-3" # Determine main repository and branch AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main" @@ -17,8 +17,10 @@ DIR="$( cd "$( dirname "$0" )" && pwd )" CLI=$(basename "$0") # Determine system architecture and current user -arch="$HOSTTYPE" -export ARCH="$arch" +ARCH="$(uname -m)" +[ "$ARCH" = "amd64" ] && ARCH=x86_64 +arch="$ARCH" +export ARCH arch # XDG Variables export BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}" @@ -39,7 +41,10 @@ LightBlue='\033[1;34m' DIVIDING_LINE="-----------------------------------------------------------------------------" # Prevent the use of "sudo" ("AM") -[ -n "$SUDO_COMMAND" ] && echo -e "\n Please do not use \"sudo\" to execute \"$CLI\", try again.\n" && exit 1 +if [ -n "${SUDO_USER:-$DOAS_USER}" ]; then + printf "\n Please do not use \"sudo\" to execute \"$CLI\", try again.\n\n" + exit 1 +fi function _create_cache_dir() { AMCACHEDIR="$CACHEDIR/$AMCLI" @@ -255,13 +260,14 @@ function _am_dependences_check() { } function _check_ubuntu_mess() { - if ! unshare --user -p /bin/true >/dev/null 2>&1; then + if command -v unshare >/dev/null 2>&1 && ! unshare --user -p /bin/true >/dev/null 2>&1; then echo "$DIVIDING_LINE" echo "" echo -e " ${RED}⚠️ WARNING: ACCESS TO USER NAMESPACES IS RESTRICTED! \033[0m" echo "" - echo " Some apps may not run, you need to enable access to user namespaces," - echo -e " please visit ${LightBlue}https://github.com/ivan-hc/AM#ubuntu-mess\033[0m to know more." + echo " Some apps may not run, you need to enable access to user namespaces, see" + echo -e " ${LightBlue}https://github.com/ivan-hc/AM/blob/main/docs/troubleshooting.md#ubuntu-mess\033[0m" + echo " to know more." echo "" echo "$DIVIDING_LINE" fi diff --git a/INSTALL b/INSTALL index 381ed1962..dff8db55b 100755 --- a/INSTALL +++ b/INSTALL @@ -1,27 +1,28 @@ #!/bin/sh -_away_error() { - ${1} >/dev/null 2>&1 -} - -_away_all() { - ${1} >/dev/null -} +# Colors +RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m' -# DETERMINE SYSTEM ARCHITECTURE AND CURRENT USER -arch=$(uname -m) -currentuser=$(who | awk '{print $1}') +# For developers +AM_BRANCH="main" +# Check dependencies for this script _check_dependency() { - program="$1" - _away_all command -v "$program" && return 0 || printf "${RED}WARNING: For Installation to work, install \"$program\" first!\033[0m\n" && exit 1 + AMDEPENDENCES="chmod chown curl grep wget" + for dependency in $AMDEPENDENCES; do + if ! command -v "$dependency" >/dev/null 2>&1; then + printf "\n %b💀 ERROR! MISSING ESSENTIAL COMMAND \033[0m: %b\n\n Install the above and try again! \n\n" "${RED}" "$dependency" + exit 1 + fi + done } -_check_dependency 'wget' -_check_dependency 'curl' +_check_dependency -# Colors -RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m' +if [ -z "${SUDO_USER:-$DOAS_USER}" ]; then + echo 'Please use sudo or doas' + exit 1 +fi # INSTALL "AM" _prepare_am_directory() { @@ -36,7 +37,7 @@ _prepare_am_directory() { chmod a+x /opt/am/remove || exit 1 # DOWNLOAD AND LINK THE MAIN SCRIPT - wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER + wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/APP-MANAGER" chmod a+x /opt/am/APP-MANAGER ln -s /opt/am/APP-MANAGER /usr/local/bin/am 2> /dev/null || printf "${RED}WARNING: Couldn't link am to \"/usr/local/bin/am\"!\033[0m\n" } @@ -44,18 +45,18 @@ _prepare_am_directory() { _download_am_modules() { # DOWNLOAD MODULES cd /opt/am/modules || exit - MODULES=$(curl -Ls https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER | tr '"' '\n' | grep "[a-z]\.am$") + MODULES=$(curl -Ls "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/APP-MANAGER" | tr '"' '\n' | grep "[a-z]\.am$") for module_name in $MODULES; do - if ! test -f ./"$module_name"; then + if [ ! -f ./"$module_name" ]; then echo " ◆ Downloading $module_name..." - wget -q "https://raw.githubusercontent.com/ivan-hc/AM/main/modules/$module_name" + wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/modules/$module_name" chmod a+x ./"$module_name" fi done cd .. # ENABLE NON-ROOT PERMISSIONS TO THE MAIN DIRECTORY FOR THE CURRENT USER - chown -R $currentuser /opt/am 2> /dev/null + chown -R "${SUDO_USER:-$DOAS_USER}" /opt/am 2>/dev/null } echo '--------------------------------------------------------------------------'