-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommon.sh
More file actions
executable file
·46 lines (39 loc) · 1.3 KB
/
common.sh
File metadata and controls
executable file
·46 lines (39 loc) · 1.3 KB
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
#!/usr/bin/env bash
# Helpers functions library to be sourced by appscale-thirdparties scripts.
set -eu
PACKAGE_CACHE='/var/cache/appscale'
PACKAGE_MIRROR='http://s3.amazonaws.com/appscale-build'
log() {
local LEVEL=${2:-INFO}
echo "$(date +'%Y-%m-%d %T') $LEVEL $1"
}
cachepackage() {
cached_file="${PACKAGE_CACHE}/$1"
remote_file="${PACKAGE_MIRROR}/$1"
expected_sha384="$2"
mkdir -p ${PACKAGE_CACHE}
if [ -f ${cached_file} ]; then
actual_sha384=($(sha384sum ${cached_file}))
if [ "${actual_sha384}" = "${expected_sha384}" ]; then
return 0
else
log "Incorrect sha384sum for ${cached_file}. Removing it." "ERROR"
rm ${cached_file}
fi
fi
log "Fetching ${remote_file}"
if ! curl -fs "${remote_file}" > "${cached_file}"; then
log "Error while downloading ${remote_file}" "ERROR"
return 1
fi
actual_sha384=($(sha384sum ${cached_file}))
if [ "${actual_sha384}" = "${expected_sha384}" ]; then
return 0
else
log "sha384 sum of downloaded file is ${actual_sha384} though ${expected_sha384} was expected" "ERROR"
log "Try downloading package manually to ${cached_file} and running script again"
rm ${cached_file}
return 1
fi
}
export PACKAGE_CACHE