home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 4.0 PR1 / NeXT_NEXTSTEP_4.0_PR1_(beta).rar / Openstep4-Pr1User.iso / NextAdmin / NetInstallHelper.app / delete_netinstall_server < prev    next >
Text File  |  1995-01-31  |  4KB  |  166 lines

  1. #!/bin/csh -f
  2. #
  3. # Delete a NetInstall server configuration
  4. # Copyright (C) 1994 by NeXT Computer, Inc.  All rights reserved.
  5.  
  6. # Trap SIGINT. This keeps the tty from getting messed up if
  7. # someone types ^C while the shell is reading a password.
  8.  
  9. onintr -
  10.  
  11. # All command names are stored in variable 
  12.  
  13. set AWK=/bin/awk
  14. set BASENAME=/usr/bin/basename
  15. set CAT=/bin/cat
  16. set DF=/bin/df
  17. set ECHO=/bin/echo
  18. set ERROR=$ECHO
  19. set EXPORTFS=/usr/etc/exportfs
  20. set GREP=/bin/grep
  21. set HOSTNAME=/bin/hostname
  22. set IFCONFIG=/usr/etc/ifconfig
  23. set LS=/bin/ls
  24. set MKDIRS=/bin/mkdirs
  25. set MOUNTD=/usr/etc/rpc.mountd
  26. set NFSD=/usr/etc/nfsd
  27. set NIUTIL=/usr/bin/niutil
  28. set PS=/bin/ps
  29. set RM=/bin/rm
  30. set SLEEP=/usr/bin/sleep
  31. set STTY=/bin/stty
  32. set TAIL=/usr/ucb/tail
  33. set WC=/usr/ucb/wc
  34.  
  35. set TRUE=1
  36. set FALSE=0
  37.  
  38. set CONFIG_DOMAIN=/
  39. set HOST_NAME=`$HOSTNAME`
  40. set PROGRAM_NAME=`$BASENAME ${0} .csh`
  41.  
  42. $ECHO "usage: ${PROGRAM_NAME} [-config_domain name]" > /tmp/_usage_$$
  43. $ECHO 'arguments:' >> /tmp/_usage_$$
  44. $ECHO '    -config_domain    Domain where servers are recorded (default is "/")' >> /tmp/_usage_$$
  45.  
  46. # This program must be run by root
  47.  
  48. set WHO=`$PS -l $$ | $TAIL -1 | $AWK '{print $2}'`
  49. if (${WHO}x != "0x") then
  50.     $ERROR 'You must run this program as "root".'
  51.     exit 1
  52. endif
  53.  
  54. # Parse command-line options
  55.  
  56. while ($#argv > 0)
  57.     switch (${1})
  58.     case "-help": # Print help message
  59.         $CAT /tmp/_usage_$$
  60.         $RM /tmp/_usage_$$
  61.         exit 1
  62.         breaksw
  63.     case "-config_domain": # Where servers are recorded
  64.         if ($#argv < 2) then
  65.             $ERROR "${PROGRAM_NAME}: missing argument to -config_domain."
  66.             $CAT /tmp/_usage_$$
  67.             $RM /tmp/_usage_$$
  68.             exit 1
  69.         endif
  70.         set CONFIG_DOMAIN="${2}"
  71.         shift
  72.         breaksw
  73.     default: # Unknown flag
  74.         $ERROR "${PROGRAM_NAME}: unknown option ${1}"
  75.         $CAT /tmp/_usage_$$
  76.         $RM /tmp/_usage_$$
  77.         exit 1
  78.         breaksw
  79.     endsw
  80.     shift
  81. end
  82.  
  83. $RM /tmp/_usage_$$
  84.  
  85. # Check server configuration
  86.  
  87. $NIUTIL -read $CONFIG_DOMAIN /locations/install_servers/$HOST_NAME > /tmp/_delete_$$
  88. if ($status == 1) then
  89.     $ERROR "Can't get server configuration for $HOST_NAME"
  90.     exit 1
  91. endif
  92.  
  93. set ROOT_IMAGE=`$GREP '^install_root:' /tmp/_delete_$$ | $AWK '{print $2}'`
  94. if (${ROOT_IMAGE}x == x) then 
  95.     $ERROR "Bad server configuration for $HOST_NAME"
  96.     $ERROR "Can't deterimine release image directory name"
  97.     exit 1
  98. endif
  99.  
  100. # Acquire root password for "config" NetInfo domain
  101.  
  102. set GET_PW=$TRUE
  103. $ECHO -n "Please enter the root password for the NetInfo domain: "
  104. $ECHO -n '"'
  105. $ECHO -n $CONFIG_DOMAIN
  106. $ECHO '"'
  107.  
  108. while ($GET_PW == $TRUE)
  109.     $STTY -echo
  110.     $ECHO -n "Password: "
  111.     set ROOT_PASSWORD=$<
  112.     $STTY echo
  113.     $ECHO ""
  114.     if (${ROOT_PASSWORD}x == "x") then
  115.         set ROOT_PASSWORD='""'
  116.     endif
  117.  
  118.     # Check password 
  119.  
  120.     $NIUTIL -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
  121.     set STATUS=`$NIUTIL -read $CONFIG_DOMAIN / | $GREP _test_$$`
  122.     if (${STATUS}x == "x") then
  123.         $ECHO -n "Password incorrect.  Do you wish to retry? [yn] "
  124.         set USER_INPUT=$<
  125.         if (${USER_INPUT}x == "nx" || ${USER_INPUT}x == "Nx") then
  126.             exit 1
  127.         endif
  128.         $SLEEP 2
  129.     else
  130.         $NIUTIL -destroyprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
  131.         set GET_PW=$FALSE
  132.     endif
  133. end
  134.  
  135. # Delete root domain /locations/install_servers entry
  136.  
  137. set NIDIR=/locations/install_servers/$HOST_NAME
  138. $NIUTIL -destroy -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR
  139.  
  140. # Delete root domain /mounts entry if it exists
  141.  
  142. set NIDIR=`$NIUTIL -list $CONFIG_DOMAIN /mounts | $GREP "${HOST_NAME}:$ROOT_IMAGE" | $AWK '{print $1}'`
  143. if (${NIDIR}x != x) then
  144.     $NIUTIL -destroy -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR
  145. endif
  146.  
  147. # remove local export if it exists
  148.  
  149. set NIDIR=`$NIUTIL -list . /exports | $GREP "$ROOT_IMAGE" | $AWK '{print $1}'`
  150. if (${NIDIR}x != x) then
  151.     $NIUTIL -destroy . $NIDIR
  152. endif
  153.  
  154. # Remove release image
  155.  
  156. $ECHO -n "OK to destroy directory ${ROOT_IMAGE}: [ny] "
  157. set USER_INPUT=$<
  158. if (${USER_INPUT}x == "yx" || ${USER_INPUT}x == "Yx") then
  159.     $RM -rf $ROOT_IMAGE
  160. endif
  161.  
  162. # All done
  163.  
  164. $ECHO "NetInstall server configuration deleted."
  165. exit 0
  166.