#!/sbin/sh
#
# Copyright 1999 Sun Microsystems, Inc. All Rights Reserved
#
#  writeLocaleFile -- Creates /a/etc/default/init file
#           $1 = locale
#           $2 = full path to Solaris locale directory locale_map file
#           (e.g., /cdrom/Solaris_2.7/Tools/Boot/usr/lib/locale/fr/locale_map)
#
LOC=$1
LOCALEMAP=$2

TEMPLATE=/.tmp_proto/root/etc/default/init.orig
LOCFILE=/a/etc/default/init

CAT=/usr/bin/cat
CP=/usr/bin/cp
RM=/usr/bin/rm
SED=/usr/bin/sed


# Copy the template, then append to it below

$RM $LOCFILE
$CP $TEMPLATE $LOCFILE

# See if there is a locale_map
# under the right directory, and use that as a base.

if [ -f "$LOCALEMAP" ]; then
  #
  # If a locale_map exists, use it
  #
  $CAT $LOCALEMAP >> $LOCFILE
else
  #
  # Create the file from scratch 
  #
  echo "LANG=$LOC" >> $LOCFILE
fi
 
# Now, substitute the timezone determined by sysid wizard
# which is (hopefully) stored in /etc/default/init

$CP $LOCFILE ${LOCFILE}.tmp
TZ=`cat $TEMPLATE | grep 'TZ=' | cut -d'=' -f2`
TZSED=`echo $TZ | $SED 's/\//\\\\\//g'`
NEWTZ=`cat /etc/default/init | grep 'TZ=' | cut -d'=' -f2`
NEWTZSED=`echo $NEWTZ | $SED 's/\//\\\\\//g'`

$SED s/${TZSED}/${NEWTZSED}/ ${LOCFILE}.tmp > $LOCFILE

$RM ${LOCFILE}.tmp



