#!/bin/sh

set -e

trap "echo ; \
      echo Received signal... exiting. ; \
      echo ; \
      echo To set your time zone at a later date, use dpkg --configure. ; \
      exit 1" 1 2 3 15

if [ -f /var/lib/dpkg/info/timezone.postrm ]; then
   rm /var/lib/dpkg/info/timezone.postrm
   echo '#! /bin/sh' >>/var/lib/dpkg/info/timezone.postrm
   echo 'set -e' >>/var/lib/dpkg/info/timezone.postrm
   chmod +x /var/lib/dpkg/info/timezone.postrm
   fi

if [ -f /etc/timezone ]; then
    timezone=`cat /etc/timezone`
    if [ "$timezone" = "Factory" ]; then 
	rm /etc/timezone
    fi
fi

if [ ! -f /etc/timezone ] ; then
	echo "You don't have a default time zone"
	echo "Running /usr/sbin/tzconfig..."
	/usr/sbin/tzconfig -auto
fi

timezone=`cat /etc/timezone`
echo "Your default time zone is $timezone."
echo "Run /usr/sbin/tzconfig to change it"
rm -f /etc/localtime
cp /usr/share/zoneinfo/$timezone /etc/localtime
rm -f /usr/share/zoneinfo/localtime
ln -s /etc/localtime /usr/share/zoneinfo/localtime

exit 0
