home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / base / root.15 / usr / lib / drf / cut_flop / cut_flop~
Text File  |  1998-08-19  |  8KB  |  330 lines

  1. #!/usr/bin/ksh
  2.  
  3. # Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  4. #                                                                         
  5. #        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  6. #                   SANTA CRUZ OPERATION INC.                             
  7. #                                                                         
  8. #   The copyright notice above does not evidence any actual or intended   
  9. #   publication of such source code.                                      
  10.  
  11. #    Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 Santa Cruz Operation, Inc. All Rights Reserved.
  12. #    Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 AT&T, Inc. All Rights Reserved.
  13. #      All Rights Reserved
  14.  
  15. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Santa Cruz Operation, Inc.
  16. #    The copyright notice above does not evidence any
  17. #    actual or intended publication of such source code.
  18.  
  19. #ident    "@(#)drf:cmd/cut_flop.sh    1.2"
  20.  
  21. # script to create boot floppy.
  22.  
  23. function ask_drive
  24. {
  25.     export BLOCKS=$(devattr $MEDIUM capacity)
  26.     case $BLOCKS in
  27.     2844) # 3.5-inch diskette
  28.         # We're cutting 2 floppies, so step down the blocks
  29.         BLOCKS=2370
  30.         TRKSIZE=36
  31.         if [ "${LANGS}" = "ja" ]
  32.         then
  33.             FIRST='FIRST '
  34.         else
  35.             FIRST=''
  36.         fi
  37.         ;;
  38.     2370) # 5.25-inch diskette
  39.         TRKSIZE=30
  40.         FIRST='FIRST '
  41.         ;;
  42.     *)
  43.         print -u2 ERROR -- diskette must be either 1.44MB 3.5 inch
  44.         print -u2 or 1.2MB 5.25 inch
  45.         exit 2
  46.         ;;
  47.     esac
  48.     FDRIVE=$(devattr $MEDIUM fmtcmd)
  49.     FDRIVE=${FDRIVE##* }
  50. }
  51.  
  52. function stripem
  53. {
  54.     typeset i save_pwd=$PWD
  55.  
  56.     [ -d $2 ] || mkdir -p $2
  57.     cd $1
  58.     for i in *
  59.     do
  60.         rmwhite $i $2/$i
  61.     done
  62.     cd $save_pwd
  63. }
  64.  
  65. function strip_comments
  66. {
  67.     . $PROTO/bin/rmwhite
  68.     [ -d $PROTO/stage/winxksh ] || mkdir $PROTO/stage/winxksh
  69.     rmwhite /usr/lib/winxksh/scr_init $PROTO/stage/winxksh/scr_init
  70.  
  71.     rmwhite /usr/lib/winxksh/winrc $PROTO/stage/winxksh/winrc
  72.  
  73.     stripem /etc/dcu.d/menus   $PROTO/stage/dcu.d/menus
  74.     stripem /etc/dcu.d/scripts $PROTO/stage/dcu.d/scripts
  75. }
  76.  
  77. function prep_flop2
  78. {
  79.     (( BLOCKS == 2370 )) || [ "$LANGS" = "ja" ] || return
  80.     print "Making tree for SECOND boot floppy."
  81.     flop2root=$PROTO/stage
  82.     set -e
  83.     mkdir flop2root 2>/dev/null
  84.     cd flop2root
  85.     mkdir -p \
  86.         ../tmp \
  87.                 tmp \
  88.                 isl/ui_modules \
  89.                 isl/install_modules \
  90.         etc/conf/mod.d \
  91.         etc/dcu.d/dculib \
  92.         etc/dcu.d/locale/${LANG} \
  93.         etc/dcu.d/menus \
  94.         etc/dcu.d/scripts \
  95.         etc/inst/scripts \
  96.         etc/inst/locale/${LANG}/menus/ \
  97.         etc/inst/locale/${LANG}/menus/help \
  98.         etc/scsi \
  99.         sbin \
  100.         usr/bin \
  101.         usr/sbin \
  102.         usr/lib \
  103.         .extra.d/sbin \
  104.         .extra.d/usr/bin \
  105.         .extra.d/etc/conf/hbamod.d \
  106.         .extra.d/etc/conf/mod.d \
  107.         .extra.d/etc/conf/bin
  108.     sed \
  109.         -e '/^#/d' \
  110.         -e "s,\$ROOT,$ROOT," \
  111.         -e "s,\$MACH,$MACH," \
  112.         -e "s,\$WORK,$WORK," \
  113.         -e "s,\$LANG,$LANG," \
  114.         -e "s,\$PROTO,$PROTO," \
  115.         /usr/lib/drf/disk2.files \
  116.         > $PROTO/disk2.files
  117.  
  118.     while read srcfile destfile
  119.     do
  120.         cp $srcfile $destfile
  121.     done < $PROTO/disk2.files
  122.  
  123.     for i in $FSMODS
  124.     do
  125.         [ -d .extra.d/etc/fs/$i -o "$i" = "dow" ] || mkdir -p .extra.d/etc/fs/$i
  126.         [ -d .extra.d/etc/fs/$i ] && cp $PROTO/etc/fs/$i/* .extra.d/etc/fs/$i
  127.     done 
  128.  
  129.     set +e
  130.     LIST=$(find . -type f -print)
  131.     print $LIST | xargs chmod 555 
  132.     print $LIST | xargs chown root:sys
  133.     typeset OIFS=$IFS
  134.     IFS=
  135.     print -r $LIST | cpio -oLDV -H crc > $PROTO/out1.$$
  136.     IFS=$OIFS
  137.     cd ..
  138.     print Compressing image for SECOND boot floppy.
  139.     bzip -s32k $PROTO/out1.$$ > $PROTO/out2.$$
  140.     wrt -s $PROTO/out2.$$ > flop2.image
  141.     rm $PROTO/out?.$$
  142. }
  143.  
  144. function get_answer
  145. {
  146.     while :
  147.     do
  148.         print -n "\007\nInsert $1 floppy into $MEDIUM drive and press\n\t<ENTER> "
  149.         print -n "to write floppy,\n\tF\tto format and write floppy,\n\ts\tto "
  150.         print -n "skip, \n\td\tto change output device, or\n\tq\tto quit: "
  151.         read a
  152.         case "$a" in
  153.         "")
  154.             return 0
  155.             ;;
  156.         F)
  157.             /usr/sbin/format -i$2 $FDRIVE || exit $?
  158.             return 0
  159.             ;;
  160.         s)
  161.             return 1
  162.             ;;
  163.         d)
  164.             echo
  165.             echo -n "Enter new device to write to :"
  166.             read FDRIVE
  167.             return 0
  168.             ;;
  169.         q)
  170.             exit 0
  171.             ;;
  172.         *)
  173.             print -u2 ERROR: Invalid response -- try again.
  174.             ;;
  175.         esac
  176.     done
  177. }
  178.  
  179. function image_make1
  180. {
  181.     set -e
  182.     COMPRESS=/usr/lib/drf/bzip
  183.     ${COMPRESS} -s28k $PROTO/$LCL_MACH/stand/unix > unix
  184.     ${COMPRESS} -s28k $PROTO/$LCL_MACH/stand/memfs.meta > memfs.meta
  185.     ${COMPRESS} -s28k $PROTO/$LCL_MACH/stand/memfs.fs > memfs.fs
  186.     cp /stand/resmgr resmgr
  187. }
  188.  
  189. function cut_flop1
  190. {
  191.     image_make1
  192.     # Create kdb.rc.  By default, just exit, so boot is uninterrupted.
  193.     echo "q" > kdb.rc
  194.  
  195.     echo "Creating/writing FIRST boot floppy image..."
  196.     cmd="$MKSMALLFS -Bfdboot -x2 -Gstage2.fdinst \
  197.         dcmp.blm stage3.blm platform.blm \
  198.         boot bootmsgs help.txt kdb.rc \
  199.         unix resmgr memfs.meta memfs.fs $FDRIVE"
  200.     echo $cmd
  201.     $cmd || exit $?
  202.  
  203.     print "Done with ${FIRST}boot floppy.\007"
  204. }
  205.  
  206. #
  207. #  Floppy two is a little unusual. The first track is a small cpio archive,
  208. # and the rest of the disk is a weird format. It might be cpio. It is created
  209. # by a cpio, then bzip-ed, then wrt is used. Mayby it puts a cpio header
  210. # back on the archive? The first archive is a disk label, the second is the
  211. # files that didn't fit on boot1.
  212. #  Anyway, the device /dev/dsk/f0 does not include the first track. The
  213. # device /dev/dsk/f0t does include the first track. This function used to
  214. # write to both. Now it creates an image of the disk, and does one write.
  215. # This lets us cut floppies over the network.
  216. #
  217. function cut_flop2
  218. {
  219.     integer count
  220.     (( BLOCKS == 2370 )) || [ "$LANGS" = "ja" ] || return
  221.     get_answer "SECOND boot" 2 || return
  222.     set -- $(ls -l flop2.image)
  223.     (( count = $5 / 512 ))
  224.     echo "Creating SECOND boot floppy image..."
  225.     #
  226.     # Create one track's worth of zeros
  227.     #
  228.     rm -rf $PROTO/tmp/zeros.$$ $PROTO/tmp/cpio.$$ $PROTO/tmp/both.$$ 
  229.     rm -rf $PROTO/tmp/track1.$$ $PROTO/tmp/disk2.$$
  230.     /usr/bin/dd if=/dev/zero of=$PROTO/tmp/zeros.$$ bs=512 count=$TRKSIZE
  231.     #
  232.     # Create the cpio header
  233.     #
  234.     rm -f $PROTO/tmp/flop.label
  235.     if [ -f $PROTO/tmp/flop.label ]
  236.     then
  237.         echo "Error: cannot remove $PROTO/tmp/flop.label"
  238.         exit 1
  239.     fi
  240.     echo  "${REL_FULLNAME} Boot Floppy 2" >$PROTO/tmp/flop.label
  241.     cdir=`pwd`
  242.     cd $PROTO
  243.     ls tmp/flop.label | cpio -oc -O $PROTO/tmp/cpio.$$ || exit $?
  244.     cd $cdir
  245.     unset cdir
  246.     chmod uog+w $PROTO/tmp/flop.label
  247.     #
  248.     # Merge them
  249.     #
  250.     cat $PROTO/tmp/cpio.$$ $PROTO/tmp/zeros.$$ > $PROTO/tmp/both.$$
  251.     #
  252.     # Extract one track's worth
  253.     #
  254.     /usr/bin/dd if=$PROTO/tmp/both.$$ of=$PROTO/tmp/track1.$$ bs=512 count=$TRKSIZE || exit $?
  255.     #
  256.     # Add on the rest of the disk
  257.     #
  258.     cat $PROTO/tmp/track1.$$ flop2.image > $PROTO/tmp/disk2.$$
  259.     #
  260.     # Dump to the disk
  261.     #
  262.     print Writing to SECOND boot floppy...
  263.     /usr/bin/dd if=$PROTO/tmp/disk2.$$ of=$FDRIVE bs=${TRKSIZE}b || exit $?
  264.     print "Wrote $count blocks to SECOND boot floppy."
  265.     print "Done with SECOND boot floppy.\007"
  266.     rm -rf $PROTO/tmp/zeros.$$ $PROTO/tmp/cpio.$$ $PROTO/tmp/both.$$ 
  267.     rm -rf $PROTO/tmp/track1.$$ $PROTO/tmp/disk2.$$
  268. }
  269.  
  270. #main()
  271.  
  272. trap "exit" 0 1 2 3 15
  273. PATH=:/usr/lib/drf:$PATH export PATH
  274. REL_FULLNAME="UnixWare7"
  275.  
  276. LOGO=logo.img
  277. #LOGO=""
  278. MKSMALLFS=/usr/lib/drf/mksmallfs
  279.  
  280. setflag=-u        #default is UnixWare set
  281. unset special_flag
  282. nflag=0
  283. quick=true
  284.  
  285. cd $PROTO
  286. ask_drive
  287.  
  288. if [ "$LANGS" != "ja" ]
  289. then
  290.     /usr/bin/egrep '^PC850.*88591.*d' \
  291.         /usr/lib/iconv/iconv_data > $PROTO/iconv_data
  292. else
  293.     /usr/bin/egrep '^sjis.*eucJP' \
  294.         /usr/lib/iconv/iconv_data > $PROTO/iconv_data
  295. fi
  296.  
  297. #
  298. # We need the mfpd drvmap file on the boot floppy, but its
  299. # verify routine is NOT available to be run from the boot
  300. # floppy.  So the user doesn't get a "failed to verify"
  301. # message, we'll indicate NO verify routine during install.
  302. #
  303.  
  304. ed -s $ROOT/.$MACH/etc/conf/drvmap.d/mfpd <<-EOF
  305. g/Y|Y/s//Y|N/
  306. w
  307. q
  308. EOF
  309.  
  310. strip_comments
  311. cd $PROTO
  312.  
  313. MEMSZ=`/sbin/memsize`
  314. sed -e "s%LANG=XXX%LANG=$LANG%" \
  315.     -e "s%LANGS=XXX%LANGS=$LANGS%" \
  316.     -e "s%LC_CTYPE=XXX%LC_CTYPE=$LANG%" \
  317.     -e "s%KEYBOARD=XXX%KEYBOARD=$KEYBOARD%" \
  318.     -e "s%KEYBOARDS=XXX%KEYBOARDS=$KEYBOARDS%" \
  319.     -e "s%VM_RUNNING=XXX%VM_RUNNING=$VM_RUNNING%" \
  320.     -e "s%MEMSZ=XXX%MEMSZ=$MEMSZ%" \
  321.     -e "s%DRF_DEBUG=XXX%DRF_DEBUG=$DRF_DEBUG%" \
  322.     -e "s%REL_FULLNAME=XXX%REL_FULLNAME=$REL_FULLNAME%" \
  323.     /usr/lib/drf/drf_inst.gen > $PROTO/drf_inst
  324.  
  325. conframdfs $special_flag $setflag -l $LANG || exit $?
  326. prep_flop2
  327. cd $PROTO
  328. cut_flop1
  329. cut_flop2
  330.