setup-images-lib.sh 16 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 31 32 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
#!/bin/sh

DIRNAME=`dirname $0`

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

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

IMAGEDIR="$OURDIR/images"
if [ ! -d "$IMAGEDIR" ]; then
    mkdir -p "$IMAGEDIR"
fi
IMAGESETUPLOCKFILE="$IMAGEDIR/image-setup-lockfile"
IMAGEUPLOADCMDFILE="$IMAGEDIR/image-upload-commands.sh"

mount_image_etc() {
    _imgfile="$1"
    modprobe nbd max_part=8 > /dev/null 2>&1
    maxdevnum=`ls -1 /dev/nbd* | sed -e 's/\/dev\/nbd//' | sort -n | tail -1`
    if [ -z "$maxdevnum" ]; then
	maxdevnum=8
    fi
    success=0
    i=0
    while [ $success -eq 0 -a $i -lt $maxdevnum ]; do
	if [ ! -e /dev/nbd$i ]; then
	    i=`expr $i + 1`
	    continue
	fi

	qemu-nbd --connect=/dev/nbd$i "$_imgfile" > /dev/null 2>&1
	if [ $? -eq 0 ]; then
	    success=1
	    DEV=/dev/nbd$i
	    DEVPREFIX=/dev/nbd
	    DEVNUM=$i
	    partprobe /dev/nbd$i
	    break
	fi
	i=`expr $i + 1`
    done
    if [ ! $success -eq 1 ]; then
	fmt=`get_image_format $_imgfile`
	if [ "$fmt" = "raw" ]; then
	    # Try loopback mount
	    maxdevnum=`ls -1 /dev/loop* | sed -e 's/\/dev\/loop//' | sort -n | tail -1`
	    if [ -z "$maxdevnum" ]; then
		maxdevnum=8
	    fi
	    success=0
	    i=0
	    while [ $success -eq 0 -a $i -lt $maxdevnum ]; do
		if [ ! -e /dev/loop$i ]; then
		    i=`expr $i + 1`
		    continue
		fi

		losetup /dev/loop$i "$_imgfile" > /dev/null 2>&1
		if [ $? -eq 0 ]; then
		    success=1
		    partprobe /dev/loop$i
		    DEV=/dev/loop$i
		    DEVPREFIX=/dev/loop
		    DEVNUM=$i
		    break
		fi
		i=`expr $i + 1`
	    done
	fi

	if [ ! $success -eq 1 ]; then
	    /bin/false
	    return
	fi
    fi

    mntdir=`mktemp -d $IMAGEDIR/mnt.XXXX`

    # Mount the partition containing /etc/passwd
    success=0
    for part in `fdisk -l $DEV | grep ^\/dev | cut -f 1 -d ' '` ; do
	# First, check to see if there's a device mapper entry for this
	# device -- i.e., if it's got LVM stuff.
	pvscan --cache --activate ay $part > /dev/null 2>&1
	sdev=`echo $DEV | sed -n -e 's/^.*\/\([^\/]*\)$/\1/p'`
	spart=`echo $part | sed -n -e 's/^.*\/\([^\/]*\)$/\1/p'`
	dmnamefile=`ls -1 /sys/block/$sdev/$spart/holders/dm-*/dm/name`
	if [ -n "$dmnamefile" -a -f "$dmnamefile" ]; then
	    dmname=`cat $dmnamefile`
	    mount /dev/mapper/$dmname $mntdir > /dev/null 2>&1
	    if [ $? -eq 0 -a -f $mntdir/etc/passwd ]; then
		echo "$mntdir"
		return
	    fi
	    umount $mntdir
	else
	    mount $part $mntdir > /dev/null 2>&1
	    if [ $? -eq 0 -a -f $mntdir/etc/passwd ]; then
		echo "$mntdir"
		return
	    fi
	    umount $mntdir
	fi
    done

    # Cleanup on error
    rmdir $mntdir > /dev/null 2>&1
    grep -q nbd "$DEV"
    if [ $? -eq 0 ]; then
	qemu-nbd --disconnect $DEV > /dev/null 2>&1
    else
	losetup -d $DEV > /dev/null 2>&1
    fi
    echo ""
    /bin/false
}

