-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-dotter.sh
68 lines (57 loc) · 1.93 KB
/
update-dotter.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
#!/usr/bin/env bash
# Exit on error
set -e
if curl --version &>/dev/null; then
echo "Using curl for HTTP requests."
HTTP_TOOL="curl"
elif wget --version &>/dev/null; then
echo "Using wget for HTTP requests."
HTTP_TOOL="wget"
else
>&2 echo "ERROR: Neither Curl nor Wget is installed!"
exit 1
fi
function download_file() {
case $HTTP_TOOL in
"curl")
# -L = follow redirects
# For some reason, GitHub lets you bypass ratelimiting by sending an authorization header...
curl -qL $1 -H "Authorization: no" 2>/dev/null
;;
"wget")
# -q = silent, -O - = write output to stdout
wget -qO - --header="Authorization: no" $1
;;
esac
}
function download_latest_release() {
local url="https://api.github.com/repos/SuperCuber/dotter/releases/latest"
local download_urls
download_urls=$(download_file "$url" | jq --raw-output ".assets | map(.browser_download_url) | .[]")
for line in $download_urls; do
local filename=$(echo "$line" | rev | cut -d / -f 1 | rev)
echo "Downloading \"$filename\"..."
# Overwrite dotter installation
download_file "$line" >"$filename"
echo "FINISHED downloading \"$filename\""
if [[ $filename != *.exe ]]; then
echo "Adding EXECUTE permissions to ./$filename"
chmod +x "./$filename"
fi
done
# Example value: 'Dotter 1.0.0'
local dotter_version=$(./dotter --version 2>/dev/null)
if [[ $dotter_version != "" ]]; then
echo "Successfully downloaded $dotter_version"
else
>&2 echo "ERROR: Couldn't download the dotter update!"
fi
}
# Print stderr in red and stdout in green
download_latest_release 2> >(while read -r line; do echo -e "\e[01;31m$line\e[0m" >&2; done) 1> >(while read -r line; do echo -e "\e[01;32m$line\e[0m" >&2; done)
# Remove the completions.zip file if it exists
if [ -f "completions.zip" ]; then
echo "Removing completions.zip..."
rm "completions.zip"
echo "completions.zip removed."
fi