-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
61 lines (53 loc) · 1.27 KB
/
update.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
#!/usr/bin/env bash
{ # Ensure the whole file is downloaded first before executing
set -euo pipefail
help() {
echo "Update journald-exporter" >&2
echo "Usage: $0" >&2
exit "$1"
}
while getopts ':h' arg; do
case "$arg" in
h)
help 0
;;
*)
help 1
;;
esac
done
REMOTE_URL=https://github.com/dead-claudia/journald-exporter/releases/latest/download/journald-exporter
SERVICE_NAME=journald-exporter.service
BINARY_NAME=journald-exporter
TMP_DIR="$(pwd)"
rm -r "$TMP_DIR"
mkdir --mode=600 "$TMP_DIR"
if which curl; then
curl \
--output "$BINARY_NAME" \
--fail \
--silent \
--show-error \
--connect-timeout 5 \
--retry 5 \
--retry-all-errors \
--max-time 30 \
--location \
"$REMOTE_URL"
elif which wget; then
wget \
--tries 5 \
--timeout 5 \
--waitretry 5 \
--retry-connrefused 5 \
--output-document "$BINARY_NAME" \
"$REMOTE_URL"
else
echo 'Neither curl nor wget detected. Please ensure one of those is installed before' >&2
echo 'running this script.' >&2
exit 1
fi
chmod 755 "$BINARY_NAME"
mv "$BINARY_NAME" "/usr/sbin/$BINARY_NAME"
systemctl restart "$SERVICE_NAME"
}