home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-User.iso / NextAdmin / NetInstallHelper.app / delete_netinstall_server < prev    next >
Text File  |  1997-03-13  |  4KB  |  169 lines

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