#!/bin/bash

. /usr/share/dosis2/bin/shell-support-functions

if [[ "$1" = "-h" ]]; then
    echo "Use like:"
    echo "    ./changetz.bash <timezone>"
    echo 
    echo "<timezone>:"
    echo "    America/Los_Angeles" 
    echo "    America/Denver"
    echo "    America/Phoenix"
    echo "    America/Chicago"
    echo "    America/New_York"
    echo "    Pacific/Honolulu"
    echo "    America/Juneau"
    echo "    Europe/London"
    echo "    Europe/Paris"
    exit 0
fi

if [ -z "$1" ]; then
    echo "No Timezone supplied on command line. Will do nothing."
else     
    ln -sfT "/usr/share/zoneinfo/$1" "/etc/localtime"
    /sbin/hwclock --systohc --utc

    echo "timezone = '$1'" > "/opt/dosis2/etc/postgresql/10/conf.d/90-timezone.conf"
    echo "$1" > /etc/timezone
    
    su - postgres -c "psql -d dosis2 -c 'SELECT pg_reload_conf()'"
fi
