#!/bin/bash

# Call yast to do the system config
yast timezone

# Get the correct timezone string
TIMEZONERAW="$(cut -d':' -f2 <<<`timedatectl | grep 'Time zone'` | tr -d '[:space:]')"
#echo "Time Zone Raw: $TIMEZONERAW"
TIMEZONE="$(cut -d'(' -f1 <<<$TIMEZONERAW)"

# And make changes to php and /etc/sysconfig/clock
sed -i "/date.timezone = /c\date.timezone = '$TIMEZONE'" /etc/php7/cli/php.ini
sed -i "/date.timezone = /c\date.timezone = '$TIMEZONE'" /etc/php7/apache2/php.ini
echo "DEFAULT_TIMEZONE=\"$TIMEZONE\"" > /etc/sysconfig/clock
echo ""
echo " Time Zone set to: $TIMEZONE"
echo " A reboot might be required for changes to take effect."
echo ""