umount_image() {
    mntdir="$1"
    # Try hard to get only the device name without the partition;
    # qemu-nbd can detach with partition device, but losetup needs only
    # the device, not a partition.
    dev=`mount | grep "$mntdir " | sed -n -e 's/^\([\/0-9A-Za-z_-]*\/[a-zA-Z_-]*[0-9]*\).* on .*$/\1/p'`
    if [ -z "$dev" ]; then
	# Fall back to the partition device.
	dev=`mount | grep "$mntdir " | sed -e 's/^\([^ ]*\) on .*$/\1/'`
    fi
    if [ -z "$dev" ]; then
	echo "*** ERROR: could not find device corresponding to $mntdir; umounting without detaching anyway!"
	umount "$mntdir"
	rmdir "$mntdir"
	/bin/false
	return
    fi
    
    umount "$mntdir"
    rmdir "$mntdir"
    grep -q nbd "$dev"
    if [ $? -eq 0 ]; then
	qemu-nbd --disconnect $dev > /dev/null 2>&1
    else
	losetup -d $dev > /dev/null 2>&1
    fi
}

fixup_mounted_image() {
    MNT="$1"
    _imgfile="$2"

    echo "*** $_imgfile: setting up sshd ..."
    grep -q '[# ]*PermitRootLogin .*' $MNT/etc/ssh/sshd_config
    if [ $? -eq 0 ]; then
158
	sed -i -e 's/^[# ]*PermitRootLogin .*$/PermitRootLogin without-password/' \
159 160
	    $MNT/etc/ssh/sshd_config
    else
161
	echo "PermitRootLogin without-password" >> $MNT/etc/ssh/sshd_config
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
    fi
    grep -q '[# ]*PasswordAuthentication .*' $MNT/etc/ssh/sshd_config
    if [ $? -eq 0 ]; then
	sed -i -e 's/^[# ]*PasswordAuthentication .*$/PasswordAuthentication yes/' \
	    $MNT/etc/ssh/sshd_config
    else
	echo "PasswordAuthentication yes" >> $MNT/etc/ssh/sshd_config
    fi

    echo "*** $_imgfile: modifying root password..."

    #cp -p $MNT/etc/shadow $IMAGEDIR/
    #cp -p $MNT/etc/passwd $IMAGEDIR/
    #cp -p $MNT/etc/group $IMAGEDIR/

    echo "*** $_imgfile: fixing root password ..."
    #sed -i -e "s@root:[^:]*:@root:${ADMIN_PASS_HASH}:@" $MNT/etc/shadow
    sed -i -e "s@root:[^:]*:@root:!:@" $MNT/etc/shadow

    grep -q Ubuntu $MNT/etc/lsb-release
    if [ $? -eq 0 ]; then
	sshvers=`dpkg-query --admindir $MNT/var/lib/dpkg -W --showformat='${Version}' openssh-server | sed -n -r -e 's/^([0-9]:)*([^:])([^:]*)$/\2/p'`
	if [ -z "$sshvers" ]; then
	    sshvers=0
	fi
	if [ $sshvers -ge 7 ]; then
	    echo "*** Adding support for dss keys for SSH version >= $sshvers"
	    echo "PubkeyAcceptedKeyTypes +ssh-dss" >> $MNT/etc/ssh/sshd_config
	fi
	echo "*** $_imgfile: fixing ubuntu password ..."
	grep ^ubuntu $MNT/etc/passwd
	if [ $? -eq 0 ]; then
	    sed -i -e "s@ubuntu:[^:]*:@ubuntu:${ADMIN_PASS_HASH}:@" \
		$MNT/etc/shadow
	else
	    # Have to add the user so that the passwd is actually set...
	    echo "ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash" \
		 >> $MNT/etc/passwd
	    echo "ubuntu:!:16731:0:99999:7:::" >> $MNT/etc/shadow
	    echo "ubuntu:x:1000:" >> $MNT/etc/group
	    echo "ubuntu:!::" >> $MNT/etc/gshadow

	    mkdir -p $MNT/home/ubuntu
	    chown 1000:1000 $MNT/home/ubuntu

	    sed -i -e "s@ubuntu:[^:]*:@ubuntu:${ADMIN_PASS_HASH}:@" \
		$MNT/etc/shadow
	fi

	echo "*** $_imgfile: modifying to support multiple NICs..."

	mkdir -p $MNT/etc/udev/rules.d
	cat <<EOF > $MNT/etc/udev/rules.d/99-auto-network.rules
ACTION=="add", SUBSYSTEM=="net", NAME!="", NAME=="eth*|en*|sl*|ww*|wl*", RUN+="/usr/local/bin/auto-udev-network-interfaces-handler add \$name \$attr{address}"
ACTION=="add", SUBSYSTEM=="net", NAME=="", KERNEL=="eth*|en*|sl*|ww*|wl*", RUN+="/usr/local/bin/auto-udev-network-interfaces-handler add \$kernel \$attr{address}"
EOF
	mkdir -p $MNT/usr/local/bin
	cat <<'EOF' >$MNT/usr/local/bin/auto-udev-network-interfaces-handler
#!/bin/sh

PREFIX='auto-udev'
RUNDIR='/run/auto-udev-interfaces.d'

command="$1"
iface="$2"
addr="$3"
stripaddr=`echo $addr | sed -e 's/://g'`

if [ ! -d $RUNDIR ]; then
    mkdir -p $RUNDIR
fi

if [ "$command" = "add" ]; then
    echo "# Added by autocloud" >$RUNDIR/$PREFIX-$iface
    echo "auto $iface" >$RUNDIR/$PREFIX-$iface
    echo "iface $iface inet dhcp" >>$RUNDIR/$PREFIX-$iface
    #ifconfig "$iface" up
elif [ "$command" = "remove" ]; then
    if [ -f $RUNDIR/$PREFIX-$iface-$stripaddr ]; then
        rm -f $RUNDIR/$PREFIX-$iface
    fi
elif [ "$command" = "reset" ]; then
    rm -f $RUNDIR/$PREFIX-*
else
    exit 1
fi

exit 0
EOF
	chmod 755 $MNT/usr/local/bin/auto-udev-network-interfaces-handler

	mkdir -p $MNT/etc/dhcp/dhclient-enter-hooks.d
	cat << 'EOF' > $MNT/etc/dhcp/dhclient-enter-hooks.d/no-default-route
#!/bin/sh

PREFIX='auto-udev'
RUNDIR='/run/auto-udev-interfaces.d'

grep -i autocloud $RUNDIR/$PREFIX-$interface
if [ $? -eq 0 ]; then
    case "$reason" in
        BOUND|RENEW|REBIND|REBOOT|TIMEOUT)
            unset new_routers
            unset new_classless_static_routes
            unset new_host_name
            unset new_domain_name
            unset new_domain_name_servers
            ;;
    esac
