Created
March 12, 2021 21:55
-
-
Save hshimamoto/02fd1dd8124b101d6b8f3fc959245d56 to your computer and use it in GitHub Desktop.
Download cloudimage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
focal https://cloud-images.ubuntu.com/focal/current/ focal-server-cloudimg-amd64.img MD5SUMS | |
bionic https://cloud-images.ubuntu.com/bionic/current/ bionic-server-cloudimg-amd64.img MD5SUMS | |
xenial https://cloud-images.ubuntu.com/xenial/current/ xenial-server-cloudimg-amd64-disk1.img MD5SUMS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd $(dirname $0) | |
if [ $# -lt 1 ]; then | |
echo "update.sh <conf file>" | |
exit 1 | |
fi | |
conf=$1 | |
echo $conf | |
if [ ! -e $conf ]; then | |
echo "no $conf" | |
exit 1 | |
fi | |
IMGDIR=~/vm/images | |
check_and_download() { | |
local suit=$1 | |
local url=$2 | |
local img=$3 | |
local chksum=$4 | |
echo $suit $url $img $chksum | |
# get chksum | |
curl -qLO $url/$chksum | |
if [ $? -ne 0 ]; then | |
echo "ERROR: $suit: download checksum" | |
return | |
fi | |
if [ -e $chksum.$suit ]; then | |
prevsum=$(cat $chksum.$suit) | |
newsum=$(grep $img $chksum) | |
if [ "$prevsum" == "$newsum" ]; then | |
return | |
fi | |
fi | |
# try to download the image | |
curl -qLO $url/$img | |
if [ $? -ne 0 ]; then | |
echo "ERROR: $suit: download image" | |
return | |
fi | |
# is there previous image? | |
if [ -e $IMGDIR/$img ]; then | |
rm -f $IMGDIR/$img.prev | |
mv $IMGDIR/$img $IMGDIR/$img.prev | |
fi | |
mv $img $IMGDIR/$img | |
grep $img $chksum > $chksum.$suit | |
} | |
while read l; do | |
case "$l" in | |
\#*) | |
continue | |
esac | |
a=($l) | |
check_and_download ${a[0]} ${a[1]} ${a[2]} ${a[3]} | |
done < $conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment