home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.1 (User) / OpenStep 4.1 (User).iso / NextAdmin / NetInstallHelper.app / make_netinstall_floppy < prev    next >
Encoding:
Text File  |  1995-02-17  |  12.6 KB  |  442 lines

  1. #!/bin/csh -f
  2. #
  3. # Create boot and drivers disks for a NetInstall client
  4. # Copyright (C) 1994 by NeXT Computer, Inc.  All rights reserved.
  5.  
  6. # All command names are stored in variables
  7.  
  8. set AWK=/bin/awk
  9. set BASENAME=/usr/bin/basename
  10. set CAT=/bin/cat
  11. set CP=/bin/cp
  12. set DF=/bin/df
  13. set DISK=/usr/etc/disk
  14. set DU=/bin/du
  15. set ECHO=/bin/echo
  16. set ERROR=$ECHO
  17. set GREP=/bin/grep
  18. set HEAD=/usr/ucb/head
  19. set LIPO=/bin/lipo
  20. set LN=/bin/ln
  21. set LS=/bin/ls
  22. set MKDIRS=/bin/mkdirs
  23. set MOUNT=/usr/etc/mount
  24. set NIUTIL=/usr/bin/niutil
  25. set PS=/bin/ps
  26. set RM=/bin/rm
  27. set SED=/bin/sed
  28. set TAIL=/usr/ucb/tail
  29. set UMOUNT=/usr/etc/umount
  30. set ARCH_CMD=/usr/bin/arch
  31. set NEWFS=/etc/newfs
  32.  
  33. set TRUE=1
  34. set FALSE=0
  35.  
  36. set PROGRAM_NAME=`$BASENAME ${0} .csh`
  37. $ECHO -n "usage: ${PROGRAM_NAME} " > /tmp/_usage_$$
  38. $ECHO '[-n] [-c network disk] [-d] [-NeXT_OD] [-config_domain name]' >> /tmp/_usage_$$
  39. $ECHO 'options:' >> /tmp/_usage_$$
  40. $ECHO "  -n               Don't initialize floppy disk" >> /tmp/_usage_$$
  41. $ECHO '  -c network disk  Custom disk for given network and disk drivers' >> /tmp/_usage_$$
  42. $ECHO '  -d               Create a drivers disk rather than a boot disk' >> /tmp/_usage_$$
  43. $ECHO '  -NeXT_OD         Create a boot optical disk for a NeXT computer' >> /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. # Determine host architecture
  55.  
  56. #set ARCH=-UNKNOWN-
  57. set ARCH=`$ARCH_CMD`
  58.  
  59. #$CAT /usr/lib/NextStep/software_version | $GREP Lightning > /dev/null
  60. #if ($status == 0) then
  61. if ($ARCH == m68k) then
  62.     set ARCH=NeXT
  63.     set M68K=$TRUE
  64. else
  65. #$CAT /usr/lib/NextStep/software_version | $GREP Thunder > /dev/null
  66. #if ($status == 0) then
  67. if ($ARCH == i386) then
  68.     set M68K=$FALSE
  69. else
  70. #$CAT /usr/lib/NextStep/software_version | $GREP Blaze > /dev/null
  71. #if ($status == 0) then
  72. if ($ARCH == hppa) then
  73.         set ARCH=hp
  74. endif
  75. endif
  76. endif
  77.  
  78. if ($ARCH != NeXT && $ARCH != i386) then
  79.     $ERROR 'You must run this program on a NeXT or Intel-based computer.'
  80.     exit 1
  81. endif
  82.  
  83. # Parse command-line options
  84.  
  85. set CONFIG_DOMAIN=/
  86. set INIT_DISK=$TRUE
  87. set CUSTOM=$FALSE
  88. set DRIVERS_DISK=$FALSE
  89. set BLOCK_DEV=/dev/fd0a
  90. set RAW_DEV=/dev/rfd0a
  91.  
  92. while ($#argv > 0)
  93.     switch (${1})
  94.     case "-help": # Print help message
  95.         $CAT /tmp/_usage_$$
  96.         $RM /tmp/_usage_$$
  97.         exit 1
  98.         breaksw
  99.     case "-n": # Don't initialize disk
  100.         set INIT_DISK=$FALSE
  101.         breaksw
  102.     case "-d": # Create a drivers disk
  103.         set DRIVERS_DISK=$TRUE
  104.         breaksw
  105.     case "-c": # Custom disk
  106.         if ($#argv < 3) then
  107.             $ERROR "${PROGRAM_NAME}: missing arguments to -d"
  108.             $CAT /tmp/_usage_$$
  109.             $RM /tmp/_usage_$$
  110.             exit 1
  111.         endif
  112.         set CUSTOM=$TRUE
  113.         set NETWORK_DRIVER="${2}"
  114.         set DISK_DRIVER="${3}"
  115.         shift
  116.         shift
  117.         breaksw
  118.     case "-NeXT_OD": # Create a NeXT Optical Disk
  119.         if ($ARCH != NeXT) then
  120.             $ERROR '-NeXT_OD option only supported on a NeXT computer.'
  121.             exit 1
  122.         endif
  123.         set BLOCK_DEV=/dev/od0a
  124.         set RAW_DEV=/dev/rod0a
  125.         breaksw
  126.     case "-config_domain": # Where servers are recorded
  127.         if ($#argv < 2) then
  128.             $ERROR "${PROGRAM_NAME}: missing argument to -config_domain."
  129.             $CAT /tmp/_usage_$$
  130.             $RM /tmp/_usage_$$
  131.             exit 1
  132.         endif
  133.         set CONFIG_DOMAIN="${2}"
  134.         shift
  135.         breaksw
  136.     default: # Unknown flag
  137.         $ERROR "${PROGRAM_NAME}: unknown option ${1}."
  138.         $CAT /tmp/_usage_$$
  139.         $RM /tmp/_usage_$$
  140.         exit 1
  141.         breaksw
  142.     endsw
  143.     shift
  144. end
  145.  
  146. $RM /tmp/_usage_$$
  147.  
  148. # Is there a NetInstall server?
  149.  
  150. $NIUTIL -list $CONFIG_DOMAIN /locations/install_servers >& /dev/null
  151. if ($status == 1) then
  152.     $ERROR 'Can't find any NetInstall servers.'
  153.     exit 1
  154. endif
  155.  
  156. set SERVER_NAME=`$NIUTIL -list $CONFIG_DOMAIN /locations/install_servers | $HEAD -1 | $AWK '{print $2}'`
  157. set SERVER_IMAGE=`$NIUTIL -read $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME | $GREP install_root | $AWK '{print $2}'`
  158. set IMAGE_DIR=/Net/${SERVER_NAME}$SERVER_IMAGE
  159.  
  160. $LS $IMAGE_DIR | $GREP "not found"
  161. if ($status == 0) then
  162.     $ERROR 'Can't find NetInstall server $SERVER_NAME directory $IMAGE_DIR.'
  163.     exit 1
  164. endif
  165.  
  166. # Make a NeXT disk?
  167.  
  168. if ($M68K == $TRUE) then
  169.  
  170.     set CUSTOM=$FALSE
  171.     set DRIVERS_DISK=$FALSE
  172.  
  173.     # Must be NeXT 
  174.  
  175.     if ($ARCH != NeXT) then
  176.         $ERROR 'You must run this program on an NeXT computer.'
  177.         exit 1
  178.     endif
  179.  
  180. else
  181.  
  182.     # Must be Intel 
  183.  
  184.     if ($ARCH != i386) then
  185.         $ERROR 'You must run this program on an Intel-based computer.'
  186.         exit 1
  187.     endif
  188.  
  189. endif
  190.  
  191. # Is there a disk mounted?
  192.  
  193. $GREP $BLOCK_DEV /etc/mtab > /dev/null
  194. if ($status == 0) then
  195.  
  196.     # There's a mounted disk in the drive.  Abort.
  197.  
  198.     set DISK_NAME=`$GREP $BLOCK_DEV /etc/mtab | $AWK '{print $2}'`
  199.     $ERROR "${PROGRAM_NAME}: Disk $DISK_NAME is present in the drive."
  200.     $ERROR "${PROGRAM_NAME}: Unmount and eject the disk before running this command."
  201.     exit 1
  202.  
  203. else
  204.     if ($M68K == $FALSE) then
  205.         # No disk present, get user to insert one
  206.  
  207.         $ECHO 'Please insert a floppy disk.'
  208.         $ECHO -n 'Press Enter to proceed or type "quit" to exit: '
  209.         set USER_INPUT=$<
  210.  
  211.         if (${USER_INPUT}x == "quitx") then
  212.             exit 0
  213.         endif
  214.     endif
  215. endif
  216.  
  217. # Initialize the disk
  218.  
  219. if ($INIT_DISK == $TRUE && $DRIVERS_DISK == $FALSE) then
  220.     $DISK -i -l NetInstall $RAW_DEV
  221.     $NEWFS -i 8192 $RAW_DEV
  222. endif
  223. if ($INIT_DISK == $TRUE && $DRIVERS_DISK == $TRUE) then
  224.     $DISK -i -l Drivers $RAW_DEV
  225. endif
  226.  
  227. # Mount the disk
  228.  
  229. set DISK_NAME=/tmp/_netinstall_$$
  230. $MKDIRS $DISK_NAME
  231. $MOUNT $BLOCK_DEV $DISK_NAME
  232.  
  233. $GREP "$DISK_NAME" /etc/mtab > /dev/null
  234. if ($status == 1) then
  235.     $ERROR "${PROGRAM_NAME}: Disk error."
  236.     exit 1
  237. endif
  238.  
  239. # Create drivers disk if -d flag specified
  240.  
  241. if ($DRIVERS_DISK == $TRUE) then
  242.  
  243.     # create /private/Drivers/i386
  244.  
  245.     $MKDIRS $DISK_NAME/private/Drivers/i386
  246.  
  247.     # Get a list of boot drivers
  248.  
  249.     set NET_TABLE=$IMAGE_DIR/private/Drivers/i386/System.config/Instance0.network
  250.     set BOOT_DRIVERS=`$GREP "Boot Drivers" $NET_TABLE | $SED 's/"Boot Drivers" = "//' | $SED 's/";//'`
  251.  
  252.     # if a custom disk, copy specified network and disk drivers
  253.  
  254.     if ($CUSTOM == $TRUE) then
  255.         set ALL_DRIVERS=`$ECHO $BOOT_DRIVERS $NETWORK_DRIVER $DISK_DRIVER`
  256.     else 
  257.         set ALL_DRIVERS=`$ECHO $BOOT_DRIVERS`
  258.  
  259.         # Find available network and disk drivers
  260.  
  261.         foreach DRIVER ($IMAGE_DIR/private/Drivers/i386/*.config)
  262.             set DRIVER_NAME=`$BASENAME $DRIVER .config`
  263.             set FAMILY=`$GREP '"Family"' $DRIVER/Default.table | $AWK '{print $3}' | $SED 's/"//g' | $SED 's/;//'`
  264.             if ($FAMILY == "Network" || $FAMILY == "Disk" || $FAMILY == "SCSI") then
  265.                 if ($DRIVER_NAME != "Floppy" \
  266.                     && $DRIVER_NAME != "IBMTokenRing" \
  267.                     && $DRIVER_NAME != "TokenExpress") then
  268.                     set ALL_DRIVERS=`$ECHO $ALL_DRIVERS $DRIVER_NAME`
  269.                 endif
  270.             endif
  271.         end
  272.     endif
  273.  
  274.     # Copy Drivers
  275.  
  276.     foreach DRIVER ($ALL_DRIVERS)
  277.         set DRIVER_SRC=$IMAGE_DIR/private/Drivers/i386/$DRIVER.config
  278.         set DRIVER_DST=$DISK_NAME/private/Drivers/i386/$DRIVER.config
  279.  
  280.         if (! -d $DRIVER_SRC) then
  281.             $ERROR "${PROGRAM_NAME}: Can't find $DRIVER_SRC"
  282.         else
  283.             $MKDIRS $DRIVER_DST
  284.             $CP $DRIVER_SRC/*_reloc $DRIVER_DST
  285.             $CP $DRIVER_SRC/*.table $DRIVER_DST
  286.             $RM -f $DRIVER_DST/Instance*.table
  287.  
  288.             foreach LANG ($DRIVER_SRC/*.lproj)
  289.                 $MKDIRS $DRIVER_DST/`$BASENAME $LANG`
  290.                 $CP $LANG/*.strings $DRIVER_DST/`$BASENAME $LANG`
  291.             end
  292.  
  293.         endif
  294.     end
  295.  
  296.     # Unmount and eject the disk
  297.  
  298.     $UMOUNT $BLOCK_DEV
  299.     $DISK -e $RAW_DEV
  300.     $RM -f $DISK_NAME
  301.  
  302.     # All done (drivers disk)
  303.  
  304.     $ECHO "NetInstall boot disk build complete."
  305.     $ECHO "You may remove the disk."
  306.     exit 0
  307.  
  308. endif
  309.  
  310. # Make a NeXT boot disk
  311.  
  312. if ($M68K == $TRUE) then
  313.     $DISK -B $IMAGE_DIR/usr/standalone/boot $RAW_DEV
  314.     $LIPO $IMAGE_DIR/mach_kernel -extract m68k -output ${DISK_NAME}/sdmach
  315.     $LN $DISK_NAME/sdmach $DISK_NAME/fdmach
  316.     $LN $DISK_NAME/sdmach $DISK_NAME/odmach
  317.     # Unmount and eject the disk
  318.  
  319.     $UMOUNT $BLOCK_DEV
  320.     $DISK -e $RAW_DEV
  321.     $RM -f $DISK_NAME
  322.  
  323.     # All done
  324.  
  325.     $ECHO "NetInstall boot disk build complete."
  326.     exit 0
  327. endif
  328.  
  329. # Make an Intel boot disk
  330.  
  331. $DISK -B $IMAGE_DIR/usr/standalone/i386/boot $RAW_DEV
  332. $LIPO $IMAGE_DIR/mach_kernel -extract i386 -output ${DISK_NAME}/mach_kernel
  333.  
  334. # Create /usr/standalone/i386/English.lproj
  335.  
  336. $MKDIRS $DISK_NAME/usr/standalone/i386/English.lproj
  337.  
  338. # Copy sarld
  339.  
  340. $CP $IMAGE_DIR/usr/standalone/i386/sarld $DISK_NAME/usr/standalone/i386
  341.  
  342. # Copy /usr/standalone/i386/Language.table
  343.  
  344. $CP $IMAGE_DIR/usr/standalone/i386/Language.table $DISK_NAME/usr/standalone/i386
  345.  
  346. # Copy /usr/standalone/i386/BootHelp.txt
  347.  
  348. $CP $IMAGE_DIR/usr/standalone/i386/BootHelp.txt $DISK_NAME/usr/standalone/i386
  349.  
  350. # Create /usr/standalone/i386/English.lproj/Localizable.strings
  351.  
  352. $CAT << END_OF_STRINGS > /tmp/_strings_$$
  353. "Loading NEXTSTEP";
  354. "Loading %s\n";
  355. "Reading NEXTSTEP configuration";
  356. "Couldn't load standalone linker; unable to load boot drivers.\n";
  357. "Insert file system media and press Return";
  358. "Errors encountered while starting up the computer.\n";
  359. "Pausing 5 seconds...\n";
  360. "Starting NEXTSTEP";
  361. "Can't find %s\n";
  362. "Couldn't start up the computer using this floppy disk.";
  363. "Error loading %s\n";
  364. "Fat binary file doesn't contain i386 code\n";
  365. "Unrecognized binary format\n";
  366. "Error reading commands\n";
  367. "Error loading section\n";
  368. "Read error\n";
  369. "Can't load driver %s without sarld\n";
  370. "Driver %s is larger than %d bytes and can't be loaded.\n";
  371. "Error occurred while linking driver %s:\n%s";
  372. "The floppy disk in the drive contains the following SCSI adapter and hard disk controller device drivers:\n";
  373. "Loading driver %s\n";
  374. "Error loading driver %s\n";
  375. "The driver was not loaded.  ";
  376. "The driver was loaded successfully.  ";
  377. "Press Return to continue.\n";
  378. "Type 1 to load a device driver from the disk in the floppy disk drive.\n";
  379. "Type 2 to continue without loading additional device drivers.\n";
  380. "When you began installing NEXTSTEP, you loaded the following device drivers from a floppy disk:\n";
  381. "Insert the floppy disk that contains these device drivers.\n";
  382. "If you have a floppy disk with NEXTSTEP device drivers that you need to use during installation, insert the floppy disk that contains the device driver for that device.\n";
  383. "The following SCSI adapter and hard disk controller device drivers are available while installing NEXTSTEP:\n";
  384. "If you have a different kind of SCSI adapter or hard disk controller, insert the floppy disk that contains its device driver.\n";
  385. "Searching for drivers";
  386. "Couldn't find /private/Drivers/i386\n";
  387. "There are no device drivers on this floppy disk.\n";
  388. "Error in standalone linker executable\n";
  389. "No room in memory for config file %s\n";
  390. "Reading config: %s\n";
  391. "Config file \"%s\" not found\n";
  392. "System config file '%s' not found\n";
  393. "Loading binary for %s\n";
  394. "Warning: No active drivers specified in system config\n";
  395. "Type the number for the device driver you want to install.\n";
  396. "Type %d to view a list of additional device drivers on this disk.\n";
  397. "Type %d to continue without installing a device driver from this disk.\n";
  398. "The floppy disk in the drive contains device drivers for the following SCSI adapters and hard disk controllers:\n" = "The floppy disk in the drive contains device drivers for the following SCSI adapters, hard disk controllers, and network adapters:\n";
  399. "MESSAGE1" = "Type the number for the network adapter in your computer.\n\n";
  400. "MESSAGE2" = "Type the number for the SCSI adapter or hard disk controller that the hard disk you want to install NEXTSTEP on is connected to.\n\n";
  401. "MESSAGE3" = "If you have another disk with the device driver for this network adapter, insert that disk in the floppy disk drive and type %d.\n";
  402. "MESSAGE4" = "If you have another disk with the device driver for this SCSI adapter or hard disk controller, insert that disk in the floppy disk drive and type %d.\n";
  403. END_OF_STRINGS
  404.  
  405. $CP /tmp/_strings_$$ $DISK_NAME/usr/standalone/i386/English.lproj/Localizable.strings
  406. $RM /tmp/_strings_$$
  407.  
  408. # Copy /private/Drivers/i386/System.config/Instance0.network to Instance0.table
  409.  
  410. $MKDIRS $DISK_NAME/private/Drivers/i386/System.config
  411.  
  412. # if a custom disk, include specified network and disk drivers in Boot Drivers
  413.  
  414.  
  415. set NET_TABLE=$IMAGE_DIR/private/Drivers/i386/System.config/Instance0.network
  416.  
  417. if ($CUSTOM == $TRUE) then
  418.     set BOOT_DRIVERS=`$GREP "Boot Drivers" $NET_TABLE | $SED 's/"Boot Drivers" = "//' | $SED 's/";//'`
  419.     set BOOT_DRIVERS=`$ECHO $BOOT_DRIVERS $NETWORK_DRIVER $DISK_DRIVER`
  420.     $ECHO -n '"Boot Drivers" = "' > /tmp/_table_$$
  421.     $ECHO -n $BOOT_DRIVERS >> /tmp/_table_$$
  422.     $ECHO '";' >> /tmp/_table_$$
  423.     $ECHO '"Install Mode" = "No";' >> /tmp/_table_$$
  424.     $GREP -v "Boot Drivers" $NET_TABLE | $GREP -v "Install Mode" >> /tmp/_table_$$
  425.     $CP /tmp/_table_$$ $DISK_NAME/private/Drivers/i386/System.config/Instance0.table
  426.     $RM /tmp/_table_$$
  427. else
  428.     $CP $NET_TABLE $DISK_NAME/private/Drivers/i386/System.config/Instance0.table
  429. endif
  430.  
  431. # Unmount and eject the floppy disk
  432.  
  433. $UMOUNT $BLOCK_DEV
  434. $DISK -e $RAW_DEV
  435. $RM -f $DISK_NAME
  436.  
  437. # All done
  438.  
  439. $ECHO "NetInstall boot disk build complete."
  440. $ECHO "You may remove the disk."
  441. exit 0
  442.