-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathget-resource.sh
executable file
·78 lines (64 loc) · 2.66 KB
/
get-resource.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
70
71
72
73
74
75
76
77
78
#!/bin/bash
#CACHEURL=http://172.22.0.1/images
set -eux
# Check and set http(s)_proxy. Required for cURL to use a proxy
export http_proxy="${http_proxy:-${HTTP_PROXY:-}}"
export https_proxy="${https_proxy:-${HTTPS_PROXY:-}}"
export no_proxy="${no_proxy:-${NO_PROXY:-}}"
# configurable variables
SHARED_DIR="${SHARED_DIR:-/shared}"
curl_with_flags() {
if [ "${CURL_VERBOSE:-}" = true ]; then
set -- --verbose "$@"
fi
if [ "${CURL_INSECURE:-}" = true ]; then
set -- --insecure "$@"
fi
curl "$@"
}
# Which image should we use
IPA_BASEURI="${IPA_BASEURI:-https://tarballs.opendev.org/openstack/ironic-python-agent/dib}"
IPA_BRANCH="$(echo "${IPA_BRANCH:-master}" | tr / -)"
IPA_FLAVOR="${IPA_FLAVOR:-centos9}"
FILENAME="${FILENAME:-ipa-${IPA_FLAVOR}-${IPA_BRANCH}.tar.gz}"
FILENAME_NO_EXT="${FILENAME%%.*}"
DESTNAME="ironic-python-agent"
mkdir -p "${SHARED_DIR}"/html/images "${SHARED_DIR}"/tmp
cd "${SHARED_DIR}"/html/images
TMPDIR="$(mktemp -d -p "${SHARED_DIR}"/tmp)"
# If we have a CACHEURL and nothing has yet been downloaded
# get header info from the cache
if [ -n "${CACHEURL:-}" ] && [ ! -e "${FILENAME}.headers" ]; then
curl_with_flags -g --fail -O "${CACHEURL}/${FILENAME}.headers" || true
fi
# Download the most recent version of IPA
if [ -r "${DESTNAME}.headers" ] ; then
ETAG="$(awk '/ETag:/ {print $2}' "${DESTNAME}.headers" | tr -d "\r")"
cd "${TMPDIR}"
curl_with_flags -g --dump-header "${FILENAME}.headers" \
-O "${IPA_BASEURI}/${FILENAME}" \
--header "If-None-Match: ${ETAG}" || cp "${SHARED_DIR}/html/images/${FILENAME}.headers" .
# curl didn't download anything because we have the ETag already
# but we don't have it in the images directory
# Its in the cache, go get it
ETAG="$(awk '/ETag:/ {print $2}' "${FILENAME}.headers" | tr -d "\"\r")"
if [ ! -s "${FILENAME}" ] && [ ! -e "${SHARED_DIR}/html/images/${FILENAME_NO_EXT}-${ETAG}/${FILENAME}" ]; then
mv "${SHARED_DIR}/html/images/${FILENAME}.headers" .
curl_with_flags -g -O "${CACHEURL}/${FILENAME_NO_EXT}-${ETAG}/${FILENAME}"
fi
else
cd "${TMPDIR}"
curl_with_flags -g --dump-header "${FILENAME}.headers" -O "${IPA_BASEURI}/${FILENAME}"
fi
if [ -s "${FILENAME}" ]; then
tar -xaf "${FILENAME}"
ETAG="$(awk '/ETag:/ {print $2}' "${FILENAME}.headers" | tr -d "\"\r")"
cd -
chmod 755 "${TMPDIR}"
mv "${TMPDIR}" "${FILENAME}-${ETAG}"
ln -sf "${FILENAME}-${ETAG}/${FILENAME}.headers" "${DESTNAME}.headers"
ln -sf "${FILENAME}-${ETAG}/${FILENAME_NO_EXT}.initramfs" "${DESTNAME}.initramfs"
ln -sf "${FILENAME}-${ETAG}/${FILENAME_NO_EXT}.kernel" "${DESTNAME}.kernel"
else
rm -rf "${TMPDIR}"
fi