-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer
executable file
·82 lines (80 loc) · 2.78 KB
/
installer
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
#!/usr/bin/env bash
# curl -sSL https://wpeb-installer.includes.io | bash
WPEB_NOW=$(date +"%Y-%m-%d-%H%M")
WPEB_MAIN="https://wpeb-main.includes.io"
WPEB_TEMP="/tmp/wpeb.$WPEB_NOW"
WPEB_TARGET="/usr/local/bin/wpeb"
start_checks() {
if [ -f "$WPEB_TARGET" ]; then
# WPEB found, run update procedure ?
run_update
else
# WPEB not found in the regular location, let's run the install.
run_install
fi
}
run_update() {
# We already know the file exists from the check for old version,
# let's get the version and just compare.
# Go ahead with the download.
WPEB_TEMP_DL=$(curl -sSL "$WPEB_MAIN" -o "$WPEB_TEMP")
WPEB_DOWN_OK=$?
if [ "$WPEB_DOWN_OK" -ne 0 ]; then
# For some reason we couldn't download, let's bail.
echo ""
echo " *** For some reason, i couldn't download the latest version of WPEB"
echo " *** Maybe you want to have a look at the docs and try a manual install ?"
echo " *** https://niladam.github.io/wpeb ***"
echo ""
run_cleanup
exit 1
fi
WPEB_NEW_VERSION=$(grep WPEB_VER "$WPEB_TEMP" | head -1 | cut -d = -f2 | tr -d '"')
WPEB_OLD_VERSION=$(grep WPEB_VER "$WPEB_TARGET" | head -1 | cut -d = -f2 | tr -d '"')
WPEB_GT=$(echo "$WPEB_NEW_VERSION > $WPEB_OLD_VERSION" | bc -q )
if [ "$WPEB_GT" = 1 ]; then
# Got newer version, move to target file.
echo " *** New version found, $WPEB_NEW_VERSION. You have $WPEB_OLD_VERSION. Proceeding with install.."
mv -f "$WPEB_TEMP" "$WPEB_TARGET"
chmod +x "$WPEB_TARGET"
echo ""
echo " *** New version, $WPEB_NEW_VERSION was updated. Enjoy!"
echo ""
else
# Now that should be impossible!:)
echo " *** Apparently, the installed version is newer or current.."
echo " *** Current: $WPEB_OLD_VERSION // NEW: $WPEB_NEW_VERSION"
# echo " *** This can happen if the file has been manually modified and/or altered.."
echo " *** If you think this is a mistake, please open an issue at "
echo " *** https://github.com/niladam/wpeb/issues *** "
run_cleanup
exit 1
fi
}
run_install() {
WPEB_TEMP_DL=$(curl -sSL "$WPEB_MAIN" -o "$WPEB_TEMP")
WPEB_NEW_VERSION=$(grep WPEB_VER "$WPEB_TEMP" | head -1 | cut -d = -f2 | tr -d '"')
if [ "$WPEB_TEMP_DL" -ne 0 ]; then
# For some reason we couldn't download, let's bail.
echo ""
echo " *** For some reason, i couldn't download the latest version of WPEB"
echo " *** Maybe you want to have a look at the docs and try a manual install ?"
echo " *** https://niladam.github.io/wpeb ***"
echo ""
run_cleanup
exit 1
else
echo " *** WPEB not found on the system. Installing $WPEB_NEW_VERSION.."
mv -f "$WPEB_TEMP" "$WPEB_TARGET"
chmod +x "$WPEB_TARGET"
echo ""
echo " *** WPEB version $WPEB_NEW_VERSION was installed. Enjoy!"
echo ""
fi
}
run_cleanup() {
# Let's clean up after ourselves..
rm -rf "$WPEB_TEMP"
}
# We have everything, let's proceed.
start_checks