#!/bin/bash

# this shell is used for cli command "set system timezone "  and
# the timezone set when booting xorp
# input $1: the timezone ,for example Asia/Chongqing
# no output var.
# if the /tmp/run/rtrmgr_ready is exist,then the shell is used for cli command.otherwise 
# it is used for setting timezone when booting xorp

. /etc/functions

STARTUP_CONFIG=${CONFIG_DIR}pica_startup.boot
if [ ! -f /tmp/run/rtrmgr_ready ] ; then
    if [ -f ${STARTUP_CONFIG} ] ; then
        echo ${STARTUP_CONFIG}
        STARTUP_TIMEZONE=`grep timezone ${STARTUP_CONFIG} | awk -F: '{print $2}' | awk -F\" '{print $2}'`
        if [ ! X${STARTUP_TIMEZONE} = X ]; then
            echo $STARTUP_TIMEZONE
            ln -sf /usr/share/zoneinfo/${STARTUP_TIMEZONE} /etc/localtime
        fi
    else
        if [ ! X${1} = X ] ; then
            ln -sf /usr/share/zoneinfo/$1 /etc/localtime
        fi
    fi
else
    if [ ! X${1} = X ] ; then
        ln -sf /usr/share/zoneinfo/$1 /etc/localtime
    fi
fi

#restart rsyslog service, apply the new timezone in syslog messages
/etc/init.d/rsyslog restart > /dev/null

exit 0
