1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/bin/sh
- _away_error() {
- ${1} >/dev/null 2>&1
- }
- _away_all() {
- ${1} >/dev/null
- }
- # DETERMINE SYSTEM ARCHITECTURE AND CURRENT USER
- arch=$(uname -m)
- currentuser=$(who | awk '{print $1}')
- _check_dependency() {
- program="$1"
- _away_all command -v "$program" && return 0 || printf "${RED}WARNING: For Installation to work, install \"$program\" first!\033[0m\n" && exit 1
- }
- _check_dependency 'wget'
- _check_dependency 'curl'
- # Colors
- RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m'
- # INSTALL "AM"
- _prepare_am_directory() {
- # CREATE AND ENTER THE MAIN DIRECTORY FOR "AM"
- mkdir -p /opt/am/modules /usr/local/bin && cd /opt/am || exit 1
- # CREATE THE SCRIPT NEEDED TO UNINSTALL "AM"
- printf '#!/bin/sh\n\nset -e\n' > /opt/am/remove
- printf '\n%s\n' 'if [ "$(id -u)" -ne 0 ]; then echo "Permission denied"; exit 1; fi' >> /opt/am/remove
- printf '%s\n' 'rm -f /usr/local/bin/am' >> /opt/am/remove
- printf '%s\n' 'rm -R -f /opt/am' >> /opt/am/remove
- chmod a+x /opt/am/remove || exit 1
- # DOWNLOAD AND LINK THE MAIN SCRIPT
- wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER
- chmod a+x /opt/am/APP-MANAGER
- 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"
- }
- _download_am_modules() {
- # DOWNLOAD MODULES
- cd /opt/am/modules || exit
- MODULES=$(curl -Ls https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER | tr '"' '\n' | grep "[a-z]\.am$")
- for module_name in $MODULES; do
- if ! test -f ./"$module_name"; then
- echo " ◆ Downloading $module_name..."
- wget -q "https://raw.githubusercontent.com/ivan-hc/AM/main/modules/$module_name"
- chmod a+x ./"$module_name"
- fi
- done
- cd ..
- # ENABLE NON-ROOT PERMISSIONS TO THE MAIN DIRECTORY FOR THE CURRENT USER
- chown -R $currentuser /opt/am 2> /dev/null
- }
- echo '--------------------------------------------------------------------------'
- printf " ${Green}Installing \"AM\" in /opt/am\033[0m\n"
- _prepare_am_directory
- echo '--------------------------------------------------------------------------'
- printf " ${Green}Installing modules\033[0m\n"
- _download_am_modules
- echo '--------------------------------------------------------------------------'
- printf " ${Green}\"AM\" has been successfully installed!\033[0m\n"
- printf " Please, run \"${LightBlue}am -h\033[0m\" to see the list of the options.\n"
- echo '--------------------------------------------------------------------------'
|