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

  1. #!/bin/csh -f
  2. #
  3. # Set up a NetInstall client
  4. # Copyright (C) 1994 by NeXT Computer, Inc.  All rights reserved.
  5.  
  6. # Configuration variables.  
  7.  
  8. set CONFIG_DOMAIN=/
  9. set PARENT_DOMAIN=-UNKNOWN-
  10. set CLIENT_NAME=-UNKNOWN-
  11. set SERVER_NAME=-UNKNOWN-
  12.  
  13. # Trap SIGINT. This keeps the tty from getting messed up if
  14. # someone types ^C while the shell is reading a password.
  15.  
  16. onintr -
  17.  
  18. # All command names are stored in variable 
  19.  
  20. set AWK=/bin/awk
  21. set BASENAME=/usr/bin/basename
  22. set CAT=/bin/cat
  23. set ECHO=/bin/echo
  24. set ERROR=$ECHO
  25. set GREP=/bin/grep
  26. set HEAD=/usr/ucb/head
  27. set LS=/bin/ls
  28. set NIUTIL=/usr/bin/niutil
  29. set RM=/bin/rm
  30. set SLEEP=/usr/bin/sleep
  31. set STTY=/bin/stty
  32. set WC=/usr/ucb/wc
  33.  
  34. set TRUE=1
  35. set FALSE=0
  36.  
  37. # Determine host architecture
  38.  
  39. set ARCH=-UNKNOWN-
  40.  
  41. $CAT /usr/lib/NextStep/software_version | $GREP Lightning > /dev/null
  42. if ($status == 0) then
  43.         set ARCH=NeXT
  44. else
  45. $CAT /usr/lib/NextStep/software_version | $GREP Thunder > /dev/null
  46. if ($status == 0) then
  47.         set ARCH=i386
  48. else
  49. $CAT /usr/lib/NextStep/software_version | $GREP Blaze > /dev/null
  50. if ($status == 0) then
  51.         set ARCH=hp
  52. endif
  53. endif
  54. endif
  55.  
  56. if ($ARCH != NeXT && $ARCH != i386) then
  57.     $ERROR 'You must run this program on a NeXT or Intel-based computer.'
  58.     exit 1
  59. endif
  60.  
  61. set PROGRAM_NAME=`$BASENAME ${0} .csh`
  62. $ECHO -n "usage: ${PROGRAM_NAME} " > /tmp/_usage_$$
  63. $ECHO '-client hostname -server hostname -domain name [-delete] [-config_domain name]' >> /tmp/_usage_$$
  64. $ECHO 'arguments:' >> /tmp/_usage_$$
  65. $ECHO '    -client hostname   NetInstall client' >> /tmp/_usage_$$
  66. $ECHO '    -server hostname   Server for NetInstall client' >> /tmp/_usage_$$
  67. $ECHO -n '    -domain name       Client' >> /tmp/_usage_$$
  68. $ECHO -n "'" >> /tmp/_usage_$$
  69. $ECHO 's parent NetInfo domain' >> /tmp/_usage_$$
  70. $ECHO '    -delete           Delete client configuration' >> /tmp/_usage_$$
  71. $ECHO '    -config_domain    Domain where servers are recorded (default is "/")' >> /tmp/_usage_$$
  72.  
  73. set DESTROY=$FALSE
  74.  
  75. # Parse command-line options
  76.  
  77. while ($#argv > 0)
  78.     switch (${1})
  79.     case "-help": # Print help message
  80.         $CAT /tmp/_usage_$$
  81.         $RM /tmp/_usage_$$
  82.         exit 1
  83.         breaksw
  84.     case "-client": # Client name
  85.         if ($#argv < 2) then
  86.             $ERROR "${PROGRAM_NAME}: missing argument to -client."
  87.             $CAT /tmp/_usage_$$
  88.             $RM /tmp/_usage_$$
  89.             exit 1
  90.         endif
  91.         set CLIENT_NAME="${2}"
  92.         shift
  93.         breaksw
  94.     case "-server": # Server name
  95.         if ($#argv < 2) then
  96.             $ERROR "${PROGRAM_NAME}: missing argument to -server."
  97.             $CAT /tmp/_usage_$$
  98.             $RM /tmp/_usage_$$
  99.             exit 1
  100.         endif
  101.         set SERVER_NAME="${2}"
  102.         shift
  103.         breaksw
  104.     case "-domain": # Client's parent domain name
  105.         if ($#argv < 2) then
  106.             $ERROR "${PROGRAM_NAME}: missing argument to -domain."
  107.             $CAT /tmp/_usage_$$
  108.             $RM /tmp/_usage_$$
  109.             exit 1
  110.         endif
  111.         set PARENT_DOMAIN="${2}"
  112.         shift
  113.         breaksw
  114.     case "-delete": # Delete client
  115.         set DESTROY=$TRUE    
  116.         breaksw
  117.     case "-config_domain": # Where servers are recorded
  118.         if ($#argv < 2) then
  119.             $ERROR "${PROGRAM_NAME}: missing argument to -config_domain."
  120.             $CAT /tmp/_usage_$$
  121.             $RM /tmp/_usage_$$
  122.             exit 1
  123.         endif
  124.         set CONFIG_DOMAIN="${2}"
  125.         shift
  126.         breaksw
  127.     default: # Unknown flag
  128.         $ERROR "${PROGRAM_NAME}: unknown option ${1}."
  129.         $CAT /tmp/_usage_$$
  130.         $RM /tmp/_usage_$$
  131.         exit 1
  132.         breaksw
  133.     endsw
  134.     shift
  135. end
  136.  
  137. if (${CLIENT_NAME}x == "-UNKNOWN-x") then
  138.         $ERROR "${PROGRAM_NAME}: client name not specified."
  139.         $CAT /tmp/_usage_$$
  140.         $RM /tmp/_usage_$$
  141.         exit 1
  142. endif
  143.  
  144. if (${SERVER_NAME}x == "-UNKNOWN-x") then
  145.         $ERROR "${PROGRAM_NAME}: server name not specified."
  146.         $CAT /tmp/_usage_$$
  147.         $RM /tmp/_usage_$$
  148.         exit 1
  149. endif
  150.  
  151. if (${PARENT_DOMAIN}x == "-UNKNOWN-x") then
  152.         $ERROR "${PROGRAM_NAME}: domain name not specified."
  153.         $CAT /tmp/_usage_$$
  154.         $RM /tmp/_usage_$$
  155.         exit 1
  156. endif
  157.  
  158. $RM /tmp/_usage_$$
  159.  
  160. # Check NetInstall server
  161.  
  162. set SERVER_IMAGE=`$NIUTIL -read $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME | $GREP install_root | $AWK '{print $2}'`
  163. set IMAGE_DIR=/Net/${SERVER_NAME}$SERVER_IMAGE
  164.  
  165. $LS $IMAGE_DIR | $GREP "not found"
  166. if ($status == 0) then
  167.     $ERROR 'Can't find NetInstall server $SERVER_NAME directory $IMAGE_DIR.'
  168.     exit 1
  169. endif
  170.  
  171. set NIUTIL=${IMAGE_DIR}$NIUTIL
  172.  
  173. # check client configuration
  174.  
  175. set TEST_CLIENT=`$NIUTIL -read $PARENT_DOMAIN /machines/$CLIENT_NAME | $WC -l`
  176. if (${TEST_CLIENT}x == "0x") then
  177.         $ERROR -n "${PROGRAM_NAME}: can't find: "
  178.         $ERROR -n $PARENT_DOMAIN 
  179.         $ERROR -n ":/machines/$CLIENT_NAME"
  180.         $CAT /tmp/_usage_$$
  181.         $RM /tmp/_usage_$$
  182.         exit 1
  183. endif
  184.  
  185. # Acquire root password for parent NetInfo domain
  186.  
  187. set GET_PW=$TRUE
  188. $ECHO -n "Please enter the root password for the NetInfo domain: "
  189. $ECHO -n '"'
  190. $ECHO -n $PARENT_DOMAIN
  191. $ECHO '"'
  192.  
  193. while ($GET_PW == $TRUE)
  194.     $STTY -echo
  195.     $ECHO -n "Password: "
  196.     set PARENT_PASSWORD=$<
  197.     $STTY echo
  198.     $ECHO ""
  199.     if (${PARENT_PASSWORD}x == "x") then
  200.         set PARENT_PASSWORD='""'
  201.     endif
  202.  
  203.     # Check password 
  204.  
  205.     $NIUTIL -createprop -P $PARENT_PASSWORD $PARENT_DOMAIN / _test_$$
  206.     set STATUS=`$NIUTIL -read $PARENT_DOMAIN / | $GREP _test_$$`
  207.     if (${STATUS}x == "x") then
  208.         $ECHO -n "Password incorrect.  Do you wish to retry? [yn] "
  209.         set USER_INPUT=$<
  210.         if (${USER_INPUT}x == "nx" || ${USER_INPUT}x == "Nx") then
  211.             exit 1
  212.         endif
  213.         $SLEEP 2
  214.     else
  215.         $NIUTIL -destroyprop -P $PARENT_PASSWORD $PARENT_DOMAIN / _test_$$
  216.         set GET_PW=$FALSE
  217.     endif
  218. end
  219.  
  220. # Acquire root password for "config" NetInfo domain
  221.  
  222. set GET_PW=$TRUE
  223. $ECHO -n "Please enter the root password for the NetInfo domain: "
  224. $ECHO -n '"'
  225. $ECHO -n $CONFIG_DOMAIN
  226. $ECHO '"'
  227.  
  228. while ($GET_PW == $TRUE)
  229.     $STTY -echo
  230.     $ECHO -n "Password: "
  231.     set ROOT_PASSWORD=$<
  232.     $STTY echo
  233.     $ECHO ""
  234.     if (${ROOT_PASSWORD}x == "x") then
  235.         set ROOT_PASSWORD='""'
  236.     endif
  237.  
  238.     # Check password 
  239.  
  240.     $NIUTIL -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
  241.     set STATUS=`$NIUTIL -read $CONFIG_DOMAIN / | $GREP _test_$$`
  242.     if (${STATUS}x == "x") then
  243.         $ECHO -n "Password incorrect.  Do you wish to retry? [yn] "
  244.         set USER_INPUT=$<
  245.         if (${USER_INPUT}x == "nx" || ${USER_INPUT}x == "Nx") then
  246.             exit 1
  247.         endif
  248.         $SLEEP 2
  249.     else
  250.         $NIUTIL -destroyprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
  251.         set GET_PW=$FALSE
  252.     endif
  253. end
  254.  
  255. # Get the server's root image directory name
  256.  
  257. set ROOT_IMAGE=`$NIUTIL -read $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME | $GREP '^install_root: ' | $AWK '{print $2}'`
  258. if (${ROOT_IMAGE}x == "x") then
  259.         $ERROR "${PROGRAM_NAME}: can't find server configuration."
  260.         $CAT /tmp/_usage_$$
  261.         $RM /tmp/_usage_$$
  262.         exit 1
  263. endif
  264.  
  265. if ($DESTROY == $TRUE) then
  266.     # Delete client from server's list of clients
  267.     $NIUTIL -destroyval -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME clients $CLIENT_NAME
  268.     $NIUTIL -destroyval -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME client_domains $PARENT_DOMAIN
  269.  
  270.     # Destroy bootparams
  271.  
  272.     $NIUTIL -destroyprop -P $PARENT_PASSWORD $PARENT_DOMAIN /machines/$CLIENT_NAME bootparams 
  273.  
  274.     # All done
  275.  
  276.     $ECHO "NetInstall client configuration deleted."
  277.     exit 0
  278.  
  279. endif
  280.  
  281. # Add new client to server's list of clients
  282. $NIUTIL -appendprop -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME clients $CLIENT_NAME
  283. $NIUTIL -appendprop -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME client_domains $PARENT_DOMAIN
  284.  
  285. # Create bootparams
  286.  
  287. $NIUTIL -createprop -P $PARENT_PASSWORD $PARENT_DOMAIN /machines/$CLIENT_NAME bootparams root=${SERVER_NAME}:$ROOT_IMAGE private=${SERVER_NAME}:$ROOT_IMAGE/private
  288.  
  289. # All done
  290.  
  291. $ECHO "NetInstall client configuration complete."
  292. exit 0