-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·51 lines (43 loc) · 1.28 KB
/
setup.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
#!/bin/bash
# Generic error handling header, credit to https://stelfox.net/blog/2013/11/fail-fast-in-bash-scripts/
function error_handler() {
echo "Error occurred in script at line: ${1}."
echo "Line exited with status: ${2}"
}
trap 'error_handler ${LINENO} $?' ERR
set -o errexit
set -o errtrace
set -o pipefail
set -o nounset
function setupFor {
if [[ ! -d "$1" ]]; then
echo "Clone the appropriate version of the $1 elm package to ./$1 so I can ZIP it"
exit 1
fi
echo "ZIPing $1/ to $1.zip (following symlinks; excluding .git/ and elm-stuff/)"
zip --exclude '*.git*' --exclude '*elm-stuff*' -r -FS "$1.zip" "$1"
# Hash it
echo # space after `zip` output
echo "Hashing the ZIP"
if command -v shasum &> /dev/null; then
shacmd=shasum
elif command -v sha1sum &> /dev/null; then
shacmd=sha1sum
else
echo
echo "Oh no, neither 'shasum' nor 'sha1sum' are available programs."
echo "Quitting without updating $1-data/endpoint.json"
exit 1
fi
ziphash=$($shacmd "$1.zip" | cut -f 1 -d " ")
echo "SHA-1 hash of $1.zip is $ziphash"
# Update endpoint.json
echo "Updating $1-data/endpoint.json"
echo "{
\"url\": \"http://localhost:8080/$1.zip\",
\"hash\": \"$ziphash\"
}" > "$1-data/endpoint.json"
echo
echo
}
setupFor browser