#!/bin/bash -i

#
# This script removes an Upstart job of the ExaGear guest from the list of host services.
#
# The script undoes changes made by add-upstart-service.
#
# Copyright (c) 2013 "Elbrus Technologies" LLC. All rights reserved.
#
# This script comes NO warranty, not even for MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.
#

if [ -e "$1" ]; then
    echo "Use"
    echo "    $0 name-of-guest-service"
    echo "to remove a guest Upstart job from the host's Upstart jobs."
    exit 1
fi

. $EXAGEAR_GUEST_CONFFILE

if [ $DELEGATE_RC_SCRIPTS_AUTOMATICALLY == "Y" ]; then
    echo "The guest image $EXAGEAR_IMAGE_NAME uses automatic integration of the startup"
    echo "and shutdown mechanisms of the host and guest systems. If you want to use"
    echo "this script to enable the autostart of individual guest services, please"
    echo "first disable the automatic integration. You can do this by editing the file"
    echo "    $EXAGEAR_GUEST_CONFFILE"
    exit 0
fi

my_dir=$(dirname $0)
etc_src=$(realpath "$my_dir/../etc/")
etc_dst="/etc/"

mgmt_script_dst="$etc_dst/init/${1}.conf"

image_dir=$(realpath "$my_dir/..")

echo "Removing the startup configuration file $mgmt_script_dst..."
rm -f $mgmt_script_dst

exit 0
