setup-images.sh 2.31 KB
Newer Older
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
#!/bin/sh

##
## Download and configure some images, and write out glance commands to
## get them uploaded into glance.  This script only runs the upload
## commands if we're not being run from controller setup; otherwise, the
## controller setup process runs this when it is safe (if in controller
## setup, we don't upload them into glance immediately because glance
## might not be running or any number of components may be restarting or
## otherwise in flux; setup-basic.sh uploads them when it is safe, near
## the end of our setup).
##

set -x

DIRNAME=`dirname $0`

# Gotta know the rules!
if [ $EUID -ne 0 ] ; then
    echo "This script must be run as root" 1>&2
    exit 1
fi

# Grab our libs
. "$DIRNAME/setup-lib.sh"

if [ "$HOSTNAME" != "$CONTROLLER" ]; then
    exit 0;
fi

31 32
logtstart "images"

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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
if [ -f $SETTINGS ]; then
    . $SETTINGS
fi

#
# Take our lockfile.
#
lockfile-create $IMAGESETUPLOCKFILE

#
# Create and truncate our upload commands.
#
truncate -s 0 $IMAGEUPLOADCMDFILE
chmod 755 $IMAGEUPLOADCMDFILE

cwd=`pwd`
cd $IMAGEDIR

#
# Setup the per-arch default images (and let them override our default
# *_image functions if they wish).
#
. $DIRNAME/setup-images-lib.sh
if [ "$ARCH" = "aarch64" ] ; then
    . $DIRNAME/setup-images-aarch64.sh
else
    . $DIRNAME/setup-images-x86_64.sh
fi

if [ -n "$EXTRAIMAGEURLS" ]; then
    for imgurl in $EXTRAIMAGEURLS ; do
	imgname=""
	echo "$imgurl" | grep -q '|'
	if [ $? -eq 0 ]; then
	    imgurl=`echo "$imgurl" | cut -f 1 -d '|'`
	    imgname=`echo "$imgurl" | cut -f 2 -d '|'`
	fi

	imgfile=`get_url "$imgurl"`
	if [ ! $? -eq 0 ]; then
	    echo "ERROR: could not download $imgurl !"
	else
	    if [ -z "$imgname" ]; then
		imgname=`echo $imgfile | sed -e 's/\([^\.]*\)\..*$/\1/'`
	    fi
	    imgfile=`extract_image "$imgfile"`
	    if [ -n "$imgfile" ]; then
		(fixup_image "$imgfile" \
		    && sched_image "$IMAGEDIR/$imgfile" "$imgname") \
		 || echo "ERROR: could not download user VM image $imgurl !"
	    else
		echo "ERROR: could not extract user VM image $imgurl !"
	    fi
	fi
    done
fi

#
# If we're not in controller setup, or if the controller has already
# run, do the uploads now.
#
94 95 96 97
#if [ -f $OURDIR/controller-done ]; then
#    . $OURDIR/admin-openrc.sh
#    . $IMAGEUPLOADCMDFILE
#fi
98 99 100 101 102 103

#
# Release our lockfile.
#
lockfile-remove $IMAGESETUPLOCKFILE

104 105
logtend "images"

106
exit 0