#!/bin/sh
# Copyright (c) 2000 Sun Microsystems, Inc.  All Rights Reserved.
#
# @(#)regpreload.sh	1.3 05/12/00
#
# AS/U registry pre-initialization script to build reg.ini file
#
TMP_FILE=/tmp/regpreload.$$
#
# verify that this is running as root
#
ID="`id | cut -d\( -f1`"
if [ "${ID}" != "uid=0" ]
then
	echo "${0} must be run as root!"
	exit 1
fi
#
# bring in the lmpaths config file
#
LMPATHS="`/bin/dirname $0`/../lib/lmpaths"

if [ -f ${LMPATHS} ]
then
    . ${LMPATHS}
else
    . lmpaths
fi

#
# remove old reg.ini file
#
rm -f ${REG_INI_PATH}
#
# copy reg.default file as starting point
#
cp ${REG_DEFAULT_PATH} ${REG_INI_PATH}
chmod 600 ${REG_INI_PATH}
#
# fixup run-time information
#
echo "NativeOS='UNIX `uname -r` `uname -v`'" >> ${REG_INI_PATH}
echo "Build=`uname -m`" >> ${REG_INI_PATH}
echo "ProcessorIdentifier=`uname -m`" >> ${REG_INI_PATH}
echo "NameUnixOs=`uname -s`" >> ${REG_INI_PATH}
echo "UnixMachineName=`uname -n`" >> ${REG_INI_PATH}
echo "SystemIdentifier=`uname -p`" >> ${REG_INI_PATH}
echo "PlatformName=`uname -p`" >> ${REG_INI_PATH}
echo "InstallDate='`date`'" >> ${REG_INI_PATH}
BUS="`uname -X 2> ${DEV_NULL_PATH} | grep BusType | tr -d ' ' | cut -d'=' -f2`"
if [ -n "${BUS}" ]
then
	echo "MultifunctionAdapterIdentifier='${BUS}'" >> ${REG_INI_PATH}
fi
#
# get the domain-specific SIDs
#
DomainAdmin=`${DOMAINSIDS_PATH} DomainAdmin`
DomainAdminBinarySid="`${DOMAINSIDS_PATH} -b DomainAdmin`"
DomainGuest=`${DOMAINSIDS_PATH} DomainGuest`
DomainGuestBinarySid="`${DOMAINSIDS_PATH} -b DomainGuest`"
echo "DomainAdmin=${DomainAdmin}" >> ${REG_INI_PATH}
echo "DomainAdminBinarySid='${DomainAdminBinarySid}'" >> ${REG_INI_PATH}
echo "DomainGuest=${DomainGuest}" >> ${REG_INI_PATH}
echo "DomainGuestBinarySid='${DomainGuestBinarySid}'" >> ${REG_INI_PATH}
#
# build the user-specific stuff
#
USERFILE=${LMREGDIR_PATH}/users.regadm
rm -f ${USERFILE}
for User in .DEFAULT ${DomainAdmin} ${DomainGuest}
do
	cat >> ${USERFILE} <<EOT
\HKEY_USERS\\${User}
:ClassName:<NO CLASS>
:Security:AdminsFullControl

\HKEY_USERS\\${User}\Console
:ClassName:<NO CLASS>

#
# changed TEMP and TMP from \TEMP to \TMP
#
\HKEY_USERS\\${User}\Environment
:ClassName:<NO CLASS>
TEMP:REG_EXPAND_SZ:%SystemDrive%\tmp
TMP:REG_EXPAND_SZ:%SystemDrive%\tmp

\HKEY_USERS\\${User}\Keyboard Layout
:ClassName:<NO CLASS>

\HKEY_USERS\\${User}\Keyboard Layout\Preload
:ClassName:<NO CLASS>
1:REG_SZ:00000409

\HKEY_USERS\\${User}\Keyboard Layout\Substitutes
:ClassName:<NO CLASS>

\HKEY_USERS\\${User}\Software
:ClassName:<NO CLASS>

\HKEY_USERS\\${User}\Software\Microsoft
:ClassName:<NO CLASS>

\HKEY_USERS\\${User}\Software\Microsoft\Windows NT
:ClassName:<NO CLASS>

