-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaoi-verify-and-link
executable file
·41 lines (35 loc) · 1.08 KB
/
aoi-verify-and-link
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
#!/bin/bash -e
function fail {
echo "$@"
exit 1
}
function verify_and_link {
cd "$dist"
gpg --verify SHA256SUMS.gpg SHA256SUMS > /dev/null 2>&1 || fail "Signature validaiton failed"
image=$(ls -rt1 *.img | tail -1)
cat SHA256SUMS | grep $image > to_verify
HASH=$(cat SHA256SUMS | grep $image | awk '{ print $1 }')
sha256sum -c to_verify
rm -f to_verify
cd ..
ln -vf "$dist/$image" $HASH.baseimg
ln -vsf $HASH.baseimg $dist.baseimg
}
if [ "$*" == "" ]; then
echo "Must supply distributions to sync. Example:"
echo " $0 xenial trusty"
fi
IMAGES_DIR="$(aoi config get images_dir /var/lib/libvirt/images/aoi)"
cd $IMAGES_DIR
ROOT="$(pwd)"
DISTRIBUTIONS="$@"
# Import GPG keys needed to validate cloud images.
gpg --import /usr/share/keyrings/ubuntu-cloudimage-keyring.gpg > /dev/null 2>&1
gpg --keyserver keyserver.ubuntu.com --recv-keys 7DB87C81 > /dev/null 2>&1
for dist in $DISTRIBUTIONS; do
cd "$ROOT"
echo "Validating and linking $dist..."
verify_and_link $dist
done
echo ""
echo "Success. Verified images can be found in: $ROOT"