#!/usr/bin/env bash

TARGET=${1}
ACTION=${2}

if [ "${ACTION}" == "enable" ]; then
	chroot ${TARGET} /sbin/hwclock -w
	sed -i 's/UTC/LOCAL/g' ${TARGET}/etc/adjtime
	chroot ${TARGET} /sbin/hwclock --hctosys --verbose
fi

if [ "${ACTION}" == "disable" ]; then
	chroot ${TARGET} /sbin/hwclock -w
	sed -i 's/LOCAL/UTC/g' ${TARGET}/etc/adjtime
	chroot ${TARGET} /sbin/hwclock --systohc --verbose
fi

if [ "${ACTION}" == "status" ]; then
  timedatectl | grep "RTC in local TZ:" | grep yes
fi
