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

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