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

  1. echo This shell script is no longer supported.
  2. exit 1
  3.  
  4. #!/bin/csh -f
  5. #
  6. # Set up a NetInstall server
  7. # Copyright (C) 1994 by NeXT Computer, Inc.  All rights reserved.
  8.  
  9. # usage: server [-cdrom dir] [-image dir]
  10. # options:
  11. #         -cdrom dir   Name of NEXTSTEP release CDROM
  12. #         -image dir   Directory for NEXTSTEP image
  13.  
  14. # A Network Install server has an NFS-exported directory that 
  15. # contains an image of the NEXTSTEP release CD-ROM.  The server
  16. # is also recorded in the NetInfo root domain, in the directory
  17. # /locations/install_servers/<servername>.  A soft, read-only 
  18. # mount is placed in the root domain.
  19.  
  20. # Configuration variables.  Change these if you with to use this
  21. # script with a custom CD-ROM or a different name for the CD-ROM 
  22. # root image directory.  You can over-ride both of these variables
  23. # with the -cdrom and -image command-line options.
  24.  
  25. set CDROM=/OPENSTEP_4.2
  26. set ROOT_IMAGE=/NEXTSTEP_INSTALL
  27.  
  28. # Trap SIGINT. This keeps the tty from getting messed up if
  29. # someone types ^C while the shell is reading a password.
  30.  
  31. onintr -
  32.  
  33. # All command names are stored in variables 
  34.  
  35. set AWK=/bin/awk
  36. set BASENAME=/usr/bin/basename
  37. set CAT=/bin/cat
  38. set DF=/bin/df
  39. set ECHO=/bin/echo
  40. set ERROR=$ECHO
  41. set EXPORTFS=/usr/etc/exportfs
  42. set GREP=/bin/grep
  43. set HOSTNAME=/bin/hostname
  44. set IFCONFIG=/usr/etc/ifconfig
  45. set LS=/bin/ls
  46. set MKDIRS=/bin/mkdirs
  47. set MOUNTD=/usr/etc/rpc.mountd
  48. set NFSD=/usr/etc/nfsd
  49. set NIUTIL=/usr/bin/niutil
  50. set PS=/bin/ps
  51. set RM=/bin/rm
  52. set SLEEP=/usr/bin/sleep
  53. set STTY=/bin/stty
  54. set TAIL=/usr/ucb/tail
  55. set WC=/usr/ucb/wc
  56.  
  57. set TRUE=1
  58. set FALSE=0
  59.  
  60. set CONFIG_DOMAIN=/
  61. set RELEASE_NAME=`$BASENAME $CDROM ""`
  62. set HOST_NAME=`$HOSTNAME`
  63. set PROGRAM_NAME=`$BASENAME ${0} .csh`
  64. $ECHO -n "usage: ${PROGRAM_NAME} " > /tmp/_usage_$$
  65. $ECHO '[-cdrom dir] [-image dir] [-config_domain name]' >> /tmp/_usage_$$
  66. $ECHO 'options:' >> /tmp/_usage_$$
  67. $ECHO '    -cdrom dir        Name of NEXTSTEP release CDROM' >> /tmp/_usage_$$
  68. $ECHO '    -image dir        Directory for NEXTSTEP image' >> /tmp/_usage_$$
  69. $ECHO '    -config_domain    Where to record servers (default is "/")' >> /tmp/_usage_$$
  70.  
  71. # This program must be run by root
  72.  
  73. set WHO=`$PS -l $$ | $TAIL -1 | $AWK '{print $2}'`
  74. if (${WHO}x != "0x") then
  75.     $ERROR 'You must run this program as "root".'
  76.     exit 1
  77. endif
  78.  
  79. # Parse command-line options
  80.  
  81. while ($#argv > 0)
  82.     switch (${1})
  83.     case "-help": # Print help message
  84.         $CAT /tmp/_usage_$$
  85.         $RM /tmp/_usage_$$
  86.         exit 1
  87.         breaksw
  88.     case "-cdrom": # CDROM name
  89.         if ($#argv < 2) then
  90.             $ERROR "${PROGRAM_NAME}: missing argument to -cdrom"
  91.             $CAT /tmp/_usage_$$
  92.             $RM /tmp/_usage_$$
  93.             exit 1
  94.         endif
  95.         set CDROM="${2}"
  96.         shift
  97.         breaksw
  98.     case "-image": # ROOT_IMAGE name
  99.         if ($#argv < 2) then
  100.             $ERROR "${PROGRAM_NAME}: missing argument to -image"
  101.             $CAT /tmp/_usage_$$
  102.             $RM /tmp/_usage_$$
  103.             exit 1
  104.         endif
  105.         set ROOT_IMAGE="${2}"
  106.         shift
  107.         breaksw
  108.     case "-config_domain": # Where servers are recorded
  109.         if ($#argv < 2) then
  110.             $ERROR "${PROGRAM_NAME}: missing argument to -config_domain."
  111.             $CAT /tmp/_usage_$$
  112.             $RM /tmp/_usage_$$
  113.             exit 1
  114.         endif
  115.         set CONFIG_DOMAIN="${2}"
  116.         shift
  117.         breaksw
  118.     default: # Unknown flag
  119.         $ERROR "${PROGRAM_NAME}: unknown option ${1}"
  120.         $CAT /tmp/_usage_$$
  121.         $RM /tmp/_usage_$$
  122.         exit 1
  123.         breaksw
  124.     endsw
  125.     shift
  126. end
  127.  
  128. $RM /tmp/_usage_$$
  129.  
  130. # Get my address and netmask
  131. # Try en0 first, then tr0
  132.  
  133. set INTERFACE=en0
  134. $IFCONFIG $INTERFACE > /dev/null
  135. if ($status != 0) then
  136.     # No en0 interface, try tr0
  137.     INTERFACE=tr0
  138.     $IFCONFIG $INTERFACE > /dev/null
  139.     if ($status != 0) then
  140.         # No interfaces
  141.         $ERROR "${PROGRAM_NAME}: Can't find a working network interface."
  142.         exit 1
  143.     endif
  144. endif
  145.  
  146. set IPADDRESS=`$IFCONFIG $INTERFACE | $TAIL -1 | $AWK '{print $2}'`
  147. set NETMASK=`$IFCONFIG $INTERFACE | $TAIL -1 | $AWK '{print $4}'`
  148. set NM=`$ECHO $NETMASK | tr 'a-f' 'A-F' | $AWK '{printf("16i %s p %s p %s p %s pq\n",substr($1,1,2), substr($1,3,2) ,substr($1,5,2), substr($1,7,2))}' | dc`
  149. set NETMASK=`$ECHO $NM[1].$NM[2].$NM[3].$NM[4]`
  150.  
  151. # Find out if CDROM is present
  152.  
  153. while (! -d $CDROM)
  154.     $ECHO -n 'Please insert the CDROM "'
  155.     $ECHO -n $CDROM
  156.     $ECHO '" in the drive.'
  157.     $ECHO -n 'Press Enter to proceed or type "quit" to exit: '
  158.     set USER_INPUT=$<
  159.  
  160.     if (${USER_INPUT}x == "quitx") then
  161.         exit 0
  162.     endif
  163.  
  164.     if (! -d $CDROM) then
  165.         $SLEEP 10
  166.     endif
  167.     $ECHO ""
  168. end
  169.  
  170. if (! -d $CDROM) then
  171.     $ERROR -n "${PROGRAM_NAME}: NEXTSTEP release CDROM "
  172.     $ERROR -n '"'
  173.     $ERROR -n $CDROM
  174.     $ERROR '" is not available.'
  175.     exit 1
  176. endif
  177.  
  178. set RELEASE_SIZE=`$DF $CDROM | $TAIL -1 | $AWK '{print $3}'`
  179.  
  180. # Determine if release image directory exists
  181.  
  182. if (! -w $ROOT_IMAGE) then
  183.     if (! -d $ROOT_IMAGE) then
  184.         # Directory doesn't exist: create it
  185.         $MKDIRS $ROOT_IMAGE
  186.         if (! -w $ROOT_IMAGE) then
  187.             $ERROR -n "${PROGRAM_NAME}: Can't create directory "
  188.             $ERROR -n '"'
  189.             $ERROR -n $ROOT_IMAGE
  190.             $ERROR '".'
  191.             exit 1
  192.         endif
  193.     else
  194.         $ERROR -n "${PROGRAM_NAME}: No write permission for directory "
  195.         $ERROR -n '"'
  196.         $ERROR -n $ROOT_IMAGE
  197.         $ERROR '".'
  198.         exit 1
  199.     endif
  200. endif
  201.  
  202. # Check if release image directory is a local directory
  203.  
  204. set WHERE=`$DF -i $ROOT_IMAGE | $TAIL -1 | $AWK '{print $3}'`
  205. if (${WHERE}x == "-1x") then
  206.     $ERROR -n "${PROGRAM_NAME}: Directory "
  207.     $ERROR -n '"'
  208.     $ERROR -n $ROOT_IMAGE
  209.     $ERROR '" is not on a local disk.'
  210.     exit 1
  211. endif
  212.  
  213. # Check if release image directory is empty
  214.  
  215. set FILES=`$LS -1a $ROOT_IMAGE | $GREP -v "lost+found" | $WC -l`
  216. if (${FILES}x != "2x") then
  217.     $ERROR -n "${PROGRAM_NAME}: Directory "
  218.     $ERROR -n '"'
  219.     $ERROR -n $ROOT_IMAGE
  220.     $ERROR '" is not empty.'
  221.     exit 1
  222. endif
  223.  
  224. # Check if release image directory has enough space
  225.  
  226. set AVAIL_SIZE=`$DF $ROOT_IMAGE | $TAIL -1 | $AWK '{print $4}'`
  227. if ($AVAIL_SIZE < $RELEASE_SIZE) then
  228.     $ERROR -n "${PROGRAM_NAME}: Insufficent space available in directory "
  229.     $ERROR -n '"'
  230.     $ERROR $ROOT_IMAGE
  231.     $ERROR '".'
  232.     $ERROR "${PROGRAM_NAME}: $AVAIL_SIZE Kbytes are available. $RELEASE_SIZE Kbytes are required."
  233.     exit 1
  234. endif
  235.  
  236. # Acquire root password for "config" NetInfo domain
  237.  
  238. set NIUTIL_33=$CDROM$NIUTIL
  239.  
  240. set GET_PW=$TRUE
  241. $ECHO -n "Please enter the root password for the NetInfo domain: "
  242. $ECHO -n '"'
  243. $ECHO -n $CONFIG_DOMAIN
  244. $ECHO '"'
  245.  
  246. while ($GET_PW == $TRUE)
  247.     $STTY -echo
  248.     $ECHO -n "Password: "
  249.     set ROOT_PASSWORD=$<
  250.     $STTY echo
  251.     $ECHO ""
  252.     if (${ROOT_PASSWORD}x == "x") then
  253.         set ROOT_PASSWORD='""'
  254.     endif
  255.  
  256.     # Check password 
  257.  
  258.     $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
  259.     set STATUS=`$NIUTIL_33 -read $CONFIG_DOMAIN / | $GREP _test_$$`
  260.     if (${STATUS}x == "x") then
  261.         $ECHO -n "Password incorrect.  Do you wish to retry? [yn] "
  262.         set USER_INPUT=$<
  263.         if (${USER_INPUT}x == "nx" || ${USER_INPUT}x == "Nx") then
  264.             exit 1
  265.         endif
  266.         $SLEEP 2
  267.     else
  268.         $NIUTIL_33 -destroyprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
  269.         set GET_PW=$FALSE
  270.     endif
  271. end
  272.  
  273. # Create /locations/install_servers entry
  274.  
  275. set NIDIR=/locations/install_servers/$HOST_NAME
  276. set RELEASE_SIZE=`$DF $CDROM | $TAIL -1 | $AWK '{print $4}'`
  277.  
  278. $NIUTIL_33 -create -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR
  279. $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR ip_address $IPADDRESS
  280. $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR netmask $NETMASK
  281. $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR install_root $ROOT_IMAGE
  282. $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR release $RELEASE_NAME
  283. $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR size $RELEASE_SIZE
  284. $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR clients
  285. $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR client_domains
  286.  
  287. # Create /mounts entry
  288.  
  289. set NIDIR=/mounts/${HOST_NAME}-temp-$$
  290.  
  291. $NIUTIL_33 -create -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR
  292. $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR dir /Net
  293. $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR opts ro bg soft net
  294. $NIUTIL_33 -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN $NIDIR name ${HOST_NAME}:$ROOT_IMAGE
  295.  
  296.  
  297. # Copy CDROM to release image
  298.  
  299. $ECHO Copying $CDROM to $ROOT_IMAGE
  300.  
  301. $CDROM/usr/etc/ditto $CDROM $ROOT_IMAGE
  302.  
  303. # Export the root image
  304.  
  305. $EXPORTFS -i $ROOT_IMAGE >& /tmp/_test_$$
  306. $GREP "already exported" /tmp/_test_$$ > /dev/null
  307. if ($status != 0) then
  308.     $NIUTIL_33 -create . /exports/netinstall.$$
  309.     $NIUTIL_33 -createprop . /exports/netinstall.$$ opts ro anon=0
  310.     $NIUTIL_33 -createprop . /exports/netinstall.$$ name $ROOT_IMAGE
  311. endif
  312.  
  313. $RM /tmp/_test_$$
  314.  
  315. $EXPORTFS -au >& /dev/null
  316. $EXPORTFS -a >& /dev/null
  317.  
  318. # Start nfsd if it's not already running
  319.  
  320. $PS -ax | $GREP '(nfsd)' | $GREP -v 'grep' > /dev/null
  321. if ($status != 0) then
  322.     $NFSD 6
  323. endif
  324.  
  325. # Start rpc.mountd if it's not already running
  326.  
  327. $PS -ax | $GREP '(rpc.mountd)' | $GREP -v 'grep' > /dev/null
  328. if ($status != 0) then
  329.     $MOUNTD
  330. endif
  331.  
  332. # All done
  333.  
  334. $ECHO "NetInstall server configuration complete."
  335. exit 0
  336.