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