AM-INSTALLER 3.6 KB

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