-
Notifications
You must be signed in to change notification settings - Fork 779
/
Copy pathget-assets.sh
executable file
·69 lines (56 loc) · 1.58 KB
/
get-assets.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
69
#!/bin/bash
set -euo pipefail
if [[ `id -u` -eq 0 ]]; then
echo "ERROR: running as root is not supported"
echo "Please run 'export UID' before running docker-compose!"
exit 1
fi
if [ $# -lt 4 ]; then
echo "ERROR: use $0 <folder> <url> <prefix> <all> [subfolder1 [subfolder2]]"
exit 1
fi
FOLDER=$1
URL=$2
PREFIX=$3
ALL=$4
shift 4
SUBFOLDERS=${@:-all}
# split by comma
SUBFOLDERS=$(echo ${SUBFOLDERS} | tr ',' ' ')
if [ "${FORCE_REBUILD}" == "true" ]; then
ALL=1
fi
function list_folders {
echo SUBFOLDERS=${SUBFOLDERS} > /dev/stderr
if [ "${SUBFOLDERS}" == "all" ]; then
find ${FOLDER} -mindepth 1 -maxdepth 1 -type d
else
for subfolder in ${SUBFOLDERS}; do
path=${FOLDER}/$subfolder
if [ -d "$path" ]; then
echo $path
else
echo "Can't asset find folder ${path}" > /dev/stderr
fi
done
fi
}
for f in $(list_folders); do
NAME=`basename "${f}"`
if [[ ! "${NAME}" =~ "@tmp" ]]; then
ID=`GIT_DIR="${f}/.git" git rev-parse HEAD`
if [ "${ALL}" -eq "1" ]; then
echo $ID $NAME
else
CHECK=`curl -sILw '%{http_code}\n' "https://${URL}/${ID}/${PREFIX}_${NAME}" -o /dev/null || true`
if [ "${CHECK}" -ne "200" ]; then
echo "https://${URL}/${ID}/${PREFIX}_${NAME} doesn't exist, include it in the build" >&2
echo $ID $NAME
else
echo "https://${URL}/${ID}/${PREFIX}_${NAME} does exist, skip building it (you can use FORCE_REBUILD to rebuild existing assets)" >&2
fi
fi
else
continue
fi
done