home *** CD-ROM | disk | FTP | other *** search
- echo This shell script is no longer supported.
- exit 1
-
- #!/bin/csh -f
- #
- # Set up a NetInstall server
- # Copyright (C) 1994 by NeXT Computer, Inc. All rights reserved.
-
- # usage: server [-cdrom dir] [-image dir]
- # options:
- # -cdrom dir Name of NEXTSTEP release CDROM
- # -image dir Directory for NEXTSTEP image
-
- # A Network Install server has an NFS-exported directory that
- # contains an image of the NEXTSTEP release CD-ROM. The server
- # is also recorded in the NetInfo root domain, in the directory
- # /locations/install_servers/<servername>. A soft, read-only
- # mount is placed in the root domain.
-
- # Configuration variables. Change these if you with to use this
- # script with a custom CD-ROM or a different name for the CD-ROM
- # root image directory. You can over-ride both of these variables
- # with the -cdrom and -image command-line options.
-
- set CDROM=/OPENSTEP_4.2
- set ROOT_IMAGE=/NEXTSTEP_INSTALL
-
- # Trap SIGINT. This keeps the tty from getting messed up if
- # someone types ^C while the shell is reading a password.
-
- onintr -
-
- # All command names are stored in variables
-
- set AWK=/bin/awk
- set BASENAME=/usr/bin/basename
- set CAT=/bin/cat
- set DF=/bin/df
- set ECHO=/bin/echo
- set ERROR=$ECHO
- set EXPORTFS=/usr/etc/exportfs
- set GREP=/bin/grep
- set HOSTNAME=/bin/hostname
- set IFCONFIG=/usr/etc/ifconfig
- set LS=/bin/ls
- set MKDIRS=/bin/mkdirs
- set MOUNTD=/usr/etc/rpc.mountd
- set NFSD=/usr/etc/nfsd
- set NIUTIL=/usr/bin/niutil
- set PS=/bin/ps
- set RM=/bin/rm
- set SLEEP=/usr/bin/sleep
- set STTY=/bin/stty
- set TAIL=/usr/ucb/tail
- set WC=/usr/ucb/wc
-
- set TRUE=1
- set FALSE=0
-
- set CONFIG_DOMAIN=/
- set RELEASE_NAME=`$BASENAME $CDROM ""`
- set HOST_NAME=`$HOSTNAME`
- set PROGRAM_NAME=`$BASENAME ${0} .csh`
- $ECHO -n "usage: ${PROGRAM_NAME} " > /tmp/_usage_$$
- $ECHO '[-cdrom dir] [-image dir] [-config_domain name]' >> /tmp/_usage_$$
- $ECHO 'options:' >> /tmp/_usage_$$
- $ECHO ' -cdrom dir Name of NEXTSTEP release CDROM' >> /tmp/_usage_$$
- $ECHO ' -image dir Directory for NEXTSTEP image' >> /tmp/_usage_$$
- $ECHO ' -config_domain Where to record servers (default is "/")' >> /tmp/_usage_$$
-
- # This program must be run by root
-
- set WHO=`$PS -l $$ | $TAIL -1 | $AWK '{print $2}'`
- if (${WHO}x != "0x") then
- $ERROR 'You must run this program as "root".'
- exit 1
- endif
-
- # Parse command-line options
-
- while ($#argv > 0)
- switch (${1})
- case "-help": # Print help message
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- breaksw
- case "-cdrom": # CDROM name
- if ($#argv < 2) then
- $ERROR "${PROGRAM_NAME}: missing argument to -cdrom"
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- endif
- set CDROM="${2}"
- shift
- breaksw
- case "-image": # ROOT_IMAGE name
- if ($#argv < 2) then
- $ERROR "${PROGRAM_NAME}: missing argument to -image"
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- endif
- set ROOT_IMAGE="${2}"
- shift
- breaksw
- case "-config_domain": # Where servers are recorded
- if ($#argv < 2) then
- $ERROR "${PROGRAM_NAME}: missing argument to -config_domain."
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- endif
- set CONFIG_DOMAIN="${2}"
- shift
- breaksw
- default: # Unknown flag
- $ERROR "${PROGRAM_NAME}: unknown option ${1}"
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- breaksw
- endsw
- shift
- end
-
- $RM /tmp/_usage_$$
-
- # Get my address and netmask
- # Try en0 first, then tr0
-
- set INTERFACE=en0
- $IFCONFIG $INTERFACE > /dev/null
- if ($status != 0) then
- # No en0 interface, try tr0
- INTERFACE=tr0
- $IFCONFIG $INTERFACE > /dev/null
- if ($status != 0) then
- # No interfaces
- $ERROR "${PROGRAM_NAME}: Can't find a working network interface."
- exit 1
- endif
- endif
-
- set IPADDRESS=`$IFCONFIG $INTERFACE | $TAIL -1 | $AWK '{print $2}'`
- set NETMASK=`$IFCONFIG $INTERFACE | $TAIL -1 | $AWK '{print $4}'`
- set NM=`$ECHO $NETMASK | tr 'a-f' 'A-F' | $AWK '{printf("16i %s p %s p %s p %s pq\n",substr($1,1,2), substr($1,3,2) ,substr($1,5,2), substr($1,7,2))}' | dc`
- set NETMASK=`$ECHO $NM[1].$NM[2].$NM[3].$NM[4]`
-
- # Find out if CDROM is present
-
- while (! -d $CDROM)
- $ECHO -n 'Please insert the CDROM "'
- $ECHO -n $CDROM
- $ECHO '" in the drive.'
- $ECHO -n 'Press Enter to proceed or type "quit" to exit: '
- set USER_INPUT=$<
-
- if (${USER_INPUT}x == "quitx") then
- exit 0
- endif
-
- if (! -d $CDROM) then
- $SLEEP 10
- endif
- $ECHO ""
- end
-
- if (! -d $CDROM) then
- $ERROR -n "${PROGRAM_NAME}: NEXTSTEP release CDROM "
- $ERROR -n '"'
- $ERROR -n $CDROM
- $ERROR '" is not available.'
- exit 1
- endif
-
- set RELEASE_SIZE=`$DF $CDROM | $TAIL -1 | $AWK '{print $3}'`
-
- # Determine if release image directory exists
-
- if (! -w $ROOT_IMAGE) then
- if (! -d $ROOT_IMAGE) then
- # Directory doesn't exist: create it
- $MKDIRS $ROOT_IMAGE
- if (! -w $ROOT_IMAGE) then
- $ERROR -n "${PROGRAM_NAME}: Can't create directory "
- $ERROR -n '"'
- $ERROR -n $ROOT_IMAGE
- $ERROR '".'
- exit 1
- endif
- else
- $ERROR -n "${PROGRAM_NAME}: No write permission for directory "
- $ERROR -n '"'
- $ERROR -n $ROOT_IMAGE
- $ERROR '".'
- exit 1
- endif
- endif
-
- # Check if release image directory is a local directory
-
- set WHERE=`$DF -i $ROOT_IMAGE | $TAIL -1 | $AWK '{print $3}'`
- if (${WHERE}x == "-1x") then
- $ERROR -n "${PROGRAM_NAME}: Directory "
- $ERROR -n '"'
- $ERROR -n $ROOT_IMAGE
- $ERROR '" is not on a local disk.'
- exit 1
- endif
-
- # Check if release image directory is empty
-
- set FILES=`$LS -1a $ROOT_IMAGE | $GREP -v "lost+found" | $WC -l`
- if (${FILES}x != "2x") then
- $ERROR -n "${PROGRAM_NAME}: Directory "
- $ERROR -n '"'
- $ERROR -n $ROOT_IMAGE
- $ERROR '" is not empty.'
- exit 1
- endif
-
- # Check if release image directory has enough space
-
- set AVAIL_SIZE=`$DF $ROOT_IMAGE | $TAIL -1 | $AWK '{print $4}'`
- if ($AVAIL_SIZE < $RELEASE_SIZE) then
- $ERROR -n "${PROGRAM_NAME}: Insufficent space available in directory "
- $ERROR -n '"'
- $ERROR $ROOT_IMAGE
- $ERROR '".'
- $ERROR "${PROGRAM_NAME}: $AVAIL_SIZE Kbytes are available. $RELEASE_SIZE Kbytes are required."
- exit 1
- endif
-
- # Acquire root password for "config" NetInfo domain
-
- set NIUTIL_33=$CDROM$NIUTIL
-
- set GET_PW=$TRUE
- $ECHO -n "Please enter the root password for the NetInfo domain: "
- $ECHO -n '"'
- $ECHO -n $CONFIG_DOMAIN
- $ECHO '"'
-
- while ($GET_PW == $TRUE)
- $STTY -echo
- $ECHO -n "Password: "
- set ROOT_PASSWORD=$<
- $STTY echo
- $ECHO ""
- if (${ROOT_PASSWORD}x == "x") then
- set ROOT_PASSWORD='""'
- endif
-
- # Check password
-
- $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
- set STATUS=`$NIUTIL_33 -read $CONFIG_DOMAIN / | $GREP _test_$$`
- if (${STATUS}x == "x") then
- $ECHO -n "Password incorrect. Do you wish to retry? [yn] "
- set USER_INPUT=$<
- if (${USER_INPUT}x == "nx" || ${USER_INPUT}x == "Nx") then
- exit 1
- endif
- $SLEEP 2
- else
- $NIUTIL_33 -destroyprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
- set GET_PW=$FALSE
- endif
- end
-
- # Create /locations/install_servers entry
-
- set NIDIR=/locations/install_servers/$HOST_NAME
- set RELEASE_SIZE=`$DF $CDROM | $TAIL -1 | $AWK '{print $4}'`
-
- $NIUTIL_33 -create -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR
- $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR ip_address $IPADDRESS
- $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR netmask $NETMASK
- $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR install_root $ROOT_IMAGE
- $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR release $RELEASE_NAME
- $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR size $RELEASE_SIZE
- $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR clients
- $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR client_domains
-
- # Create /mounts entry
-
- set NIDIR=/mounts/${HOST_NAME}-temp-$$
-
- $NIUTIL_33 -create -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR
- $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR dir /Net
- $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR opts ro bg soft net
- $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR name ${HOST_NAME}:$ROOT_IMAGE
-
-
- # Copy CDROM to release image
-
- $ECHO Copying $CDROM to $ROOT_IMAGE
-
- $CDROM/usr/etc/ditto $CDROM $ROOT_IMAGE
-
- # Export the root image
-
- $EXPORTFS -i $ROOT_IMAGE >& /tmp/_test_$$
- $GREP "already exported" /tmp/_test_$$ > /dev/null
- if ($status != 0) then
- $NIUTIL_33 -create . /exports/netinstall.$$
- $NIUTIL_33 -createprop . /exports/netinstall.$$ opts ro anon=0
- $NIUTIL_33 -createprop . /exports/netinstall.$$ name $ROOT_IMAGE
- endif
-
- $RM /tmp/_test_$$
-
- $EXPORTFS -au >& /dev/null
- $EXPORTFS -a >& /dev/null
-
- # Start nfsd if it's not already running
-
- $PS -ax | $GREP '(nfsd)' | $GREP -v 'grep' > /dev/null
- if ($status != 0) then
- $NFSD 6
- endif
-
- # Start rpc.mountd if it's not already running
-
- $PS -ax | $GREP '(rpc.mountd)' | $GREP -v 'grep' > /dev/null
- if ($status != 0) then
- $MOUNTD
- endif
-
- # All done
-
- $ECHO "NetInstall server configuration complete."
- exit 0
-