This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstaller-prep
executable file
·311 lines (261 loc) · 9.45 KB
/
installer-prep
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/bash
#
# This script looks at the operating system, architecture, bit type, etc., to determine
# whether or not the system is supported by Mewdeko. Once the system is deemed as
# supported, the main installer will be downloaded and executed.
#
########################################################################################
#### [ Exported and/or Globally Used Variables ]
# Refer to the 'README' note at the beginning of 'linuxAIO' for more information.
current_linuxAIO_revision=4
# Name of the main installer script.
main_installer="mewdeko-main-installer"
# Similar to 'current_linuxAIO_revision', expecpt it's used as a more general tracking
# number. Instead of only being used to represent the relationship between this script
# and 'linuxAIO', it represents major changes to the installer that requires a change in
# behavior, that would otherwise result in conflict with older verisons of the script.
export _REVISION_NUMBER=1
## Modify output text color.
# shellcheck disable=SC2155
{
export _YELLOW="$(printf '\033[1;33m')"
export _GREEN="$(printf '\033[0;32m')"
export _CYAN="$(printf '\033[0;36m')"
export _RED="$(printf '\033[1;31m')"
export _NC="$(printf '\033[0m')"
export _GREY="$(printf '\033[0;90m')"
export _CLRLN="$(printf '\r\033[K')"
}
#### End of [ Exported and/or Globally Used Variables ]
########################################################################################
#### [ Functions ]
########
# Identify the operating system, version number, architecture, bit type (32 or 64), etc.
#
# Arguments:
# None
########
detect_sys_info() {
if [[ -f /etc/os-release ]]; then
# shellcheck disable=SC1091
. /etc/os-release
_DISTRO="$ID"
_VER="$VERSION_ID" # Version: x.x.x...
_SVER=${_VER//.*/} # Version: x
pname="$PRETTY_NAME"
else
_DISTRO=$(uname -s)
_VER=$(uname -r)
fi
## Identify bit and architecture type.
case $(uname -m) in
x86_64) bits="64"; _ARCH="x64" ;;
i*86) bits="32"; _ARCH="x86" ;;
armv*) bits="32"; _ARCH="?" ;;
*) bits="?"; _ARCH="?" ;;
esac
}
########
# Download the latest version of 'linuxAIO' if $_LINUXAIO_REVISION and
# $current_linuxAIO_revision aren't of equal value.
#
# Arguments:
# None
########
linuxAIO_update() {
echo -n "${_YELLOW}You are using an older version of 'linuxAIO'. "
read -rp "Press [Enter] to download the latest version.${_NC}"
echo "Downloading latest version of 'linuxAIO'..."
## Only download the newest version of 'linuxAIO', as there are some incompatible
## changes to 'linuxAIO' making it difficult or impossible to merge existing
## configurations.
if ((_LINUXAIO_REVISION <= 3)); then
if [[ -f linuxAIO.sh ]]; then
echo "Backing up 'linuxAIO.sh' as 'linuxAIO.sh.old'..."
mv linuxAIO.sh linuxAIO.sh.old
elif [[ -f linuxAIO ]]; then
echo "Backing up 'linuxAIO' as 'linuxAIO.old'..."
mv linuxAIO linuxAIO.old
fi
curl -O "$_RAW_URL"/linuxAIO && sudo chmod +x linuxAIO
echo "${_CYAN}NOT applying existing configurations to 'linuxAIO'"
echo "${_GREEN}Successfully downloaded the newest version of 'linuxAIO'.${_NC}"
## Download the newest version of 'linuxAIO' and apply existing changes to it.
else
## Save the values of the current Configuration Variables specified in
## 'linuxAIO', to be set in the new 'linuxAIO'.
local installer_branch
local installer_branch_found
installer_branch=$(grep '^installer_branch=.*' linuxAIO)
installer_branch_found="$?"
local bot_install_version
local bot_install_version_found
bot_install_version=$(grep '^export _BOT_INSTALL_VERSION=.*' linuxAIO)
bot_install_version_found="$?"
curl -O "$_RAW_URL"/linuxAIO && sudo chmod +x linuxAIO
echo "Applying existing configurations to the new 'linuxAIO'..."
# Set $installer_branch inside of the new 'linuxAIO'.
[[ $installer_branch_found = 0 ]] \
&& sed -i "s/^installer_branch=.*/$installer_branch/" linuxAIO
# Set $bot_install_version inside of the new 'linuxAIO'.
[[ $bot_install_version_found = 0 ]] \
&& sed -i "s/^export _BOT_INSTALL_VERSION=.*/$bot_install_version/" linuxAIO
echo "${_GREEN}Successfully downloaded the newest version of 'linuxAIO' and" \
"applied changes to the newest version of 'linuxAIO'${_NC}"
fi
clean_up "0" "Exiting" "true"
}
########
# Provide the end-user with the option to continue, even if their system isn't
# officially supported.
#
# Arguments:
# None
########
unsupported() {
echo "${_RED}Your operating system is not OFFICIALLY supported for the" \
"installation, setup, and/or use of Mewdeko" >&2
echo "${_YELLOW}WARNING: By continuing, you accept that unexpected behaviors" \
"may occur. If you run into any errors or problems with the installation and" \
"use of the Mewdeko, you are on your own.${_NC}"
read -rp "Would you like to continue anyways? [y/N] " choice
choice=$(echo "$choice" | tr '[:upper:]' '[:lower:]')
case "$choice" in
y|yes) clear -x; execute_main_installer ;;
*) clean_up "0" "Exiting" ;;
esac
}
########
# Cleanly exit the installer by removing files that aren't required unless the installer
# is currently running.
#
# Arguments:
# $1 - required
# Exit code.
# $2 - required
# Output text.
# $3 - optional
# True if 'Cleaning up...' should be printed with two new-line symbols.
########
clean_up() {
# Files to be removed.
local installer_files=("installer-prep" "mewdeko-runner" "prereqs-installer"
"mewdeko-latest-installer" "mewdeko-main-installer")
if [[ $3 = true ]]; then echo -e "\n\nCleaning up..."
else echo -e "\nCleaning up..."
fi
cd "$_WORKING_DIR" || _STDERR "Failed to move to Mewdeko's root directory" "1"
[[ -d Mewdeko_tmp ]] && rm -rf Mewdeko_tmp
for file in "${installer_files[@]}"; do
[[ -f $file ]] && rm "$file"
done
echo "$2..."
exit "$1"
}
########
# Download and execute $main_installer.
#
# Arguments:
# None
########
execute_main_installer() {
_DOWNLOAD_SCRIPT "$main_installer" "true"
./"$main_installer"
clean_up "$?" "Exiting"
}
########################################################################################
#### [[ Functions To Be Exported ]]
########
# Download the specified script and modify it's execution permissions.
#
# Arguments:
# $1 - required
# Name of the script to download.
# $2 - optional
# True if the script should output text indicating $1 is being downloaded.
########
_DOWNLOAD_SCRIPT() {
[[ $2 = true ]] && printf "Downloading '%s'..." "$1"
curl -O -s "$_RAW_URL"/"$1"
sudo chmod +x "$1"
}
########
# Output an error message, and if desired, exit the script.
#
# Arguments:
# $1 - required
# Error message.
# $2 - optional
# If provided, exit with the provided value.
# $3 - optional
# If provided, output an additional message.
########
_STDERR() {
echo "${_RED}$1${_NC}" >&2
[[ $3 ]] && echo -e "$3"
[[ $2 ]] && exit "$2"
}
#### End of [[ Functions To Be Exported ]]
########################################################################################
#### End of [ Functions ]
########################################################################################
#### [ Error Traps ]
trap 'clean_up "130" "Exiting" "true"' SIGINT
trap 'clean_up "143" "Exiting" "true"' SIGTERM
trap 'clean_up "148" "Exiting" "true"' SIGTSTP
#### End of [ Error Traps ]
########################################################################################
#### [ Prepping ]
# If the current 'linuxAIO' revision number is not of equil value of the expected
# revision number...
if [[ $_LINUXAIO_REVISION && $_LINUXAIO_REVISION != "$current_linuxAIO_revision" ]]; then
linuxAIO_update
clean_up "0" "Exiting"
fi
# Change the working directory to the location of the executed script.
cd "${0%/*}" || {
echo "${_RED}Failed to change working directory" >&2
echo "${_CYAN}Change your working directory to that of the executed script${_NC}"
clean_up "1" "Exiting"
}
export _WORKING_DIR="$PWD"
export _INSTALLER_PREP="$_WORKING_DIR/installer-prep"
#### End of [ Prepping ]
########################################################################################
#### [ Main ]
clear -x
detect_sys_info
export _DISTRO _SVER _VER _ARCH
export -f _DOWNLOAD_SCRIPT _STDERR
# Use $_DISTRO if $pname is unset or null...
echo "SYSTEM INFO
Bit Type: $bits
Architecture: $_ARCH
Distro: ${pname:=$_DISTRO}
Distro Version: $_VER
"
### Check if the operating system is supported by Mewdeko and the installer.
if [[ $bits = 64 ]]; then
if [[ $_DISTRO = "ubuntu" ]]; then
case "$_VER" in
22.04|20.04|18.04) execute_main_installer ;;
*) unsupported ;;
esac
elif [[ $_DISTRO = "debian" ]]; then
case "$_SVER" in
11|10) execute_main_installer ;;
*) unsupported ;;
esac
elif [[ $_DISTRO = "linuxmint" ]]; then
case "$_SVER" in
21|20) execute_main_installer ;;
*) unsupported ;;
esac
else
unsupported
fi
else
unsupported
fi
#### End of [ Main ]
########################################################################################