123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #!/bin/sh
- 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'
- _check_dependency() {
- program="$1"
- _away_all command -v "$program" || { echo "For Installation to work, install \"$program\" first!" && exit 1; }
- }
- _check_dependency 'wget'
- _check_dependency 'curl'
- # 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
- if command -v sudo >/dev/null 2>&1; then
- SUDOCMD="sudo"
- elif command -v doas >/dev/null 2>&1; then
- SUDOCMD="doas"
- else
- echo 'ERROR: No sudo or doas found'
- exit 1
- fi
- $SUDOCMD "$CACHEDIR"/INSTALL-AM.sh && rm -f "$CACHEDIR"/INSTALL-AM.sh
- }
- # INSTALL "AM" LOCALLY, AS "APPMAN"
- _install_appman() {
- ZSHRC="${ZDOTDIR:-$HOME}/.zshrc"
- BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
- mkdir -p "$BINDIR"
- if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then
- echo '--------------------------------------------------------------------------'
- echo " Adding $BINDIR to PATH, you might need to"
- echo " close and reopen the terminal for this to take effect."
- if [ -e ~/.bashrc ] && ! grep 'PATH="$PATH:$BINDIR"' ~/.bashrc >/dev/null 2>&1; then
- printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> ~/.bashrc
- printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> ~/.bashrc
- printf ' export PATH="$PATH:$BINDIR"\nfi\n' >> ~/.bashrc
- fi
- if [ -e "$ZSHRC" ] && ! grep 'PATH="$PATH:$BINDIR"' "$ZSHRC" >/dev/null 2>&1; then
- printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> "$ZSHRC"
- printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> "$ZSHRC"
- 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
- }
- # CHOOSE BETWEEN "AM" AND "APPMAN"
- printf " Choose how to install \"AM\" and all its managed applications.
- 1) As \"${RED}AM\033[0m\", command \"${Green}am\033[0m\", this is a system-wide installation:
- - the command is a symlink /usr/local/bin/am for /opt/am/APP-MANAGER
- - install and manage both system (default, require \"root\") and local apps
- - choose wherever you want to install local apps
- - you are the one with read-write permissions for \"AM\" and system programs
- - other users can only use programs you have installed, nothing else
- - other users can still use \"AppMan mode\" for their rootless configurations
- 2) As \"${LightBlue}AppMan\033[0m\", command \"${Green}appman\033[0m\", local installation:
- - the command is the script ~/.local/bin/appman
- - install and manage only local apps
- - choose wherever you want to install local apps
- - you can replicate your configurations on every system you want
- - more storage space required, if more users use \"AppMan\"
- "
- read -r -p "Choose between \"AM\" (type 1) and \"AppMan\" (2), or leave blank to exit: " response
- case "$response" in
- 1) _install_am || exit 1
- ;;
- 2) _install_appman || exit 1
- echo '--------------------------------------------------------------------------'
- printf " ${Green}\"AppMan\" has been successfully installed!\033[0m\n"
- printf " Please, run \"${LightBlue}appman -h\033[0m\" to see the list of the options.\n"
- echo '--------------------------------------------------------------------------'
- ;;
- ''|*) echo "Installation aborted, exiting." && exit 1
- ;;
- esac
|