AM-INSTALLER 4.2 KB

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