|
| 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 | +# Function to check online connections (uses github.com by default, as the database and CLI itself are stored/hosted there) |
| 25 | +_online_check() { |
| 26 | + if ! wget -q --tries=3 --timeout=10 --spider https://github.com; then |
| 27 | + printf "\n Installer wouldn't work offline\n\n Please check your internet connection and try again\n\n" |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | +} |
| 31 | + |
| 32 | +_online_check |
| 33 | + |
| 34 | +# INSTALL "AM" SYSTEM-WIDE |
| 35 | +_install_am() { |
| 36 | + CACHEDIR="${XDG_CACHE_HOME:-$HOME/.cache}" |
| 37 | + mkdir -p "$CACHEDIR" || true |
| 38 | + rm -f "$CACHEDIR"/INSTALL-AM.sh || true |
| 39 | + wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/INSTALL" -O "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh |
| 40 | + #cp ./INSTALL "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh # for developers |
| 41 | + if command -v sudo >/dev/null 2>&1; then |
| 42 | + SUDOCMD="sudo" |
| 43 | + elif command -v doas >/dev/null 2>&1; then |
| 44 | + SUDOCMD="doas" |
| 45 | + else |
| 46 | + echo 'ERROR: No sudo or doas found' |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + $SUDOCMD "$CACHEDIR"/INSTALL-AM.sh && rm -f "$CACHEDIR"/INSTALL-AM.sh |
| 50 | +} |
| 51 | + |
| 52 | +# INSTALL "AM" LOCALLY, AS "APPMAN" |
| 53 | +_install_appman() { |
| 54 | + ZSHRC="${ZDOTDIR:-$HOME}/.zshrc" |
| 55 | + BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}" |
| 56 | + mkdir -p "$BINDIR" |
| 57 | + if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then |
| 58 | + echo '--------------------------------------------------------------------------' |
| 59 | + echo " Adding $BINDIR to PATH, you might need to" |
| 60 | + echo " close and reopen the terminal for this to take effect." |
| 61 | + if [ -e ~/.bashrc ] && ! grep 'PATH="$PATH:$BINDIR"' ~/.bashrc >/dev/null 2>&1; then |
| 62 | + printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> ~/.bashrc |
| 63 | + printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> ~/.bashrc |
| 64 | + printf ' export PATH="$PATH:$BINDIR"\nfi\n' >> ~/.bashrc |
| 65 | + fi |
| 66 | + if [ -e "$ZSHRC" ] && ! grep 'PATH="$PATH:$BINDIR"' "$ZSHRC" >/dev/null 2>&1; then |
| 67 | + printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> "$ZSHRC" |
| 68 | + printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> "$ZSHRC" |
| 69 | + printf ' export PATH="$PATH:$BINDIR"\nfi\n' >> "$ZSHRC" |
| 70 | + fi |
| 71 | + fi |
| 72 | + wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/APP-MANAGER" -O "$BINDIR"/appman && chmod a+x "$BINDIR"/appman |
| 73 | +} |
| 74 | + |
| 75 | +# CHOOSE BETWEEN "AM" AND "APPMAN" |
| 76 | +printf " Choose how to install \"AM\" and all its managed applications. |
| 77 | +
|
| 78 | + 1) As \"${RED}AM\033[0m\", command \"${Green}am\033[0m\", this is a system-wide installation: |
| 79 | + - the command is a symlink /usr/local/bin/am for /opt/am/APP-MANAGER |
| 80 | + - install and manage both system (default, require \"root\") and local apps |
| 81 | + - choose wherever you want to install local apps |
| 82 | + - you are the one with read-write permissions for \"AM\" and system programs |
| 83 | + - other users can only use programs you have installed, nothing else |
| 84 | + - other users can still use \"AppMan mode\" for their rootless configurations |
| 85 | +
|
| 86 | + 2) As \"${LightBlue}AppMan\033[0m\", command \"${Green}appman\033[0m\", local installation: |
| 87 | + - the command is the script ~/.local/bin/appman |
| 88 | + - install and manage only local apps |
| 89 | + - choose wherever you want to install local apps |
| 90 | + - you can replicate your configurations on every system you want |
| 91 | + - more storage space required, if more users use \"AppMan\" |
| 92 | +
|
| 93 | +" |
| 94 | +read -r -p "Choose between \"AM\" (type 1) and \"AppMan\" (2), or leave blank to exit: " response |
| 95 | +case "$response" in |
| 96 | + 1) _install_am || exit 1 |
| 97 | + ;; |
| 98 | + 2) _install_appman || exit 1 |
| 99 | + echo '--------------------------------------------------------------------------' |
| 100 | + printf " ${Green}\"AppMan\" has been successfully installed!\033[0m\n" |
| 101 | + printf " Please, run \"${LightBlue}appman -h\033[0m\" to see the list of the options.\n" |
| 102 | + echo '--------------------------------------------------------------------------' |
| 103 | + ;; |
| 104 | + ''|*) echo "Installation aborted, exiting." && exit 1 |
| 105 | + ;; |
| 106 | +esac |
0 commit comments