\HKEY_USERS\\${User}\Software\Microsoft\Windows NT\CurrentVersion
:ClassName:<NO CLASS>

\HKEY_USERS\\${User}\UNICODE Program Groups
:ClassName:<NO CLASS>

EOT
done

#
# populate some machine-specific registry data
#

#
# determine processor type
#
PROCESSOR="`uname -p`"
case $PROCESSOR in
	alpha)
		CentralProcessorIdentifier="DEC-"
		FloatingPointProcessorIdentifier="DEC-"
		ProcessorArchitecture="alpha"
		ProcessorIdentifier="alpha Family"
		ProcessorLevel="5"
		ProcessorRevision="020c"
		;;
	R3000|R4000)
		CentralProcessorIdentifier="MIPS-"
		FloatingPointProcessorIdentifier="MIPS-"
		ProcessorArchitecture="R3000"
		ProcessorIdentifier="R3000 Family"
		ProcessorLevel="5"
		ProcessorRevision="020c"
		;;
	RS6000|rs6000)
		CentralProcessorIdentifier="PowerPC"
		FloatingPointProcessorIdentifier="PowerPC"
		ProcessorArchitecture="RS6000"
		ProcessorIdentifier="RS6000 Family"
		ProcessorLevel="5"
		ProcessorRevision="020c"
		;;
	hppa|HPPA)
		CentralProcessorIdentifier="x86 "
		FloatingPointProcessorIdentifier="x86 "
		ProcessorArchitecture="HPPA"
		ProcessorIdentifier="HPPA Family"
		ProcessorLevel="5"
		ProcessorRevision="020c"
		;;
	sparc)
		CentralProcessorIdentifier="x86 "
		FloatingPointProcessorIdentifier="x86 "
		ProcessorArchitecture="SPARC"
		ProcessorIdentifier="SPARC Family"
		ProcessorLevel="5"
		ProcessorRevision="020c"
		;;
	*386*|*486*|x86at|*)
		CentralProcessorIdentifier="x86 "
		FloatingPointProcessorIdentifier="x86 "
		ProcessorArchitecture="x86"
		ProcessorIdentifier="x86 Family"
		ProcessorLevel="5"
		ProcessorRevision="020c"
		;;
esac
echo "ProcessorArchitecture='${ProcessorArchitecture}'" >> ${REG_INI_PATH}
echo "ProcessorIdentifier='${ProcessorIdentifier}'" >> ${REG_INI_PATH}
echo "ProcessorLevel='${ProcessorLevel}'" >> ${REG_INI_PATH}
echo "ProcessorRevision='${ProcessorRevision}'" >> ${REG_INI_PATH}
#
# get the number of CPU's
#
if [ -x /usr/sbin/psrinfo ]
then
	NumCPU="`/usr/sbin/psrinfo -n 2> ${DEV_NULL_PATH}`"
	if [ $? -ne 0 ]
	then
		NumCPU="1"
	fi
fi
if [ -z "${NumCPU}" ]
then
	NumCPU=1
fi
if [ ${NumCPU} -ne 1 ]
then
	echo 'CURRENT_TYPE="Multiprocessor Free"' >> ${REG_INI_PATH}
fi
echo "NumCPU=${NumCPU}" >> ${REG_INI_PATH}
#
# fixup ownership and mode
#
chmod ${REG_INI_MODE} ${REG_INI_PATH}
chown ${REG_INI_OWNER} ${REG_INI_PATH}
chgrp ${REG_INI_GROUP} ${REG_INI_PATH}
#
# build a file with CPU and FPU configuration information
#
MACHINEFILE=${LMREGDIR_PATH}/machine.regadm
rm -f ${MACHINEFILE}
Count=0
while [ ${Count} -lt ${NumCPU} ]
do
	cat >> ${MACHINEFILE} <<EOT
\HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\\${Count}
:ClassName:Processor
Identifier:REG_SZ:${CentralProcessorIdentifier}

\HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\FloatingPointProcessor\\${Count}
:ClassName:Processor
Identifier:REG_SZ:${FloatingPointProcessorIdentifier}

EOT

	Count=`expr ${Count} + 1`
done
#
# and we're done
#
echo "${REG_INI_NAME} created successfully"
#
# end of file
