#!/bin/bash
. "`dirname $0`/bootscriptfunctions.sh"
OSM_NO_ALT_ROOT="true"
source_emulator_functions _snapshot

if [ "$#" != 3 ]
then
	echo "no machine config specified" >&2
	echo "usage: `basename $0` <machine config> <info package version> <image package version>"
	exit 1
fi

machine_config="$1"
info_version="$2"
image_version="$3"

if ! check_guest_lock -n "$machine_config"
then
	panic "Machine config $1 currently in use"
fi

if [ ! -d "$OSM_SNAP_ROOT/$machine_config" ]
then
	exit 0
fi

get_snapshot_paths -p "$machine_config"
md5sums="$snap_config_root/_last_pkg_md5sums"
if [ -f "$md5sums" ] && ! md5sum --status -c "$md5sums"
then
	exit 0
fi

if [ "$info_version" -gt "$image_version" ]
then
	snapshot_create -t initial $1
fi
