forked from coreos/coreos-xhyve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coreos-xhyve-fetch
executable file
·63 lines (48 loc) · 1.82 KB
/
coreos-xhyve-fetch
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
#!/bin/bash
set -e -o pipefail
getVersionID () {
declare channel="$1"
v_url="http://${channel}.release.core-os.net/amd64-usr/current/version.txt"
curl -Lsk "${v_url}" | grep COREOS_VERSION_ID= | sed -e 's,.*=,,'
}
CHANNEL=${CHANNEL:-alpha}
VERSION=${VERSION:-$(getVersionID ${CHANNEL})}
# Ensure that required executables exist before proceeding
which curl >/dev/null || (echo "CURL is required." && exit 1)
type gpg 2>&1 > /dev/null || echo "GPG was not found. Downloaded images integrity won't be verified."
# Everything we do should be user-access only!
umask 077
# Pre-flight checks pass, lets get this party started!
WORKDIR=$(mktemp -d coreos-install.XXXXXXXXXX)
trap "rm -rf '${WORKDIR}'" EXIT
chmod 700 ${WORKDIR}
# Image signing key: [email protected]
GPG_LONG_ID="48F9B96A2E16137F"
GPG_KEY_FILENAME=CoreOS_Image_Signing_Key.asc
GPG_KEY_URL=https://coreos.com/security/image-signing-key/$GPG_KEY_FILENAME
curl $GPG_KEY_URL > $WORKDIR/$GPG_KEY_FILENAME
# Setup GnuPG for verifying the image signature
export GNUPGHOME="${WORKDIR}/gnupg"
mkdir "${GNUPGHOME}"
type gpg 2>&1 > /dev/null && gpg --batch --quiet --import < $WORKDIR/$GPG_KEY_FILENAME
function get {
FILE=$1
if [ -f imgs/${CHANNEL}.${VERSION}.${FILE} ]; then
echo "found cached $FILE (${CHANNEL}/${VERSION})"
return
fi
cd ${WORKDIR}
curl "${ROOT}${FILE}" > ${FILE}
curl "${ROOT}${FILE}.sig" > ${FILE}.sig
cd -
type gpg 2>&1 > /dev/null && gpg --batch --trusted-key "${GPG_LONG_ID}" \
--verify "${WORKDIR}/${FILE}.sig" "${WORKDIR}/${FILE}"
mv ${WORKDIR}/${FILE} imgs/${CHANNEL}.${VERSION}.${FILE}
mv ${WORKDIR}/${FILE}.sig imgs/${CHANNEL}.${VERSION}.${FILE}.sig
}
mkdir -p imgs
ROOT=http://${CHANNEL}.release.core-os.net/amd64-usr/${VERSION}/
VMLINUZ=coreos_production_pxe.vmlinuz
INITRD=coreos_production_pxe_image.cpio.gz
get $VMLINUZ
get $INITRD