-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
INSTALL
executable file
·70 lines (58 loc) · 2.41 KB
/
INSTALL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/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 '--------------------------------------------------------------------------'