#!/bin/sh

# Most of functions used in system-autoupdate and system-autoupdate-runner are in common-funcs.sh
# Scripts work from ./usr/sbin/ in the development directory
# Script may be called from ./ or ./usr/sbin/
for common_funcs_file in "/usr/share/system-autoupdate/common-funcs.sh" "../share/system-autoupdate/common-funcs.sh" "./usr/share/system-autoupdate/common-funcs.sh"
do
	if [ -f "$common_funcs_file" ]; then
		. "$common_funcs_file"
	fi
done

case "$1" in
	"full_run")
		check_live
		if [ "$LIVECD" = '1' ]; then
			echo "Will not continue working on Live CD"
			exit
		fi
		block_shutdown
		notify_all_if_config low info "${notify_update_begin_text_title}" "${notify_update_begin_text_body}"
		run_update
		notify_all_if_config low info "${notify_update_end_text_title}" "${notify_update_end_text_body}"
		unblock_shutdown
	;;
	"block_shutdown")
		block_shutdown
	;;
	"unblock_shutdown")
		unblock_shutdown
	;;
	"run_update")
		run_update
	;;
	"notify_all")
		## TODO: it will not work, because 'notify_all' will be $1
		notify_all "$@"
	;;
	"notify_all_shutdown_error")
		if [ "$notify_on_shutdown_error" = '1' ]; then
			notify_all critical dialog-error "${notify_shutdown_error_text_title}" "${notify_shutdown_error_text_body}"
		fi
		/usr/sbin/system-autoupdate run_hooks on-shutdown-error
	;;
	"check_shutdown")
		check_shutdown
	;;
	"enable")
		service_status enable
	;;
	"disable")
		service_status disable
	;;
	"status")
		service_status status
	;;
	"log")
		log
	;;
	"check_root")
		check_root
	;;
	*)
		echo_help
		exit 1
	;;
esac
