-
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathAM-INSTALLER
More file actions
executable file
·161 lines (142 loc) · 5.48 KB
/
Copy pathAM-INSTALLER
File metadata and controls
executable file
·161 lines (142 loc) · 5.48 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/sh
set -e
# Colors
RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m'
# For developers
AM_BRANCH="main"
if command -v tput >/dev/null 2>&1; then
TERMINAL_WIDTH=$(($(tput cols)-3))
else
TERMINAL_WIDTH=${COLUMNS:-80}
fi
DIVIDING_LINE=$(printf '%*s' "$TERMINAL_WIDTH" '' | tr ' ' '-')
_fit() {
if command -v tput >/dev/null 2>&1; then
fold -sw "$TERMINAL_WIDTH" | sed 's/^/ /g'
else
fold -sw 77 | sed 's/^/ /g'
fi
}
# Function to check online connections (uses github.com by default, as the database and CLI itself are stored/hosted there)
_online_check_tool() {
if command -v wget >/dev/null 2>&1; then
wget -q --tries=10 --timeout=20 --spider https://github.com
elif command -v curl >/dev/null 2>&1; then
curl --output /dev/null --silent --head --fail https://github.com 1> /dev/null
else
printf "\n %b💀 ERROR! MISSING ESSENTIAL COMMANDS\033[0m: %s\n\n Install the above and try again! \n\n" "${RED}" "curl, wget"
exit 0
fi
}
_online_check() {
if ! _online_check_tool; then
printf "\n Installer wouldn't work offline\n\n Please check your internet connection and try again\n\n"
exit 0
fi
}
_online_check
# Check dependencies for this script
_check_dependency() {
AMDEPENDENCES="chmod chown grep"
for dependency in $AMDEPENDENCES; do
if ! command -v "$dependency" >/dev/null 2>&1; then
printf "\n %b💀 ERROR! MISSING ESSENTIAL COMMAND \033[0m: %b\n\n Install the above and try again! \n\n" "${RED}" "$dependency"
exit 1
fi
done
}
_check_dependency
_script_downloader() {
if command -v wget >/dev/null 2>&1; then
wget -q "$URL" -O "$SCRIPT"
elif command -v curl >/dev/null 2>&1; then
curl -Lo "$SCRIPT" "$URL" 2>/dev/null
fi
}
# INSTALL "AM" SYSTEM-WIDE
_install_am() {
CACHEDIR="${XDG_CACHE_HOME:-$HOME/.cache}"
URL="https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/INSTALL"
SCRIPT="$CACHEDIR/INSTALL-AM.sh"
mkdir -p "$CACHEDIR" || true
rm -f "$CACHEDIR"/INSTALL-AM.sh || true
_script_downloader && chmod a+x "$CACHEDIR"/INSTALL-AM.sh
#cp ./INSTALL "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh # for developers
if command -v sudo >/dev/null 2>&1; then
SUDOCMD="sudo"
elif command -v doas >/dev/null 2>&1; then
SUDOCMD="doas"
else
echo "ERROR: No sudo or doas found"
exit 1
fi
$SUDOCMD "$CACHEDIR"/INSTALL-AM.sh && rm -f "$CACHEDIR"/INSTALL-AM.sh
}
# INSTALL "AM" LOCALLY, AS "APPMAN"
_install_appman() {
ZSHRC="${ZDOTDIR:-$HOME}/.zshrc"
BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
mkdir -p "$BINDIR"
if ! echo "$PATH" | grep "$BINDIR" >/dev/null 2>&1; then
echo '--------------------------------------------------------------------------'
echo " Adding $BINDIR to PATH, you might need to"
echo " close and reopen the terminal for this to take effect."
if [ -e ~/.bashrc ] && ! grep 'PATH="$PATH:$BINDIR"' ~/.bashrc >/dev/null 2>&1; then
printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> ~/.bashrc
printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> ~/.bashrc
printf ' export PATH="$PATH:$BINDIR"\nfi\n' >> ~/.bashrc
fi
if [ -e "$ZSHRC" ] && ! grep 'PATH="$PATH:$BINDIR"' "$ZSHRC" >/dev/null 2>&1; then
printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> "$ZSHRC"
printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> "$ZSHRC"
printf ' export PATH="$PATH:$BINDIR"\nfi\n' >> "$ZSHRC"
fi
fi
URL="https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/APP-MANAGER"
SCRIPT="$BINDIR/appman"
echo '--------------------------------------------------------------------------'
printf " %bInstalling \"AppMan\" in %b\033[0m\n" "${Green}" "$BINDIR"
_script_downloader && chmod a+x "$BINDIR"/appman
echo '--------------------------------------------------------------------------'
printf " %bThe following modules will be installed gradually, as you use AppMan\033[0m\n" "${Green}"
MODULES=$(sort "$SCRIPT" | tr '"' '\n' | grep "[a-z]\.am$")
for module_name in $MODULES; do
echo " ◆ https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/modules/$module_name"
done
echo '--------------------------------------------------------------------------'
printf " %b\"AppMan\" has been successfully installed! \033[0m\n" "${Green}"
printf " Please, run \"%bappman -h\033[0m\" to see the list of the options.\n" "${LightBlue}"
echo '--------------------------------------------------------------------------'
}
# CHOOSE BETWEEN "AM" AND "APPMAN"
echo "$DIVIDING_LINE"
printf "
Choose how to install \"AM\" and its managed applications:
1. System Installation, as \"%bAM\033[0m\"
- Command : %bam\033[0m
- Path : symlink /usr/local/bin/am → /opt/am/APP-MANAGER
- Programs : installed in /opt or locally
- Root : YES, only for installations and removals
- Ownership : only you have read-write permissions
- Target : power users
- Others : can only use programs and AppMan mode
2. Local Installation, as \"%bAppMan\033[0m\"
- Command : %bappman\033[0m
- Path : %b/.local/bin/appman
- Programs : can be installed anywhere
- Root : NO
- Ownership : anyone with read-write access in %b
- Target : anyone
- Others : can have separate configs or replicate yours
\n" "${RED}" "${Green}" "${LightBlue}" "${Green}" "$HOME" "$HOME" | _fit
read -r -p " Choose between \"AM\" (type 1) and \"AppMan\" (2), or leave blank to exit: " response
case "$response" in
1) _install_am || exit 1
;;
2) _install_appman || exit 1
;;
''|*)
echo "$DIVIDING_LINE"
echo "Installation aborted, exiting." && echo "$DIVIDING_LINE" && exit 1
;;
esac