AM-INSTALLER 3.8 KB

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