INSTALL 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh
  2. _away_error() {
  3. ${1} >/dev/null 2>&1
  4. }
  5. _away_all() {
  6. ${1} >/dev/null
  7. }
  8. # DETERMINE SYSTEM ARCHITECTURE AND CURRENT USER
  9. arch=$(uname -m)
  10. currentuser=$(who | awk '{print $1}')
  11. _check_dependency() {
  12. program="$1"
  13. _away_all command -v "$program" && return 0 || printf "${RED}WARNING: For Installation to work, install \"$program\" first!\033[0m\n" && exit 1
  14. }
  15. _check_dependency 'wget'
  16. _check_dependency 'curl'
  17. # Colors
  18. RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m'
  19. # INSTALL "AM"
  20. _prepare_am_directory() {
  21. # CREATE AND ENTER THE MAIN DIRECTORY FOR "AM"
  22. mkdir -p /opt/am/modules /usr/local/bin && cd /opt/am || exit 1
  23. # CREATE THE SCRIPT NEEDED TO UNINSTALL "AM"
  24. printf '#!/bin/sh\n\nset -e\n' > /opt/am/remove
  25. printf '\n%s\n' 'if [ "$(id -u)" -ne 0 ]; then echo "Permission denied"; exit 1; fi' >> /opt/am/remove
  26. printf '%s\n' 'rm -f /usr/local/bin/am' >> /opt/am/remove
  27. printf '%s\n' 'rm -R -f /opt/am' >> /opt/am/remove
  28. chmod a+x /opt/am/remove || exit 1
  29. # DOWNLOAD AND LINK THE MAIN SCRIPT
  30. wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER
  31. chmod a+x /opt/am/APP-MANAGER
  32. ln -s /opt/am/APP-MANAGER /usr/local/bin/am 2> /dev/null || printf "${RED}WARNING: Couldn't link am to \"/usr/local/bin/am\"!\033[0m\n"
  33. }
  34. _download_am_modules() {
  35. # DOWNLOAD MODULES
  36. cd /opt/am/modules || exit
  37. MODULES=$(curl -Ls https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER | tr '"' '\n' | grep "[a-z]\.am$")
  38. for module_name in $MODULES; do
  39. if ! test -f ./"$module_name"; then
  40. echo " ◆ Downloading $module_name..."
  41. wget -q "https://raw.githubusercontent.com/ivan-hc/AM/main/modules/$module_name"
  42. chmod a+x ./"$module_name"
  43. fi
  44. done
  45. cd ..
  46. # ENABLE NON-ROOT PERMISSIONS TO THE MAIN DIRECTORY FOR THE CURRENT USER
  47. chown -R $currentuser /opt/am 2> /dev/null
  48. }
  49. echo '--------------------------------------------------------------------------'
  50. printf " ${Green}Installing \"AM\" in /opt/am\033[0m\n"
  51. _prepare_am_directory
  52. echo '--------------------------------------------------------------------------'
  53. printf " ${Green}Installing modules\033[0m\n"
  54. _download_am_modules
  55. echo '--------------------------------------------------------------------------'
  56. printf " ${Green}\"AM\" has been successfully installed!\033[0m\n"
  57. printf " Please, run \"${LightBlue}am -h\033[0m\" to see the list of the options.\n"
  58. echo '--------------------------------------------------------------------------'