/ AM-INSTALLER
AM-INSTALLER
1 #!/bin/sh 2 3 set -e 4 5 # Colors 6 RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m' 7 8 # For developers 9 AM_BRANCH="main" 10 11 # Check dependencies for this script 12 _check_dependency() { 13 AMDEPENDENCES="chmod chown curl grep wget" 14 for dependency in $AMDEPENDENCES; do 15 if ! command -v "$dependency" >/dev/null 2>&1; then 16 printf "\n %b💀 ERROR! MISSING ESSENTIAL COMMAND \033[0m: %b\n\n Install the above and try again! \n\n" "${RED}" "$dependency" 17 exit 1 18 fi 19 done 20 } 21 22 _check_dependency 23 24 # INSTALL "AM" SYSTEM-WIDE 25 _install_am() { 26 CACHEDIR="${XDG_CACHE_HOME:-$HOME/.cache}" 27 mkdir -p "$CACHEDIR" || true 28 rm -f "$CACHEDIR"/INSTALL-AM.sh || true 29 wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/INSTALL" -O "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh 30 #cp ./INSTALL "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh # for developers 31 if command -v sudo >/dev/null 2>&1; then 32 SUDOCMD="sudo" 33 elif command -v doas >/dev/null 2>&1; then 34 SUDOCMD="doas" 35 else 36 echo 'ERROR: No sudo or doas found' 37 exit 1 38 fi 39 $SUDOCMD "$CACHEDIR"/INSTALL-AM.sh && rm -f "$CACHEDIR"/INSTALL-AM.sh 40 } 41 42 # INSTALL "AM" LOCALLY, AS "APPMAN" 43 _install_appman() { 44 ZSHRC="${ZDOTDIR:-$HOME}/.zshrc" 45 BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}" 46 mkdir -p "$BINDIR" 47 if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then 48 echo '--------------------------------------------------------------------------' 49 echo " Adding $BINDIR to PATH, you might need to" 50 echo " close and reopen the terminal for this to take effect." 51 if [ -e ~/.bashrc ] && ! grep 'PATH="$PATH:$BINDIR"' ~/.bashrc >/dev/null 2>&1; then 52 printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> ~/.bashrc 53 printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> ~/.bashrc 54 printf ' export PATH="$PATH:$BINDIR"\nfi\n' >> ~/.bashrc 55 fi 56 if [ -e "$ZSHRC" ] && ! grep 'PATH="$PATH:$BINDIR"' "$ZSHRC" >/dev/null 2>&1; then 57 printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> "$ZSHRC" 58 printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> "$ZSHRC" 59 printf ' export PATH="$PATH:$BINDIR"\nfi\n' >> "$ZSHRC" 60 fi 61 fi 62 wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/APP-MANAGER" -O "$BINDIR"/appman && chmod a+x "$BINDIR"/appman 63 } 64 65 # CHOOSE BETWEEN "AM" AND "APPMAN" 66 printf " Choose how to install \"AM\" and all its managed applications. 67 68 1) As \"${RED}AM\033[0m\", command \"${Green}am\033[0m\", this is a system-wide installation: 69 - the command is a symlink /usr/local/bin/am for /opt/am/APP-MANAGER 70 - install and manage both system (default, require \"root\") and local apps 71 - choose wherever you want to install local apps 72 - you are the one with read-write permissions for \"AM\" and system programs 73 - other users can only use programs you have installed, nothing else 74 - other users can still use \"AppMan mode\" for their rootless configurations 75 76 2) As \"${LightBlue}AppMan\033[0m\", command \"${Green}appman\033[0m\", local installation: 77 - the command is the script ~/.local/bin/appman 78 - install and manage only local apps 79 - choose wherever you want to install local apps 80 - you can replicate your configurations on every system you want 81 - more storage space required, if more users use \"AppMan\" 82 83 " 84 read -r -p "Choose between \"AM\" (type 1) and \"AppMan\" (2), or leave blank to exit: " response 85 case "$response" in 86 1) _install_am || exit 1 87 ;; 88 2) _install_appman || exit 1 89 echo '--------------------------------------------------------------------------' 90 printf " ${Green}\"AppMan\" has been successfully installed!\033[0m\n" 91 printf " Please, run \"${LightBlue}appman -h\033[0m\" to see the list of the options.\n" 92 echo '--------------------------------------------------------------------------' 93 ;; 94 ''|*) echo "Installation aborted, exiting." && exit 1 95 ;; 96 esac