-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·166 lines (131 loc) · 3.87 KB
/
install.sh
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
#!/usr/bin/env bash
# shellcheck disable=SC2164
# Folder for the installation environment
# shellcheck disable=SC2153
TEMP="$PREFIX/tmp"
TEMP_DIR="$TEMP/dotload-installer"
LOG_FILE="$TEMP/dotload-installer.log"
EXECUTABLE_LINK="https://github.com/okineadev/dotload/releases/latest/download/dotload"
mkdir "$TEMP_DIR"
if [[ ! -f $LOG_FILE ]]; then
# Create log file in temporary dir
touch "$LOG_FILE"
else
# Clear all logs
echo "" > "$LOG_FILE"
fi
# Modifiable prefix variable
prefix="$PREFIX"
sudo="sudo"
pkgmgr=""
update="update"
install="install -y"
# If Linux OS or msys (linux emulator on Windows)
if echo "$OSTYPE" | grep -qE '^(linux-gnu|msys).*'; then
if [ -f '/etc/debian_version' ]; then
pkgmgr="apt"
elif [[ -f '/etc/arch-release' || "$OSTYPE" =~ ^msys.*$ ]]; then
pkgmgr="pacman"
install="-Sy --noconfirm"
update="-Sy"
if echo "$OSTYPE" | grep -qE '^msys.*'; then
# Because `sudo` in msys shell (on Windows™) are useless
sudo=""
fi
fi
# macOS
elif echo "$OSTYPE" | grep -qE '^darwin.*'; then
pkgmgr="brew"
install="install"
# The `/bin` directory in macOS is read-only, so you need to install the binary in `/usr/local`
# https://github.com/openstreetmap/mod_tile/issues/349#issuecomment-1784165860
prefix="/usr/local"
# Termux
elif echo "$OSTYPE" | grep -qE '^linux-android.*'; then
pkgmgr="pkg"
sudo=""
fi
# Remove color markings from text (necessary to make logs cleaner)
normalize() {
echo -e "$1" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"
}
# Write the text in the log
write_log() {
echo -e "\e[1;32m↪\e[0m $1"
echo -e "$(normalize "$1")" >> "$LOG_FILE"
}
log() {
# shellcheck disable=SC2124
local command="$@"
# Executes the command, after which writes its output to the log
$command 2>&1 | tee -a "$LOG_FILE"
}
available() {
command -v $1 >/dev/null
}
current_step=0
steps=3
if [[ ! $SKIP_CHECKSUM_VALIDATION == "true" ]]; then
((steps++))
fi
step() {
((current_step++))
write_log "[$current_step/$steps] \e[1m$1\e[0m"
}
shasum_cmd=""
if available sha256; then
shasum_cmd="sha256sum"
elif available shasum; then
shasum_cmd="shasum -a 256"
else
SKIP_CHECKSUM_VALIDATION="true"
write_log "Skipping checksum validation"
fi
validate_checksum() {
log $shasum_cmd --quiet --status -c $@
}
cd "$TEMP_DIR"
echo ""
step "Downloading executable"
log curl -LO --progress-bar "$EXECUTABLE_LINK"
if [[ ! $SKIP_CHECKSUM_VALIDATION == "true" ]]; then
# ((steps++))
step "Validating checksum"
log curl -LOs "$EXECUTABLE_LINK.sha256"
# File integrity check
if validate_checksum dotload.sha256; then
write_log "✅ Checksum validated"
else
write_log "❌ The checksum is invalid, please try again"
write_log " If the result is the same - report the error at this link: https://github.com/okineadev/dotload/issues/new?assignees=okineadev&labels=bug&template=bug_report.md&title=[Bug]:+invalid+checksum"
log rm -rf "$TEMP_DIR"
exit 1
fi
fi
# Makes the script executable
log chmod +x dotload
if [[ -f "$prefix/bin/dotload" ]]; then
step "Updating"
else
step "Installing"
fi
if ! available git; then
step "Installing dependencies"
if [[ ! -n "$pkgmgr" ]]; then
write_log "$pkgmgr in not defined\nPlease install \e[1mgit\e[0m manually."
exit 1
else
if [[ "$pkgmgr" == "brew" ]]; then
if ! command -v brew >/dev/null; then
# Code from https://brew.sh/#install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
fi
# shellcheck disable=SC2086
$sudo $pkgmgr $install git
fi
fi
log $sudo cp dotload "$prefix/bin"
step "Cleaning"
log rm -rf "$TEMP_DIR"
echo -e "\n\e[1;32mDone!\e[0m"