home *** CD-ROM | disk | FTP | other *** search
- echo This shell script is no longer supported.
- exit 1
-
- #!/bin/csh -f
- #
- # Set up a NetInstall client
- # Copyright (C) 1994 by NeXT Computer, Inc. All rights reserved.
-
- # Configuration variables.
-
- set CONFIG_DOMAIN=/
- set PARENT_DOMAIN=-UNKNOWN-
- set CLIENT_NAME=-UNKNOWN-
- set SERVER_NAME=-UNKNOWN-
-
- # 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 variable
-
- set AWK=/bin/awk
- set BASENAME=/usr/bin/basename
- set CAT=/bin/cat
- set ECHO=/bin/echo
- set ERROR=$ECHO
- set GREP=/bin/grep
- set HEAD=/usr/ucb/head
- set LS=/bin/ls
- set NIUTIL=/usr/bin/niutil
- set RM=/bin/rm
- set SLEEP=/usr/bin/sleep
- set STTY=/bin/stty
- set WC=/usr/ucb/wc
- set ARCH_CMD=/usr/bin/arch
-
- set TRUE=1
- set FALSE=0
-
- # Determine host architecture
-
- #set ARCH=-UNKNOWN-
- set ARCH=`$ARCH_CMD`
-
- #$CAT /usr/lib/NextStep/software_version | $GREP Lightning > /dev/null
- #if ($status == 0) then
- if ($ARCH == m68k) then
- set ARCH=NeXT
- else
- #$CAT /usr/lib/NextStep/software_version | $GREP Thunder > /dev/null
- #if ($status == 0) then
- if ($ARCH == i386) then
- set ARCH=i386
- else
- #$CAT /usr/lib/NextStep/software_version | $GREP Blaze > /dev/null
- #if ($status == 0) then
- if ($ARCH == hppa) then
- set ARCH=hp
- endif
- endif
- endif
-
- if ($ARCH != NeXT && $ARCH != i386) then
- $ERROR 'You must run this program on a NeXT or Intel-based computer.'
- exit 1
- endif
-
- set PROGRAM_NAME=`$BASENAME ${0} .csh`
- $ECHO -n "usage: ${PROGRAM_NAME} " > /tmp/_usage_$$
- $ECHO '-client hostname -server hostname -domain name [-delete] [-config_domain name]' >> /tmp/_usage_$$
- $ECHO 'arguments:' >> /tmp/_usage_$$
- $ECHO ' -client hostname NetInstall client' >> /tmp/_usage_$$
- $ECHO ' -server hostname Server for NetInstall client' >> /tmp/_usage_$$
- $ECHO -n ' -domain name Client' >> /tmp/_usage_$$
- $ECHO -n "'" >> /tmp/_usage_$$
- $ECHO 's parent NetInfo domain' >> /tmp/_usage_$$
- $ECHO ' -delete Delete client configuration' >> /tmp/_usage_$$
- $ECHO ' -config_domain Domain where servers are recorded (default is "/")' >> /tmp/_usage_$$
-
- set DESTROY=$FALSE
-
- # Parse command-line options
-
- while ($#argv > 0)
- switch (${1})
- case "-help": # Print help message
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- breaksw
- case "-client": # Client name
- if ($#argv < 2) then
- $ERROR "${PROGRAM_NAME}: missing argument to -client."
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- endif
- set CLIENT_NAME="${2}"
- shift
- breaksw
- case "-server": # Server name
- if ($#argv < 2) then
- $ERROR "${PROGRAM_NAME}: missing argument to -server."
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- endif
- set SERVER_NAME="${2}"
- shift
- breaksw
- case "-domain": # Client's parent domain name
- if ($#argv < 2) then
- $ERROR "${PROGRAM_NAME}: missing argument to -domain."
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- endif
- set PARENT_DOMAIN="${2}"
- shift
- breaksw
- case "-delete": # Delete client
- set DESTROY=$TRUE
- 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
-
- if (${CLIENT_NAME}x == "-UNKNOWN-x") then
- $ERROR "${PROGRAM_NAME}: client name not specified."
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- endif
-
- if (${SERVER_NAME}x == "-UNKNOWN-x") then
- $ERROR "${PROGRAM_NAME}: server name not specified."
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- endif
-
- if (${PARENT_DOMAIN}x == "-UNKNOWN-x") then
- $ERROR "${PROGRAM_NAME}: domain name not specified."
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- endif
-
- $RM /tmp/_usage_$$
-
- # Check NetInstall server
-
- set SERVER_IMAGE=`$NIUTIL -read $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME | $GREP install_root | $AWK '{print $2}'`
- set IMAGE_DIR=/Net/${SERVER_NAME}$SERVER_IMAGE
-
- $LS $IMAGE_DIR | $GREP "not found"
- if ($status == 0) then
- $ERROR 'Can't find NetInstall server $SERVER_NAME directory $IMAGE_DIR.'
- exit 1
- endif
-
- set NIUTIL=${IMAGE_DIR}$NIUTIL
-
- # check client configuration
-
- set TEST_CLIENT=`$NIUTIL -read $PARENT_DOMAIN /machines/$CLIENT_NAME | $WC -l`
- if (${TEST_CLIENT}x == "0x") then
- $ERROR -n "${PROGRAM_NAME}: can't find: "
- $ERROR -n $PARENT_DOMAIN
- $ERROR -n ":/machines/$CLIENT_NAME"
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- endif
-
- # Acquire root password for parent NetInfo domain
-
- set GET_PW=$TRUE
- $ECHO -n "Please enter the root password for the NetInfo domain: "
- $ECHO -n '"'
- $ECHO -n $PARENT_DOMAIN
- $ECHO '"'
-
- while ($GET_PW == $TRUE)
- $STTY -echo
- $ECHO -n "Password: "
- set PARENT_PASSWORD=$<
- $STTY echo
- $ECHO ""
- if (${PARENT_PASSWORD}x == "x") then
- set PARENT_PASSWORD='""'
- endif
-
- # Check password
-
- $NIUTIL -createprop -P $PARENT_PASSWORD $PARENT_DOMAIN / _test_$$
- set STATUS=`$NIUTIL -read $PARENT_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 -destroyprop -P $PARENT_PASSWORD $PARENT_DOMAIN / _test_$$
- set GET_PW=$FALSE
- endif
- end
-
- # Acquire root password for "config" NetInfo domain
-
- 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 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
- set STATUS=`$NIUTIL -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 -destroyprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
- set GET_PW=$FALSE
- endif
- end
-
- # Get the server's root image directory name
-
- set ROOT_IMAGE=`$NIUTIL -read $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME | $GREP '^install_root: ' | $AWK '{print $2}'`
- if (${ROOT_IMAGE}x == "x") then
- $ERROR "${PROGRAM_NAME}: can't find server configuration."
- $CAT /tmp/_usage_$$
- $RM /tmp/_usage_$$
- exit 1
- endif
-
- if ($DESTROY == $TRUE) then
- # Delete client from server's list of clients
- $NIUTIL -destroyval -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME clients $CLIENT_NAME
- $NIUTIL -destroyval -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME client_domains $PARENT_DOMAIN
-
- # Destroy bootparams
-
- $NIUTIL -destroyprop -P $PARENT_PASSWORD $PARENT_DOMAIN /machines/$CLIENT_NAME bootparams
-
- # All done
-
- $ECHO "NetInstall client configuration deleted."
- exit 0
-
- endif
-
- # Add new client to server's list of clients
- $NIUTIL -appendprop -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME clients $CLIENT_NAME
- $NIUTIL -appendprop -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME client_domains $PARENT_DOMAIN
-
- # Create bootparams
-
- $NIUTIL -createprop -P $PARENT_PASSWORD $PARENT_DOMAIN /machines/$CLIENT_NAME bootparams root=${SERVER_NAME}:$ROOT_IMAGE private=${SERVER_NAME}:$ROOT_IMAGE/private
-
- # All done
-
- $ECHO "NetInstall client configuration complete."
- exit 0
-