mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-10 14:36:58 +02:00
oem/ami: add support for importing VMDK images
This commit is contained in:
parent
65e185cef0
commit
7acc0759dc
@ -15,7 +15,7 @@ readonly COREOS_EPOCH=1372636800
|
|||||||
VERSION="master"
|
VERSION="master"
|
||||||
BOARD="amd64-usr"
|
BOARD="amd64-usr"
|
||||||
GROUP="alpha"
|
GROUP="alpha"
|
||||||
IMAGE="coreos_production_ami_image.bin.bz2"
|
IMAGE="coreos_production_ami_vmdk_image.vmdk.bz2"
|
||||||
GS_URL="gs://builds.release.core-os.net"
|
GS_URL="gs://builds.release.core-os.net"
|
||||||
IMG_URL=""
|
IMG_URL=""
|
||||||
IMG_PATH=""
|
IMG_PATH=""
|
||||||
@ -121,12 +121,22 @@ fi
|
|||||||
export EC2_URL="https://ec2.${region}.amazonaws.com"
|
export EC2_URL="https://ec2.${region}.amazonaws.com"
|
||||||
echo "Building AMI in zone ${EC2_IMPORT_ZONE}"
|
echo "Building AMI in zone ${EC2_IMPORT_ZONE}"
|
||||||
|
|
||||||
|
imgfmt=unknown
|
||||||
|
setfmt() {
|
||||||
|
case "$1" in
|
||||||
|
*_image.bin*) imgfmt=raw;;
|
||||||
|
*_image.vmdk*) imgfmt=vmdk;;
|
||||||
|
*_image.vhd*) imgfmt=vhd;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
tmpimg=$(mktemp)
|
tmpimg=$(mktemp)
|
||||||
trap "rm -f '${tmpimg}'" EXIT
|
trap "rm -f '${tmpimg}'" EXIT
|
||||||
|
|
||||||
# if it is on the local fs, just use it, otherwise try to download it
|
# if it is on the local fs, just use it, otherwise try to download it
|
||||||
if [[ -n "$IMG_PATH" ]]; then
|
if [[ -n "$IMG_PATH" ]]; then
|
||||||
if [[ "$IMG_PATH" =~ \.bz2$ ]]; then
|
setfmt "$IMG_PATH"
|
||||||
|
if [[ "$IMG_PATH" == *.bz2 ]]; then
|
||||||
bunzip2 -c "$IMG_PATH" >"${tmpimg}"
|
bunzip2 -c "$IMG_PATH" >"${tmpimg}"
|
||||||
else
|
else
|
||||||
rm -f "${tmpimg}"
|
rm -f "${tmpimg}"
|
||||||
@ -134,13 +144,20 @@ if [[ -n "$IMG_PATH" ]]; then
|
|||||||
tmpimg="$IMG_PATH"
|
tmpimg="$IMG_PATH"
|
||||||
fi
|
fi
|
||||||
elif [[ "$IMG_URL" == gs://* ]]; then
|
elif [[ "$IMG_URL" == gs://* ]]; then
|
||||||
|
setfmt "$IMG_URL"
|
||||||
gsutil cat "$IMG_URL" | bunzip2 >"${tmpimg}"
|
gsutil cat "$IMG_URL" | bunzip2 >"${tmpimg}"
|
||||||
else
|
else
|
||||||
|
setfmt "$IMG_URL"
|
||||||
curl --fail "$IMG_URL" | bunzip2 >"${tmpimg}"
|
curl --fail "$IMG_URL" | bunzip2 >"${tmpimg}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$imgfmt" == unknown ]]; then
|
||||||
|
echo "$0: Cannot guess image format from image path!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
importid=$(ec2-import-volume "${tmpimg}" \
|
importid=$(ec2-import-volume "${tmpimg}" \
|
||||||
-f raw -s $size -x 2 \
|
-f $imgfmt -s $size -x 2 \
|
||||||
-z "${EC2_IMPORT_ZONE}" \
|
-z "${EC2_IMPORT_ZONE}" \
|
||||||
-b "${EC2_IMPORT_BUCKET}" \
|
-b "${EC2_IMPORT_BUCKET}" \
|
||||||
-o "${AWS_ACCESS_KEY}" \
|
-o "${AWS_ACCESS_KEY}" \
|
||||||
|
Loading…
Reference in New Issue
Block a user