-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaoi-fetch-latest-image
executable file
·31 lines (26 loc) · 1.01 KB
/
aoi-fetch-latest-image
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
#!/bin/bash -e
DISTRO=$1
if [ "$DISTRO" == "" ]; then
echo "Must supply a distribution name. For example:"
echo " $0 xenial"
exit 1
fi
IMAGES_DIR="$(aoi config get images_dir /var/lib/libvirt/images/aoi)"
DISTRO_IMAGES=$IMAGES_DIR/$DISTRO
mkdir -p $DISTRO_IMAGES
# Set premissions so that both KVM and the current user will retain access
# to the synced images. (Usually the libvirt-qemu user grabs ownership of
# the images, which may prevent a future rsync from working properly.)
chown $USER:kvm $IMAGES_DIR
# These commands will start to fail once VMs are created, but we don't want
# tne entire script to fail.
setfacl -m default:user:$UID:rwX -R $IMAGES_DIR 2> /dev/null || true
setfacl -m user:$UID:rwX -R $IMAGES_DIR 2> /dev/null || true
cd $DISTRO_IMAGES
rsync \
--verbose --recursive --times --links --prune-empty-dirs \
--include '*-amd64-disk1.img' \
--include '*-amd64.img' \
--include 'SHA256*' \
--exclude '*' \
rsync://cloud-images.ubuntu.com/cloud-images/$DISTRO/current/ .