#!/bin/sh
set -e

. /opt/gira/share/devicestack/ipmodule-functions

echo -n "started" > ${CLONE_STATUS_FILE}

clean_up() {
  set +e
  echo "House keeping"
  umount_all
  sleep 1
  sync_buffer
}

trap clean_up SIGHUP SIGINT SIGTERM EXIT

check_executable ${MOUNT}
check_executable ${UNMOUNT}

identify_offline
umount_all
erase_offline
mount_offline_system
mount_current_system
clone_current_system
clone_current_kernel

echo -n "stopped" > ${CLONE_STATUS_FILE}
echo "The clone script has successfully done it's job and will now exit with return code 0."
exit 0
