#!/bin/sh
usage() {
	cat >&2 <<EOF
Usage: $0 (install|download|none)
	Control auto-installation of updates.

	install: Updates are downloaded and installed automatically.
	download: Updates are downloaded automatically, but must be installed manually.
	none: You need to check for updates manually.
EOF
}

if [ "$(id -u)" != "0" ]; then
	echo "$0 needs to be run as root."
	exec sudo $0 "$@"
fi

case "$1" in
install)
	[ -e /etc/sysconfig/system-update ] && sed -i -e 's,^NO_INSTALL,# NO_INSTALL,' /etc/sysconfig/system-update
	systemctl enable system-update.timer
	;;
download)
	[ -e /etc/sysconfig/system-update ] && sed -i -e '/^NO_INSTALL/d' /etc/sysconfig/system-update
	echo 'NO_INSTALL=1' >>/etc/sysconfig/system-update
	systemctl enable system-update.timer
	;;
none)
	systemctl disable system-update.timer
	;;
*)
	usage
	exit 1
	;;
esac
