#!/bin/sh
set -e

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

printf "started" > ${CLONE_STATUS_FILE}

clean_up() {
  set +e
  printf "House keeping\\n"
  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

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

exit 0