fi
EOF
	chmod 755 $MNT/etc/dhcp/dhclient-enter-hooks.d/no-default-route

	cat <<EOF >> $MNT/etc/network/interfaces
source-directory /run/auto-udev-interfaces.d
EOF

	#
	# Ok, there is some delay with local-filesystems not finishing
	# mounting until after the cloud-utils have blocked up the
	# system :(.  So, remove this dependency.  You can see why the
	# Ubuntu people have it in general, but it will never bother us
	# in this VM image!
	#
	if [ -f $MNT/etc/init/networking.conf ]; then
	    #sed -i -e 's/^start on (local-filesystems$/start on (mounted MOUNTPOINT=\/ and mounted MOUNTPOINT=\/sys and mounted MOUNTPOINT=\/proc and mounted MOUNTPOINT=\/run/' $MNT/etc/init/networking.conf
	    sed -i -e 's/^start on (local-filesystems$/start on (mounted MOUNTPOINT=\//' $MNT/etc/init/networking.conf
	fi

    fi

    if [ -f $MNT/etc/centos-release ]; then
	echo "*** $_imgfile: fixing centos password ..."
	grep ^centos $MNT/etc/passwd
	if [ $? -eq 0 ]; then
	    sed -i -e "s@centos:[^:]*:@centos:${ADMIN_PASS_HASH}:@" \
		$MNT/etc/shadow
	else
	    # Have to add the user so that the passwd is actually set...
	    echo "centos:x:1000:1000:Centos:/home/centos:/bin/bash" \
		 >> $MNT/etc/passwd
	    echo "centos:!:16731:0:99999:7:::" >> $MNT/etc/shadow
	    echo "centos:x:1000:" >> $MNT/etc/group
	    echo "centos:!::" >> $MNT/etc/gshadow

	    mkdir -p $MNT/home/centos
	    chown 1000:1000 $MNT/home/centos

	    sed -i -e "s@centos:[^:]*:@centos:${ADMIN_PASS_HASH}:@" \
		$MNT/etc/shadow
	fi

    fi

    if [ -f $MNT/etc/redhat-release ]; then
	echo "*** $_imgfile: fixing fedora password ..."
	grep ^fedora $MNT/etc/passwd
	if [ $? -eq 0 ]; then
	    sed -i -e "s@fedora:[^:]*:@fedora:${ADMIN_PASS_HASH}:@" \
		$MNT/etc/shadow
	else
	    # Have to add the user so that the passwd is actually set...
	    echo "fedora:x:1000:1000:Fedora:/home/fedora:/bin/bash" \
		 >> $MNT/etc/passwd
	    echo "fedora:!:16731:0:99999:7:::" >> $MNT/etc/shadow
	    echo "fedora:x:1000:" >> $MNT/etc/group
	    echo "fedora:!::" >> $MNT/etc/gshadow

	    mkdir -p $MNT/home/fedora
	    chown 1000:1000 $MNT/home/fedora

	    sed -i -e "s@fedora:[^:]*:@fedora:${ADMIN_PASS_HASH}:@" \
		$MNT/etc/shadow
	fi
    fi

    if [ -f $MNT/etc/centos-release -o -f $MNT/etc/redhat-release ]; then
	# Add a special fake network device that basically calls
	# dhclient on any non-eth0 and non-lo device.
	cat << 'EOF' > $MNT/etc/sysconfig/network-scripts/ifcfg-eth99
