home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / riscbsd / 1_1_beta / upgrades / inst_gz / inst_gz~
Encoding:
Text File  |  1996-07-04  |  19.7 KB  |  951 lines

  1. #!/bin/sh
  2. # Copyright (c) 1995-1996 Mark Brinicombe
  3. # All rights reserved.
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. # 1. Redistributions of source code must retain the above copyright
  8. #    notice, this list of conditions and the following disclaimer.
  9. # 2. Redistributions in binary form must reproduce the above copyright
  10. #    notice, this list of conditions and the following disclaimer in the
  11. #    documentation and/or other materials provided with the distribution.
  12. # 3. All advertising materials mentioning features or use of this software
  13. #    must display the following acknowledgement:
  14. #    This product includes software developed by Mark Brinicombe.
  15. # 4. The name of the author may not be used to endorse or promote products
  16. #    derived from this software without specific prior written permission
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. #
  29. #    $Id: inst,v 1.9 1996/04/18 20:56:14 mark Exp $
  30. #
  31.  
  32. #
  33. # Installation utilites (functions), to get NetBSD installed on
  34. # the hard disk.  These are meant to be invoked from the shell prompt,
  35. # by people installing NetBSD.
  36. #
  37.  
  38. VERSION=`echo '$Revision: 1.9 $' | cut '-d ' -f2`
  39.  
  40. Load_tape()
  41. {
  42.     Tmp_dir
  43.     echo -n    "Which tape drive will you be using? [rst0] "
  44.     read which
  45.     if [ "X$which" = "X" ]; then
  46.         which=rst0
  47.     fi
  48.     echo -n "Insert the tape into the tape drive and hit return to "
  49.     echo -n "continue..."
  50.     read foo
  51.     echo    "Extracting files from the tape..."
  52.     $TAR xvpf --unlink /dev/$which
  53.     echo    "Done."
  54. }
  55.  
  56.  
  57. Get_Dest_Dir()
  58. {
  59.     echo -n "Enter new path to dest directory [$dest_dir] "
  60.     read newdir
  61.     if [ ! "X$newdir" = "X" ]; then
  62.         dest_dir=$newdir
  63.     fi
  64. }
  65.  
  66.  
  67. Get_Distrib_Dir()
  68. {
  69.     echo -n "Enter new path to distrib directory [$distribdir] "
  70.     read distribdir
  71.     if [ "X$distribdir" = "X" ]; then
  72.         distribdir=$destdir/usr/distrib
  73.     fi
  74.     if [ ! -d $distribdir ]; then
  75.         echo -n "$distribdir does not exist, create it [n] "
  76.         read yorn
  77.         if [ "$yorn" = "y" ]; then
  78.             mkdir $distribdir
  79.         fi
  80.     fi
  81. }
  82.  
  83.  
  84. Set_Distrib_Dir()
  85. {
  86.     while [ ! -d $distribdir ]; do
  87.         echo "Directory $distribdir does not exist"
  88.         Get_Distrib_Dir
  89.     done
  90.  
  91.     cd $distribdir
  92. }
  93.  
  94.  
  95. Load_Msdos_Fd()
  96. {
  97.     echo "Loading sets from msdos floppies"
  98.     Set_Distrib_Dir
  99.  
  100.     which=
  101.     while [ "$which" != "0" -a "$which" != "1" ]; do
  102.         echo -n    "Read from which floppy drive ('0' or '1')? [0] "
  103.         read which
  104.         if [ "X$which" = "X" ]; then
  105.             which=0
  106.         fi
  107.     done
  108.  
  109.     foo=
  110.     while [ "X$foo" = "X" ]; do
  111.                echo -n "Insert floppy (type s to stop, enter to load): "
  112.         read foo
  113.         if [ "X$foo" = "X" ]; then
  114.             mount -t msdos /dev/fd${which}a /mnt2
  115.             cp -rp /mnt2/* .
  116.             umount /mnt2
  117.         fi
  118.     done    
  119. }
  120.  
  121.  
  122. Load_Tar_Fd()
  123. {
  124.     echo "Loading sets from tar floppies"
  125.     Set_Distrib_Dir
  126.  
  127.     which=
  128.     while [ "$which" != "0" -a "$which" != "1" ]; do
  129.         echo -n    "Read from which floppy drive ('0' or '1')? [0] "
  130.         read which
  131.         if [ "X$which" = "X" ]; then
  132.             which=0
  133.         fi
  134.     done
  135.  
  136.     foo=
  137.     while [ "X$foo" = "X" ]; do
  138.                echo -n "Insert floppy (type s to stop, enter to load): "
  139.         read foo
  140.         if [ "X$foo" = "X" ]; then
  141.             tar xf /dev/fd${which}a
  142.         fi
  143.     done    
  144. }
  145.  
  146.  
  147. Load_Tar_Fd1()
  148. {
  149.     echo "Loading sets from multi-volume tar floppies"
  150.     Set_Distrib_Dir
  151.  
  152.     which=
  153.     while [ "$which" != "0" -a "$which" != "1" ]; do
  154.         echo -n    "Read from which floppy drive ('0' or '1')? [0] "
  155.         read which
  156.         if [ "X$which" = "X" ]; then
  157.             which=0
  158.         fi
  159.     done
  160.  
  161.     foo=
  162.     while [ "X$foo" = "X" ]; do
  163.                echo -n "Insert floppy (type s to stop, enter to load): "
  164.         read foo
  165.         if [ "X$foo" = "X" ]; then
  166.             tar xfM /dev/fd${which}a
  167.         fi
  168.     done    
  169. }
  170.  
  171.  
  172. Load_Sets()
  173. {
  174.     res0=
  175.     while [ "$res0" != "q" -a "$res0" != "Q" ]; do
  176.         echo ""
  177.         echo -n "1. Set distrib directory (Currently $distribdir"
  178.         if [ ! -d $distribdir ]; then
  179.             echo " - non-existant)"
  180.         else
  181.             echo ")"
  182.         fi
  183.         echo "2. Load sets from msdos floppies"
  184.         echo "3. Load sets from tar floppies"
  185.         echo "4. Load sets from multi-volume tar floppies"
  186.         echo "Q. Return to previous menu"
  187.         echo ""
  188.         echo -n "Choice : "
  189.         read res0
  190.         case "$res0" in
  191.         1)
  192.             Get_Distrib_Dir
  193.             ;;
  194.         2)
  195.             Load_Msdos_Fd
  196.             ;;
  197.         3)
  198.             Load_Tar_Fd
  199.             ;;
  200.         4)
  201.             Load_Tar_Fd1
  202.             ;;
  203.         q|Q)
  204. #            echo "Returning to previous menu"
  205.             ;;
  206.         esac
  207.     done
  208. }
  209.  
  210.  
  211. Mount_SCSI_CDROM()
  212. {
  213.     which=
  214.     while [ "$which" != "0" -a "$which" != "1" ]; do
  215.         echo -n    "Mount which CDROM drive ('0' or '1')? [0] "
  216.         read which
  217.         if [ "X$which" = "X" ]; then
  218.             which=0
  219.         fi
  220.     done
  221.  
  222.     mount -r -t cd9660 /dev/cd${which}a /cdrom
  223.     if [ ! $? = 0 ]; then
  224.         echo "Mount failed"
  225.     else
  226.         distribdir="/cdrom/usr/distrib"
  227.     fi
  228.     
  229. }
  230.  
  231.  
  232. Mount_SCSI_Disc()
  233. {
  234.     echo -n    "Mount which SCSI device as CDROM ? [sd0a] "
  235.     read which
  236.  
  237.     mount -r -t cd9660 /dev/${which} /cdrom
  238.     if [ ! $? = 0 ]; then
  239.         echo "Mount failed"
  240.     else
  241.         distribdir="/cdrom/usr/distrib"
  242.     fi
  243.     
  244. }
  245.  
  246.  
  247. Mount_ATAPI_CDROM()
  248. {
  249.     mount -r -t cd9660 /dev/wcd0a /cdrom
  250.     if [ ! $? = 0 ]; then
  251.         mount -r -t cd9660 /dev/wcd0a /cdrom
  252.         if [ ! $? = 0 ]; then
  253.             echo "Mount failed"
  254.         else
  255.             distribdir="/cdrom/usr/distrib"
  256.         fi
  257.     else
  258.         distribdir="/cdrom/usr/distrib"
  259.     fi
  260.     
  261. }
  262.  
  263.  
  264. CDROM_Sets() {
  265.     res0=
  266.     while [ "$res0" != "q" -a "$res0" != "Q" ]; do
  267.         echo ""
  268.         echo -n "1. Set distrib directory (Currently $distribdir"
  269.         if [ ! -d $distribdir ]; then
  270.             echo " - non-existant)"
  271.         else
  272.             echo ")"
  273.         fi
  274.         echo -n "2. Mount SCSI CDROM "
  275.         if [ ! -b /dev/cd0a ]; then
  276.             echo "- Not available"
  277.         else
  278.             echo ""
  279.         fi
  280.         echo -n "3. Mount ATAPI CDROM "
  281.         if [ ! -b /dev/wcd0a ]; then
  282.             echo "- Not available"
  283.         else
  284.             echo ""
  285.         fi
  286.         if [ -f /var/inst/developer ]; then
  287.             echo "D. Mount SCSI disc as CDROM"
  288.         fi
  289.         echo "Q. Return to previous menu"
  290.         echo ""
  291.         echo -n "Choice : "
  292.         read res0
  293.         case "$res0" in
  294.         1)
  295.             Get_Distrib_Dir
  296.             ;;
  297.         2)
  298.             Mount_SCSI_CDROM
  299.             ;;
  300.         3)
  301.             Mount_ATAPI_CDROM
  302.             ;;
  303.         d|D)
  304.             Mount_SCSI_Disc
  305.             ;;
  306.         q|Q)
  307.             ;;
  308.         esac
  309.     done
  310. }
  311.  
  312.  
  313. Show_Sets()
  314. {
  315.     Set_Distrib_Dir
  316.     sets=`ls *.[sS][eE][tT] 2>/dev/null | sed -e 's/.[sS][eE][tT]//'`
  317.  
  318.     echo "Loaded sets in $distribdir :"
  319.     for set in $sets; do
  320.         cat "$set".set 2>/dev/null | grep 'desc:' | cut -f2-
  321.         cat "$set".SET 2>/dev/null | grep 'desc:' | cut -f2-
  322.     done
  323. }
  324.  
  325.  
  326. Show_Installed_Sets()
  327. {
  328.     INSTALLDIR=$dest_dir/var/inst/installed
  329.     cd $INSTALLDIR
  330.     if [ ! $? = 0 ]; then
  331.         return
  332.     fi
  333.     sets=`ls *.[sS][eE][tT] 2>/dev/null | sed -e 's/.[sS][eE][tT]//'`
  334.  
  335.     echo "Installed sets:"
  336.     for set in $sets; do
  337.         cat "$set".set 2>/dev/null | grep 'desc:' | cut -f2-
  338.         cat "$set".SET 2>/dev/null | grep 'desc:' | cut -f2-
  339.     done
  340. }
  341.  
  342.  
  343. Validate_Sets()
  344. {
  345.     Set_Distrib_Dir
  346.     sets=`ls *.[sS][eE][tT] 2>/dev/null | sed -e 's/.[sS][eE][tT]//'`
  347.     list=""
  348.  
  349.     echo "Loaded sets in $distribdir :"
  350.     for set in $sets; do
  351.         printf "$set\t"
  352.         list="$list $set"
  353.     done
  354.     echo ""
  355.  
  356.     echo -n "Enter set names or 'all' for all sets : "
  357.     read res2
  358.     res2=`echo "$res2" | tr "," " " | tr "[A-Z]" "[a-z]"`
  359.     if [ "$res2" = "all" ]; then
  360.         res2="$list"
  361.     fi
  362.     sets="$res2"
  363.  
  364.     echo "Validating in $distribdir :"
  365.     fail=""
  366.     for set in $sets; do
  367.         setname="set"
  368.         if [ ! -f "$set"."$setname" ]; then
  369.             setname="SET"
  370.             set=`echo $set | tr [a-z] [A-Z]`
  371.         fi
  372.         p1=`cat $set.$setname 2>/dev/null | grep 'parts:' | cut -f2`
  373.         if [ "$p1" = "" ]; then
  374.             continue
  375.         fi
  376.         p2=`ls "$set".[0-9a-z][0-9a-z] 2>/dev/null | wc | awk '{print $1}'`
  377.         printf "$set\t:"
  378. #        echo "$p1 , $p2"
  379.         if [ ! "$p1" = "$p2" ]; then
  380.             echo -n " Failed parts check (need $p1, got $p2)"
  381.         else
  382.             echo -n " Passed parts check"
  383.         fi
  384.         loop=0
  385.         while [ $loop -lt $p1 ]; do
  386.             if [ $loop -lt 10 ]; then
  387.                 file="0$loop"
  388.             else
  389.                 file=$loop
  390.             fi
  391.             echo -n " [$file]"
  392.             cksum=`cat $set.$setname | grep "cksum.$file:" | cut -f2`
  393.             cksum1=`cat "$set".$file 2>&1 | cksum | cut "-d " -f1`
  394.             #echo "#$cksum, $cksum1#"
  395.             if [ ! "$cksum" = "$cksum1" ]; then
  396.                 echo -n " part $file failed checksum"
  397.                 fail="yes"
  398.             fi
  399.             loop=$(($loop+1))
  400.         done
  401.         if [ "$fail" = "" ]; then
  402.             echo " Passed checksum"
  403.         else
  404.             echo ""
  405.         fi
  406.     done
  407. }
  408.  
  409.  
  410. Verify_Sets()
  411. {
  412.     Set_Distrib_Dir
  413.     sets=`ls *.[sS][eE][tT] 2>/dev/null | sed -e 's/.[sS][eE][tT]//'`
  414.     list=""
  415.  
  416.     echo "Loaded sets in $distribdir :"
  417.     for set in $sets; do
  418.         printf "$set\t"
  419.         list="$list $set"
  420.     done
  421.     echo ""
  422.  
  423.     echo -n "Enter set names or 'all' for all sets : "
  424.     read res2
  425.     res2=`echo "$res2" | tr "," " " | tr "[A-Z]" "[a-z]"`
  426.     if [ "$res2" = "all" ]; then
  427.         res2="$list"
  428.     fi
  429.     sets="$res2"
  430.  
  431.     echo "Verifing sets in $distribdir :"
  432.     for set in $sets; do
  433.         setname="set"
  434.         if [ ! -f "$set"."$setname" ]; then
  435.             setname="SET"
  436.             set=`echo $set | tr [a-z] [A-Z]`
  437.         fi
  438.         printf "$set\t:"
  439.         cat "$set".[0-9a-z][0-9a-z] 2>/dev/null | $GUNZIP -t 2>/dev/null 1>/dev/null
  440.         if [ ! $? = 0 ]; then
  441.             echo " Failed archive integrity"
  442.         else
  443.             echo " Passed"
  444.         fi
  445.     done
  446. }
  447.  
  448.  
  449. Verify_Checksums()
  450. {
  451.     echo -n "Enter name of checksums file : "
  452.     read checkfile
  453.     if [ "X$checkfile" = "X" ]; then
  454.         return
  455.     fi
  456.  
  457.     Set_Distrib_Dir
  458.     sets=`ls *.[sS][eE][tT] 2>/dev/null | sed -e 's/.[sS][eE][tT]//'`
  459.     list=""
  460.  
  461.     echo "Available sets in $distribdir :"
  462.     for set in $sets; do
  463.         printf "$set\t"
  464.         list="$list $set"
  465.     done
  466.     echo ""
  467.  
  468.     echo -n "Enter set names or 'all' for all sets : "
  469.     read res2
  470.     res2=`echo "$res2" | tr "," " " | tr "[A-Z]" "[a-z]"`
  471.     if [ "$res2" = "all" ]; then
  472.         res2="$list"
  473.     fi
  474.     sets="$res2"
  475.  
  476.     TMPFILE1="/tmp/inst.cksum1"
  477.     TMPFILE2="/tmp/inst.cksum2"
  478.  
  479.     echo "Verifing checksums for sets in $distribdir :"
  480.     for set in $sets; do
  481.         setname="set"
  482.         if [ ! -f "$set"."$setname" ]; then
  483.             setname="SET"
  484.             set=`echo $set | tr [a-z] [A-Z]`
  485.         fi
  486.         printf "$set\t:"
  487.         grep cksum $set.$setname >$TMPFILE1
  488.         egrep -i "`echo ^$set.$setname | sed -e 's/\+/\\\\+/g'`" $checkfile | cut '-d:' -f2- >$TMPFILE2
  489.         cmp -s $TMPFILE1 $TMPFILE2
  490.         if [ $? = 0 ]; then
  491.             echo "checksums ok"
  492.         else
  493.             echo "checksum error"
  494.         fi
  495.     done
  496.     rm -f $TMPFILE1
  497.     rm -f $TMPFILE2
  498. }
  499.  
  500.  
  501. Check_Sets() {
  502.     res0=
  503.     while [ "$res0" != "q" -a "$res0" != "Q" ]; do
  504.         echo ""
  505.         echo "1. Validate distribution sets (confirm checksums)"
  506.         echo "2. Verify distribution sets (integrity check)"
  507.         echo "3. Verify checksums (confirm set checksums)"
  508.         echo "Q. Return to previous menu"
  509.         echo ""
  510.         echo -n "Choice : "
  511.         read res0
  512.         case "$res0" in
  513.         1)
  514.             Validate_Sets
  515.             ;;
  516.         2)
  517.             Verify_Sets
  518.             ;;
  519.         3)
  520.             Verify_Checksums
  521.             ;;
  522.         q|Q)
  523.             ;;
  524.         esac
  525.     done
  526. }
  527.  
  528.  
  529.  
  530.  
  531. List_Sets()
  532. {
  533.     Set_Distrib_Dir
  534.     sets=`ls *.[sS][eE][tT] 2>/dev/null | sed -e 's/.[sS][eE][tT]//'`
  535.     list=""
  536.  
  537.     echo "Loaded sets in $distribdir :"
  538.     for set in $sets; do
  539.         printf "$set\t"
  540.         list="$list $set"
  541.     done
  542.     echo ""
  543.  
  544.     echo -n "Enter set names or 'all' for all sets : "
  545.     read res2
  546.     res2=`echo "$res2" | tr "," " " | tr "[A-Z]" "[a-z]"`
  547.     if [ "$res2" = "all" ]; then
  548.         res2="$list"
  549.     fi
  550.     sets="$res2"
  551.  
  552.     echo "Listing contents of sets in $distribdir :"
  553.     for set in $sets; do
  554.         setname="set"
  555.         if [ ! -f "$set"."$setname" ]; then
  556.             setname="SET"
  557.             set=`echo $set | tr [a-z] [A-Z]`
  558.         fi
  559.         echo "$set:"
  560.         cat "$set".[0-9a-z][0-9a-z] | $GUNZIP | $TAR -tpvf -
  561.     done
  562. }
  563.  
  564.  
  565. Install_Sets()
  566. {
  567. # Make sure all the directories exist for recording the installation
  568.  
  569.     INSTALLDIR=$dest_dir/var/inst
  570.     if [ ! -d $dest_dir/var ]; then
  571.         echo "Creating $dest_dir/var"
  572.         mkdir $dest_dir/var
  573.     fi
  574.     if [ ! -d $INSTALLDIR ]; then
  575.         echo "Creating $INSTALLDIR"
  576.         mkdir $INSTALLDIR
  577.     fi
  578.     if [ ! -d $INSTALLDIR/installed ]; then
  579.         echo "Creating $INSTALLDIR/installed"
  580.         mkdir $INSTALLDIR/installed
  581.     fi
  582.     if [ ! -d $INSTALLDIR/sets ]; then
  583.         echo "Creating $INSTALLDIR/sets"
  584.         mkdir $INSTALLDIR/sets
  585.     fi
  586.  
  587.     if [ ! -d $dest_dir/tmp ]; then
  588.         echo "Creating $dest_dir/tmp"
  589.         mkdir $dest_dir/tmp
  590.         chmod 1777 $dest_dir/tmp
  591.     fi
  592.  
  593. # Set the distribution directory and list all the available sets
  594.  
  595.     Set_Distrib_Dir
  596.     sets=`ls *.[sS][eE][tT] 2>/dev/null | sed -e 's/.[sS][eE][tT]//'`
  597.     list=""
  598.  
  599.     echo "Loaded sets in $distribdir :"
  600.     for set in $sets; do
  601.         printf "$set\t"
  602.         list="$list $set"
  603.     done
  604.     echo ""
  605.  
  606. # Prompt for the sets to install
  607.  
  608.     echo -n "Enter set names or 'all' for all sets : "
  609.     read res2
  610.     res2=`echo "$res2" | tr "," " " | tr "[A-Z]" "[a-z]"`
  611.  
  612. # Check for any of the special sets
  613.  
  614.     if [ "$res2" = "all" ]; then
  615.         res2="$list"
  616.     fi
  617.  
  618.     if [ "$res2" = "req" ]; then
  619.         res2="base etc misc text kern"
  620.     fi
  621.  
  622.     if [ "$res2" = "std" ]; then
  623.         res2="base etc misc text local man kern"
  624.     fi
  625.  
  626. # Hack to make sure the base set is the first installed
  627.  
  628.     echo "$res2" | grep base 2>/dev/null >/dev/null
  629.     if [ $? = 0 ]; then
  630.         res2="base "`echo "$res2" | sed 's/base//'`
  631.     fi
  632.  
  633.     echo "$res2" | grep BASE 2>/dev/null >/dev/null
  634.     if [ $? = 0 ]; then
  635.         res2="BASE "`echo "$res2" | sed 's/BASE//'`
  636.     fi
  637.  
  638.     echo -n "Would you like to list the files as they're extracted? [n] "
  639.     read verbose
  640.     case $verbose in
  641.     y*|Y*)
  642.         tarverbose=v
  643.         ;;
  644.     *)
  645.         tarverbose=
  646.         ;;
  647.     esac
  648.  
  649.     for set in $res2; do
  650.         setname="set"
  651.         if [ ! -f "$set"."$setname" ]; then
  652.             setname="SET"
  653.             set=`echo $set | tr [a-z] [A-Z]`
  654.         fi
  655.  
  656. # Test for conflicts
  657.  
  658.         ok=""
  659.         for file in `ls $INSTALLDIR/installed/*.[sS][eE][tT] 2>/dev/null`; do
  660.             conflict="`grep conflict: $file | cut -d: -f2- 2>/dev/null`"
  661.             echo $conflict | egrep -i "(^|[[:space:]])$set([[:space:]]|$)" 2>/dev/null > /dev/null
  662.             if [ $? = 0 ]; then
  663.                 echo "Set $set conflicts with installed set `basename $file`"
  664.                 ok="no"
  665.                 break
  666.             fi
  667.         done
  668.  
  669.         if [ ! "$ok" = "" ]; then
  670.             continue
  671.         fi
  672.  
  673.         conflicts="`grep conflict: $set.$setname | cut -d: -f2-`"
  674.         installed="`(cd $INSTALLDIR/installed ; ls *.[sS][eE][tT]) 2>/dev/null`"
  675.  
  676.         for conflict in $conflicts ; do
  677.             echo $installed | egrep -i "(^|[[:space:]])$conflict.set([[:space:]]|$)" 2>/dev/null > /dev/null
  678.             if [ $? = 0 ]; then
  679.                 echo "Set $set conflicts with installed set $conflict"
  680.                 ok="no"
  681.                 break;
  682.             fi
  683.         done
  684.  
  685.         if [ ! "$ok" = "" ]; then
  686.             continue
  687.         fi
  688.  
  689.         dependancies="`grep depend: $set.$setname | cut -d: -f2-`"
  690.         installed="`(cd $INSTALLDIR/installed ; ls *.[sS][eE][tT]) 2>/dev/null`"
  691.  
  692.         for depend in $dependancies ; do
  693.             echo $installed | egrep -i "(^|[[:space:]])$depend\.set([[:space:]]|$)" 2> /dev/null >/dev/null
  694.             if [ ! $? = 0 ]; then
  695.                 echo "Set $depend must be installed before $set"
  696.                 ok="no"
  697.                 break;
  698.             fi
  699.         done
  700.  
  701.         if [ ! "$ok" = "" ]; then
  702.             continue
  703.         fi
  704.  
  705.         if [ -f "$set".00 ]; then
  706.             if [ -x "$INSTALLDIR/scripts/$set" ]; then
  707.                 echo "Running deinstallation script for $set"
  708.                 (cd $dest_dir ; INSTALLROOT=$dest_dir; export INSTALLROOT ; $INSTALLDIR/scripts/$set deinstall)
  709.             fi
  710.  
  711.             filelist="$dest_dir/tmp/$set.files"
  712.             echo "Installing $set"
  713.             case $verbose in
  714.             y*|Y*)
  715.                 cat "$set".[0-9a-z][0-9a-z] | $GUNZIP | (cd $dest_dir ; $TAR  --unlink -xpvf - | tee $filelist)
  716.                 ;;
  717.             *)
  718.                 cat "$set".[0-9a-z][0-9a-z] | $GUNZIP | (cd $dest_dir ; $TAR  --unlink -xpvf - >$filelist)
  719.                 ;;
  720.             esac
  721.             echo "Generating installation information"
  722.             cat $filelist | awk '{ print $0 }' > $INSTALLDIR/installed/$set.files
  723. #            cat $filelist | awk '{ print $3 $8 }' > $INSTALLDIR/installed/$set.files
  724.             rm $filelist
  725.             cp $set.$setname $INSTALLDIR/installed/
  726.  
  727. # Run any install script
  728.  
  729.             if [ -x "$INSTALLDIR/scripts/$set" ]; then
  730.                 echo "Running installation script for $set"
  731.                 (cd $dest_dir ; INSTALLROOT=$dest_dir; export INSTALLROOT ; $INSTALLDIR/scripts/$set install)
  732.             fi
  733.         else
  734.             echo "Set $set not available for installation"
  735.         fi
  736.         sync
  737.     done
  738.  
  739. # Test for other set requirements
  740.  
  741.     echo "Checking installed set requirements"
  742.  
  743.     installed="`(cd $INSTALLDIR/installed ; ls *.[sS][eE][tT]) 2>/dev/null`"
  744.  
  745.     for set in $installed; do
  746.         required="`grep req: $INSTALLDIR/installed/$set | cut -d: -f2- 2>/dev/null`"
  747.         for require in $required; do
  748.             echo $installed | egrep -i "(^|[[:space:]])$require.set([[:space:]]|$)" 2>/dev/null > /dev/null
  749.             if [ ! $? = 0 ]; then
  750.                 echo "Set $set requires set $require"
  751. #                break
  752.             fi
  753.         done
  754.     done
  755. }
  756.  
  757.  
  758. Deinstall_Sets()
  759. {
  760. # Make sure all the directories exist for recording the installation
  761.  
  762.     INSTALLDIR=$dest_dir/var/inst
  763.  
  764. # Set the distribution directory and list all the available sets
  765.  
  766.     cd $INSTALLDIR/installed
  767.     sets=`ls *.[sS][eE][tT] 2>/dev/null | sed -e 's/.[sS][eE][tT]//'`
  768.     list=""
  769.  
  770.     echo "Installed sets :"
  771.     for set in $sets; do
  772.         printf "$set\t"
  773.         list="$list $set"
  774.     done
  775.     echo ""
  776.  
  777. # Prompt for the sets to deinstall
  778.  
  779.     echo -n "Enter set names : "
  780.     read res2
  781.     res2=`echo "$res2" | tr "," " " | tr "[A-Z]" "[a-z]"`
  782.  
  783.     echo -n "Would you like to list the files as they're removed? [n] "
  784.     read verbose
  785.  
  786.     for set in $res2; do
  787.         setname="set"
  788.         if [ ! -f "$set"."$setname" ]; then
  789.             setname="SET"
  790.             set=`echo $set | tr [a-z] [A-Z]`
  791.         fi
  792.  
  793.         if [ -f "$set".set ]; then
  794. # Test for dependancies
  795.  
  796.             ok=""
  797.             for file in `ls $INSTALLDIR/installed/*.[sS][eE][tT] 2>/dev/null`; do
  798.                 depend="`grep depend: $file 2>/dev/null`"
  799.                 echo $depend | egrep -i "(^|[[:space:]])$set([[:space:]]|$)" 2>/dev/null > /dev/null
  800.                 if [ $? = 0 ]; then
  801.                     echo "Installed set $file depends on set $set"
  802.                     ok="no"
  803.                     break
  804.                 fi
  805.             done
  806.  
  807.             if [ ! "$ok" = "" ]; then
  808.                 continue
  809.             fi
  810.  
  811.             echo "Deinstalling $set"
  812.             if [ -x "$INSTALLDIR/scripts/$set" ]; then
  813.                 echo "Running deinstallation script for $set"
  814.                 (cd $dest_dir ; INSTALLROOT=$dest_dir; export INSTALLROOT ; $INSTALLDIR/scripts/$set deinstall)
  815.             fi
  816.             case $verbose in
  817.             y*|Y*)
  818.                 for file in `cat $set.files`; do
  819.                     echo $file
  820.                     (cd $dest_dir ; rm $file) 2>/dev/null >/dev/null
  821.                 done
  822.                 ;;
  823.             *)
  824.                 cat "$set.files" | (cd $dest_dir ; xargs rm 2>/dev/null >/dev/null )
  825.                 ;;
  826.             esac
  827.             rm "$set.files"
  828.             rm "$set.set"
  829.         else
  830.             echo "Set $set not available for deinstallation"
  831.         fi
  832.         sync
  833.     done
  834.  
  835. # Test for other set requirements
  836.  
  837.     echo "Checking installed set requirements"
  838.  
  839.     installed="`(cd $INSTALLDIR/installed ; ls *.[sS][eE][tT]) 2>/dev/null`"
  840.  
  841.     for set in $installed; do
  842.         required="`grep req: $INSTALLDIR/installed/$set | cut -d: -f2- 2>/dev/null`"
  843.         for require in $required; do
  844.             echo $installed | egrep -i "(^|[[:space:]])$require.set([[:space:]]|$)" 2>/dev/null > /dev/null
  845.             if [ ! $? = 0 ]; then
  846.                 echo "Set $set requires set $require"
  847. #                break
  848.             fi
  849.         done
  850.     done
  851. }
  852.  
  853.  
  854. Select_Sets()
  855. {
  856. }
  857.  
  858.  
  859. Main_Menu()
  860. {
  861.     res1=
  862.     while [ "$res1" != "q" -a "$res1" != "Q" ]; do
  863.         echo ""
  864.         echo "RiscBSD (NetBSD/arm32) Installer V$VERSION"
  865.         echo ""
  866.         echo -n "1. Set distrib directory (Currently $distribdir"
  867.         if [ ! -d $distribdir ]; then
  868.             echo " - non-existant)"
  869.         else
  870.             echo ")"
  871.         fi
  872.         echo "2. Load distribution sets onto harddisc"
  873.         echo "3. Load distribution sets from CDROM"
  874.         echo "4. Show distribution sets"
  875.         echo "5. Show installed sets"
  876.         echo "6. Check sets (verify/validate)"
  877.         echo "7. List contents of distribution sets in $distribdir"
  878.         echo "8. Install distribution sets from $distribdir"
  879.         echo "D. Deinstall installed sets"
  880.         echo "R. Set root directory for install (Currently $dest_dir)"
  881.         echo "Q. Quit"
  882.         echo ""
  883.         echo -n "Choice : "
  884.         read res1
  885.         case "$res1" in
  886.         1)
  887.             Get_Distrib_Dir
  888.             ;;
  889.         2)
  890.             Load_Sets
  891.             ;;
  892.         3)
  893.             CDROM_Sets
  894.             ;;
  895.         4)
  896.             Show_Sets
  897.             ;;
  898.         5)
  899.             Show_Installed_Sets
  900.             ;;
  901.         6)
  902.             Check_Sets
  903.             ;;
  904.         7)
  905.             List_Sets
  906.             ;;
  907.         8)
  908.             Install_Sets
  909.             ;;
  910.         d|D)
  911.             Deinstall_Sets
  912.             ;;
  913.         r|R)
  914.             Get_Dest_Dir
  915.             ;;
  916.         q|Q)
  917. #            echo "Quitting"
  918.             ;;
  919.         esac
  920.     done
  921. }
  922.  
  923.  
  924. # we know that /etc/fstab is only generated on the hard drive
  925. destdir=
  926. dest_dir=/
  927. if [ ! -f /etc/fstab ]; then
  928.     dest_dir=/mnt/
  929. fi
  930. if [ -f /etc/cdrom ]; then
  931.     dest_dir=/mnt/
  932. fi
  933.  
  934. # counter for possible shared library confusion
  935. TAR=/usr/bin/tar
  936. GUNZIP=/usr/bin/gunzip
  937.  
  938. distribdir=$destdir/usr/distrib
  939.  
  940. IAM=`whoami`
  941.  
  942. if [ ! "$IAM" = "root" ]; then
  943.     echo "inst should be run as root"
  944.     exit
  945. fi
  946.  
  947. Main_Menu
  948.  
  949. exit
  950.