home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1999 March B
/
SCO_CASTOR4RRT.iso
/
nis
/
install
/
request
< prev
Wrap
Text File
|
1998-08-19
|
11KB
|
550 lines
#ident "@(#)request 1.3"
#ident "$Header: $"
SCRIPTS=/usr/sbin/pkginst
UPGRADE_STORE=/var/sadm/upgrade
PKGMSG=/${PKGINST}.pkg export PKGMSG
LOCALE=${LC_ALL:-${LC_MESSAGES:-${LANG:-"C"}}}
PATH=/bin:/usr/bin:/usr/etc:/usr/sbin:$PATH
export PATH
yproot_dir=/var/yp
hf=/tmp/ypservers #used by postinstall
clientp=F export clientp
masterp=F
slavep=F export slavep
host="" export host
NIS_DOMAIN="" export NIS_DOMAIN
host_type="" export host_type
master="" export master
ACCEPT="No" export ACCEPT
not_configured=1
SERV1="" export SERV1
SERV2="" export SERV2
SERV3="" export SERV3
CONFIG_NOW="No" export CONFIG_NOW
NISOVERLAY=/tmp/nis.overlay export NISOVERLAY
PKGADD_FILE=$1
NIS_RESP=$1 export NIS_RESP
nis_setup_exists="-d $yproot_dir/binding -a -d $yproot_dir/binding/* -o -f $yproot_dir/binding"
INITSCRIPT=/etc/init.d/nis
USE_CURRENT="Yes" export USE_CURRENT
TYPE="" export TYPE
badhosts=/tmp/.nishosts export badhosts
HOW_INSTALL=NORMAL
if [ -f /etc/rc2.d/S02POSTINST ]
then
HOW_INSTALL=POSTREBOOT
fi
if [ -f /etc/inst/scripts/postreboot.sh ]
then
HOW_INSTALL=ON_BFLOP
fi
ckhost()
{
#
# Now check to see if the host is in /etc/hosts
#
found=0
if [ -f /etc/inet/hosts ]
then
found=`cat /etc/inet/hosts | sed '/^#/d' | nawk '
BEGIN {found=0}
host == $2 {found=1; exit 0}
END {print found}' host=$1`
fi
if [ -s /etc/resolv.conf ]
then
/usr/sbin/ping $1 5 >/dev/null 2>&1
[ "$?" = "0" ] && found=1
fi
return $found
}
cleanup()
{
rm -f $MENU_RESP
rm -f $NISOVERLAY
rm -f $hf
rm -f $badhosts
}
savemv()
{
trap "" 1 2 3 15
mv -f $1 $2 > /tmp/nis.config 2>&1
if [ $? -ne 0 ]
then
error 4 "Unable to create %s\n" $2
fi
trap 1 2 3 15
}
error()
{
export error_string
export mgs_num
msg_num="$1"
error_string="`/usr/bin/pfmt -s error -g ${PKGMSG}:$1 "$2" 2>&1`" $3
. /etc/inst/locale/C/menus/menu_colors.sh error > /dev/null 2>&1
menu_colors error
menu -f ${MENU_DIR}/menu.err -o /dev/null 2>/dev/null
menu_colors regular
}
setdomain()
{
NIS_DOMAIN=`domainname` 2>/tmp/nis.config
if [ $? -ne 0 ]
then
error 3 "Can not get local host's domain name. \n"
cleanup
exit 1
fi
menu -f ${MENU_DIR}/menu.5 -o ${MENU_RESP} 2>/dev/null
cat ${MENU_RESP} >> ${NIS_RESP}
. ${MENU_RESP}
}
initnis()
{
host=`uname -n` 2>/tmp/nis.config
notdone=1
while [ $notdone = 1 ]
do
menu -f ${MENU_DIR}/menu.2 -o ${MENU_RESP} 2>/dev/null
cat ${MENU_RESP} >> ${NIS_RESP}
. ${MENU_RESP}
case "$TYPE" in
1)
masterp=T
ismaster=1
isserver=1
notdone=0
host_type="master server"
;;
2)
menu -f ${MENU_DIR}/menu.2.1 -o ${MENU_RESP}
cat ${MENU_RESP} >> ${NIS_RESP}
. ${MENU_RESP}
if [ ! -z "$master" ]
then
if [ "$host" = "$master" ]
then
. /etc/inst/locale/C/menus/menu_colors.sh warn 1>/dev/null 2>&1
menu_colors warn
menu -f ${MENU_DIR}/menu.2.1.1 -o ${MENU_RESP}
menu_colors regular
continue
fi
slavep=T
isserver=1
notdone=0
fi
host_type="slave server"
;;
3)
clientp=T
notdone=0
host_type="client"
;;
*)
continue
;;
esac
done
}
#
# Get current NIS configuration.
#
getnisconfig()
{
/sbin/rm -rf $NISOVERLAY
NIS_DOMAIN=`/usr/bin/domainname`
echo "NIS_DOMAIN=$NIS_DOMAIN" >> $NIS_RESP
if [ $nis_setup_exists ]
then
if [ -f $yproot_dir/binding/$NIS_DOMAIN/ypservers ]
then
#
# Just print out the first 3 servers onto the menu.
#
sed -n '1,3p' $yproot_dir/binding/$NIS_DOMAIN/ypservers >> $NISOVERLAY
echo "\n \n" >> $NISOVERLAY
else
#
# If /var/yp/binding/$NIS_DOMAIN/ypservers is not
# present then can not use current configuarion.
#
return 1
fi
if [ -f $INITSCRIPT ]
then
awk -F= '/^domain/ { printf("NIS_DOMAIN=%s", $2) }
/^isserver/ { printf("ISSERVER=%s", $2) }
/^ismaster/ { printf("ISMASTER=%s", $2) }
/^startypbind/ { printf("STARTYPBIND=%s", $2) }
/^startypserv/ { printf("STARTYPSERV=%s", $2) }
/^startyppass/ { printf("STARTYPPASS=%s", $2) }
' $INITSCRIPT >> $NIS_RESP
else
#
# If /etc/init.d/nis is not present then can not use
# current configuarion.
#
return 1
fi
. $NIS_RESP
if [ $ISSERVER = "1" ]
then
if [ $ISMASTER = "1" ]
then
NIS_TYPE="master"
else
NIS_TYPE="slave"
fi
else
NIS_TYPE="client"
fi
echo "NIS_TYPE=$NIS_TYPE" >> $NIS_RESP
if [ "$HOW_INSTALL" = "NORMAL" ]
then
/usr/sbin/menu -f ${MENU_DIR}/menu.ol -o ${MENU_RESP}
cat ${MENU_RESP} >> ${NIS_RESP}
. ${MENU_RESP}
fi
rm -rf $NISOVERLAY
if [ "$USE_CURRENT" = "No" ]
then
#
# Do not use current configuration.
#
return 1
else
#
# Save some volatile files.
#
mv /var/yp/YPMAPS /var/yp/YPMAPS.old 2>/dev/null
mv /var/yp/aliases /var/yp/aliases.old 2>/dev/null
mv /var/yp/Makefile /var/yp/Makefile.old 2>/dev/null
#
# Use current configuration.
#
return 0
fi
else
#
# No valid configuration found.
#
return 1
fi
}
. ${SCRIPTS}/updebug
[ "$UPDEBUG" = YES ] && set -x
#
# Check to see if we are being called from boot floppy
#
#if [ -f /etc/inst/scripts/postreboot.sh ]
#then
# mkdir /tmp/nis
# cp ${REQDIR}/request /etc/inst/scripts/nisrequest
# cp ${REQDIR}/postinstall /etc/inst/scripts/nispostinst
# chmod +x /etc/inst/scripts/nisrequest
# chmod +x /etc/inst/scripts/nispostinst
# exit 0
#fi
# We are rebooting after fnd set installation if the script
# /etc/rc2.d/S02POSTINST exists
#if [ ! -f /etc/rc2.d/S02POSTINST ]
#then
# # if we make it this far, postinstall must be called from pkagadd
# NIS_RESP=/tmp/nis.resp
#fi
#
# menu stuff
#
MENU_DIR=/etc/inst/locale/${LOCALE}/menus/nis
PKG_MENU=${REQDIR}/nis
REQ_MENU=${PKG_MENU}
MENU_RESP=/tmp/nisout
[ -d ${MENU_DIR} ] || mkdir -p ${MENU_DIR}
MENUS="menu.1 menu.2 menu.2.1 menu.2.1.1 menu.4 menu.5 menu.err menu.wk menu.ck menu.ol menu.hosts"
for i in $MENUS
do
if [ ! -f ${MENU_DIR}/$i ]
then
if [ ! -f ${PKG_MENU}/$i ]
then
cp ${PKG_MENU}/$i ${MENU_DIR}
chgrp sys ${MENU_DIR}/$i
else
cp ${REQ_MENU}/$i ${MENU_DIR}
chgrp sys ${MENU_DIR}/$i
fi
fi
done
#
# Set up to use menu_colors; default to C-locale if ${LANG}'s dir has
# no menu_colors.sh
#
if [ -f /etc/inst/locale/${LOCALE}/menus/menu_colors.sh ]
then
. /etc/inst/locale/${LOCALE}/menus/menu_colors.sh 1> /dev/null 2>&1
else
. /etc/inst/locale/C/menus/menu_colors.sh 1> /dev/null 2>&1
fi
menu_colors regular
#
# Create in message catalogs
#
if [ ! -f /usr/lib/locale/${LOCALE}/LC_MESSAGES/${PKGMSG} ]
then
if [ -f ${REQDIR}/inst/locale/${LOCALE}/${PKGMSG} -a \
-d /usr/lib/locale/${LOCALE}/LC_MESSAGES ]
then
cp ${REQDIR}/inst/locale/${LOCALE}/${PKGMSG} \
/usr/lib/locale/${LOCALE}/LC_MESSAGES
fi
fi
#
# This is the main loop of the script
#
while [ $not_configured = 1 ]
do
############# Begin UPGRADE AND OVERLAY #######################
${SCRIPTS}/chkpkgrel $PKGINST
PKGVERSION=$?
case $PKGVERSION in
2) PKGINSTALL_TYPE=OVERLAY ;;
4) PKGINSTALL_TYPE=UPGRADE ;;
6) PKGINSTALL_TYPE=UPGRADE2 ;;
*) unset PKGINSTALL_TYPE ;;
esac
#
# Check to see if NIS is installed and initialized.
# If so, get the current NIS configuration
# otherwise, initialize NIS. getnisconfig() returns 0 if a
# valid configuration was found.
#
# the NIS package did not exist before update 6 of uw1.1.
# Upgrade will then be anything from update 6 to uw2.0 or later
# Overlay will be update 6 to update 7 etc., uw2.0 to uw2.1.
# In both cases the actions to be take are the same for now.
#
if [ $PKGINSTALL_TYPE=UPGRADE ] || [ $PKGINSTALL_TYPE=OVERLAY ] || \
[ $PKGINSTALL_TYPE=UPGRADE2 ]
then
getnisconfig
if [ "$?" = "0" ]
then
if [ $USE_CURRENT = "Yes" ]
then
echo "CONFIG_NOW=Yes" >> $NIS_RESP
cp $NIS_RESP $PKGADD_FILE 2>/dev/null
exit 0
fi
fi
fi
############# End UPGRADE AND OVERLAY #######################
if [ "$HOW_INSTALL" = "NORMAL" ]
then
#
# This is the case of pkgadd on a running system.
#
#
# Find out if user wants to configure NIS now
#
menu -f ${MENU_DIR}/menu.1 -o ${MENU_RESP}
. ${MENU_RESP}
if [ $CONFIG_NOW = "No" ]
then
echo "CONFIG_NOW=No" >> $NIS_RESP
cp $NIS_RESP $PKGADD_FILE 2>/dev/null
not_configured=0
continue
fi
initnis
host=`uname -n` 2>/tmp/nis.config
if [ $? -ne 0 ]
then
error 1 "Can not determine local host's name. \n"
cleanup
exit 1
fi
if [ -z "$host" ]
then
error 2 "The local host's name has not been set. Please set it. \n"
cleanup
exit 1
fi
setdomain
binding_dir="$yproot_dir""/binding/""$NIS_DOMAIN"
binding_file="$yproot_dir""/binding/""$NIS_DOMAIN""/ypservers"
if [ ! -d "$yproot_dir" ]
then
mkdir -p $yproot_dir 2>/dev/null
fi
if [ ! -d "$binding_dir" ]
then
mkdir -p $binding_dir 2>/dev/null
fi
if [ ! -d $binding_dir ]
then
error 12 " The directory %s does not exist. Restore it from the distribution." $binding_dir
cleanup
exit 1
fi
if [ $slavep = F ]
then
rm -f $badhosts
rm -f $hf
more_servers="Yes"
first_loop="yes" export first_loop
if [ $TYPE = "1" ]
then
SERVER1=`uname -n`
export SERVER1
fi
if [ $TYPE = "3" ]
then
SERVER1=""
export SERVER1
fi
while [ $more_servers = "Yes" ]
do
menu -f ${MENU_DIR}/menu.4 -o ${MENU_RESP}
. ${MENU_RESP}
for i in SERVER1 SERVER2 SERVER3 SERVER4 SERVER5
do
eval arg=$"$i"
if [ "$arg" != "" ]
then
echo $arg >> $hf
ckhost $arg
if [ "$?" = "0" ]
then
echo $arg >> $badhosts
fi
fi
if [ $first_loop = "yes" ]
then
if [ "$i" = "SERVER1" ]
then
SERV1=$arg
fi
if [ "$i" = "SERVER2" ]
then
SERV2=$arg
fi
if [ "$i" = "SERVER3" ]
then
SERV3=$arg
fi
fi
done
first_loop="no"
SERVER1=""
done
else
#
# This is a slave host.
#
rm -f $badhosts
rm -f $hf
echo $master >> $hf
echo $host >> $hf
ckhost $master
if [ "$?" = "0" ]
then
echo $master >> $badhosts
fi
fi
#
# Check to see if hosts were entered that were not
# in /etc/hosts.
#
if [ -f $badhosts ]
then
menu_colors warn
menu -f ${MENU_DIR}/menu.hosts -o /dev/null 2>/tmp/error
menu_colors regular
fi
rm -f $badhosts
menu -f ${MENU_DIR}/menu.ck -o ${MENU_RESP}
. ${MENU_RESP}
if [ $ACCEPT != "Yes" ]
then
master=""
slavep=F
client=F
SERV1=""
SERV2=""
SERV3=""
not_configured=1
else
echo "CONFIG_NOW=Yes" >> $NIS_RESP
not_configured=0
fi
cp $NIS_RESP $PKGADD_FILE 2>/dev/null
fi
if [ "$HOW_INSTALL" = "ON_BFLOP" ]
then
#
# We're installing from ISL exit.
#
exit 0
fi
done
#
# Nothing left to do!
#
exit 0