#
# HACK: run dhclient on all interfaces (except eth0 and lo; we assume
# any cloud image will configure those two devices).
#
# Note that this file's name (eth99) cannot overlap with an actual
# existing interface or dhclient will loop.  dhclient-script invokes
# the source-config function which sources the ifcfg-ethN file.  Thus
# if this script were called "ifcfg-eth0" and eth0 was the DHCPable
# interface, we would wind up recursively invoking dhclient.
#
# This is actually invoked from /etc/sysconfig/network-scripts/ifup-autocloud
# not directly from here, since /etc/init.d/network stop sources this file
# without telling it why it was sourced.  So, we define a custom ifup script
# instead, triggered by the DEVICETYPE variable being set to autocloud, 
# and by creating /etc/sysconfig/network-scripts/ifup-autocloud.
#

DEVICE="eth99"
TYPE="ethernet"
DEVICETYPE="autocloud"
ONBOOT="yes"
EOF

	cat << 'EOF' > $MNT/etc/sysconfig/network-scripts/ifup-autocloud
#/bin/sh -
#
# HACK: run dhclient on all interfaces except eth0 and lo.
#
# (also see comments in /etc/sysconfig/network-scripts/ifcfg-eth99 to
# understand how this gets invoked)
#

DEVICE="eth99"

interfaces=`ip -o link show | grep 'link/ether' | sed -e 's/^[^:]*:[ ]*\([^:]*\):.*$/\1/'`

#
# Run dhclient on each.
#
for iface in $interfaces ; do
    [ "$iface" = "eth0" -o "$iface" = "lo" -o "$iface" = "lo0" ] && continue

    if [ ! -f /etc/sysconfig/network-scripts/ifcfg-$iface ]; then
        cat << IOF > /etc/sysconfig/network-scripts/ifcfg-$iface
# Added by autocloud
DEVICE="$iface"
BOOTPROTO="dhcp"
# Not on boot because this script manually runs ifup
ONBOOT="no"
TYPE="ethernet"
PERSISTENT_DHCLIENT="yes"
IOF
    fi
    ifup $iface
done

exit 0
EOF
	chmod 755 $MNT/etc/sysconfig/network-scripts/ifup-autocloud

	mkdir -p $MNT/etc/dhcp/dhclient-enter-hooks.d
	cat << 'EOF' > $MNT/etc/dhcp/dhclient-enter-hooks.d/no-default-route
#!/bin/sh

grep -i autocloud /etc/sysconfig/network-scripts/ifcfg-$interface
if [ $? -eq 0 ]; then
    case "$reason" in
        BOUND|RENEW|REBIND|REBOOT|TIMEOUT)
            unset new_routers
            unset new_classless_static_routes
            unset new_host_name
            unset new_domain_name
            unset new_domain_name_servers
            ;;
    esac
fi
EOF
	chmod 755 $MNT/etc/dhcp/dhclient-enter-hooks.d/no-default-route
	#
	# Ok, copy our hooks into every possible place dhclient might
	# look, but don't overwrite any native dhclient-enter-hooks
	# files.  (We have observed that sometimes dhclient does not
	# call the hooks in the .d directories -- weird).
	#
	mkdir -p $MNT/etc/dhcp3/dhclient-enter-hooks.d
	cp $MNT/etc/dhcp/dhclient-enter-hooks.d/no-default-route \
	    $MNT/etc/dhcp3/dhclient-enter-hooks.d/no-default-route
	if [ ! -f $MNT/etc/dhcp/dhclient-enter-hooks ]; then
	    cp $MNT/etc/dhcp/dhclient-enter-hooks.d/no-default-route \
		$MNT/etc/dhcp/dhclient-enter-hooks
	fi
	if [ ! -f $MNT/etc/dhcp3/dhclient-enter-hooks ]; then
	    cp $MNT/etc/dhcp/dhclient-enter-hooks.d/no-default-route \
		$MNT/etc/dhcp3/dhclient-enter-hooks
	fi
	sshvers=`rpm --root $MNT --queryformat '%{VERSION}' -q openssh | sed -n -r -e 's/^([^.]*)(.*)$/\1/p'`
	if [ -z "$sshvers" ]; then
	    sshvers=0
	fi
	if [ $sshvers -ge 7 ]; then
	    echo "*** Adding support for dss keys for SSH version >= $sshvers"
	    echo "PubkeyAcceptedKeyTypes +ssh-dss" >> $MNT/etc/ssh/sshd_config
	fi
    fi

    if [ -f $MNT/etc/cloud/cloud.cfg ]; then
	# permit root login!!
	sed -i -e 's/^disable_root: true$/disable_root: false/' \
	    $MNT/etc/cloud/cloud.cfg

	# don't overwrite the Ubuntu passwd we just hacked in
	sed -i -e 's/^\(.*lock_passwd:\)\(.*\)$/\1 false/' \
	    $MNT/etc/cloud/cloud.cfg
    fi

    /bin/true
}

fixup_image() {
    _imgfile="$1"
    MNT=`mount_image_etc "$_imgfile"`
    if [ -z "$MNT" ]; then
	echo "ERROR: could not mount $_imgfile !"
	/bin/false
	return
    fi

    fixup_mounted_image "$MNT" "$_imgfile"

    umount_image "$MNT"
}

#
# We only support xz/lzma/gz .
#
extract_image() {
    _imgfile="$1"
    _force="$2"
    if [ -n "$_force" -a "$_force" = "1" ]; then
	forcearg="-f"
    else
	forcearg=""
    fi

    echo "$_imgfile" | grep -iq '\(\.xz\)\|\(\.lzma\)'
    if [ $? -eq 0 ]; then
	xz --decompress -k $forcearg "$_imgfile"
	newfile=`echo "$_imgfile" | sed -e 's/\(\.xz\|\.lzma\)//i'`
	echo "$newfile"
	return
    fi
    echo "$_imgfile" | grep -iq '\(\.gz\)'
    if [ $? -eq 0 ]; then
	gzip -d -k $forcearg "$_imgfile"
	newfile=`echo "$_imgfile" | sed -e 's/\(\.gz\)//i'`
	echo "$newfile"
	return
    fi

    echo "$_imgfile"
    return
}

#
# We only support qcow,vmware,vhd,raw.
#
get_image_format() {
    _imgfile="$1"

    output=`file $_imgfile`
    echo "$output" | grep -iq qcow
    if [ $? -eq 0 ]; then
	echo "qcow2"
	return
    fi
    echo "$output" | grep -iq vmware
    if [ $? -eq 0 ]; then
	echo "vmdk"
	return
    fi
    echo "$output" | grep -iq vhd
    if [ $? -eq 0 ]; then
	echo "vhd"
	return
    fi
    echo "$output" | grep -iq 'MBR boot sector'
    if [ $? -eq 0 ]; then
	echo "raw"
	return
    fi

    echo "raw"
}

sched_image() {
    _imgfile="$1"
    _imgname="$2"

    if [ -z "$_imgname" ]; then
	_imgname="$_imgfile"
    fi
    
    touch $IMAGEUPLOADCMDFILE
    chmod 755 $IMAGEUPLOADCMDFILE

    GLANCEOPTS=""
    if [ "$OSCODENAME" = "juno" -o "$OSCODENAME" = "kilo" ]; then
	GLANCEOPTS="--is-public True"
    fi

    format=`get_image_format $_imgfile`

    echo "glance image-create --name '${_imgname}' ${GLANCEOPTS} --disk-format $format --container-format bare --progress --file '$_imgfile'" >> $IMAGEUPLOADCMDFILE
}

upload_image() {
    _imgfile="$1"
    _imgname="$2"

    if [ -z "$_imgname" ]; then
	_imgname="$_imgfile"
    fi
    
    GLANCEOPTS=""
    if [ "$OSCODENAME" = "juno" -o "$OSCODENAME" = "kilo" ]; then
	GLANCEOPTS="--is-public True"
    fi

    format=`get_image_format $_imgfile`

    glance image-create --name "${_imgname}" ${GLANCEOPTS} --disk-format $format --container-format bare --progress --file "$_imgfile"
}

#
# Drag in the arch-specific customizations, if any.
#
ARCH=`uname -m`
if [ "$ARCH" = "aarch64" ] ; then
    if [ -f $DIRNAME/setup-images-lib-aarch64.sh ]; then
	. $DIRNAME/setup-images-lib-aarch64.sh
    fi
else
    if [ -f $DIRNAME/setup-images-lib-x86_64.sh ]; then
	. $DIRNAME/setup-images-lib-x86_64.sh
    fi
fi