home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / sls / old / a1.5 / bin / sysinstall < prev    next >
Encoding:
Text File  |  1993-06-25  |  8.4 KB  |  329 lines

  1. #!/bin/sh
  2. # sysinstall is a front-end to tar/compress that allows packages (tar archives,
  3. # optionally compressed)  to be installed, removed, or files to be extracted 
  4. # into packages from disk.  It also will execute the script /install/doinst.sh
  5. # if found in the package, with one of the following args: -install (install 
  6. # files), -remove (uninstall package), -extract (move files to locations in
  7. # preparation for extraction), and -retract (move files back after
  8. # an extract has been done).  
  9. #
  10. # requires:  tar, sed, basename, compress/zcat/gzip, mv, mount and umount.
  11. # copywrite Softlanding Software, 1992:  Distribute and use freely, don't restrict.
  12.  
  13. function PrintUsage() {
  14.     echo "usage: sysinstall -all                * install most: base + X11"
  15.     echo "       sysinstall -base               * install full base: no X11"
  16.     echo "       sysinstall -mini               * install a minimal base: ~10 Meg"
  17.     echo "       sysinstall -everything         * install everything"
  18.     echo "       sysinstall -rest               * install the rest of the base"
  19.     echo "       sysinstall -X11                * install just X11"
  20.     echo "       sysinstall -special C          * install the C set of disks"
  21.     echo "       sysinstall -install pkg.taz    * install a specific pkg file"
  22.     echo "       sysinstall -install pkg.tpz    * install a specific pkg file"
  23.     echo "       sysinstall -install pkg.tar    * same as above, but compressed pkg"
  24.     echo "       sysinstall -remove pkg         * uninstall a pkg"
  25.     echo "       sysinstall -extract pkg        * collect pkg files into new pkg.tpz"
  26.     echo "       sysinstall -extracttar pkg     * same as above, but into pkg.tar if smaller"
  27.     echo "       sysinstall -disk               * install all pkgs on a disk"
  28.     echo "       sysinstall -disk DISKNAME      * install pkgs on disk DISKNAME"
  29.     echo "       sysinstall -mount              * mount floppy"
  30.     echo "       sysinstall -unmount            * unmount floppy"
  31.     echo "       sysinstall -instdev INSTDEV    * device to install from"
  32.     echo "       sysinstall -instroot INSTROOT  * directory to use as root"
  33.     echo "       sysinstall -instsrc  INSTSRC   * use directory INSTSRC instead of floppy"
  34.     echo "       sysinstall -doprompt           * prompt user before installing each package"
  35.     echo "       sysinstall -compress           * use the old compress program, not gzip"
  36. }
  37.  
  38. umask 0
  39. INSTROOT=/
  40. INSTDEV=/dev/fd0
  41. INSTSRC=""
  42. DOPROMPT="false"
  43. COMPR=gzip
  44. ZEXT=tgz
  45.  
  46. while [ 0 ]; do
  47.     if [ $# -gt 1 -a "$1" = "-instdev" ]; then
  48.         INSTDEV=$2;
  49.         shift 2;
  50.         continue;
  51.     elif [ $# -gt 1 -a "$1" = "-instroot" ]; then
  52.         INSTROOT=$2;
  53.         shift 2;
  54.         continue;
  55.     elif [ $# -gt 1 -a "$1" = "-doprompt" ]; then
  56.         DOPROMPT="true";
  57.         shift 1;
  58.         continue;
  59.     elif [ $# -gt 1 -a "$1" = "-instsrc" ]; then
  60.         INSTSRC=$2;
  61.         shift 2;
  62.         continue;
  63.     elif [ $# -gt 0 -a "$1" = "-compress" ]; then
  64.         COMPR=compress;
  65.         ZEXT=taz
  66.         shift;
  67.         continue;
  68.     else
  69.         break;
  70.     fi
  71. done;
  72.  
  73. INSTTOPDIR=$INSTROOT/install
  74. INSTDIR=$INSTTOPDIR/installed
  75. INSTSCRDIR=$INSTTOPDIR/scripts
  76. INSTSCRIPT=doinst.sh
  77.  
  78. MNTDIR=/user
  79. MOUNTTYPE=minix
  80.  
  81. function MountDisk() {
  82.     declare -i MountStat
  83.     if [ "$INSTSRC" != "" ]; then
  84.         test -d $INSTSRC;
  85.         MountStat=$?
  86.         return $MountStat;
  87.     fi
  88.     for j in 1 2 3; do
  89.         echo -n "Insert disk $1 into the floppy drive then hit enter, or q to quit"
  90.         read ans;
  91.         if [ "$ans" = "q" ]; then
  92.             exit 1;
  93.         fi;
  94.         MountStat=0
  95.         for k in $MOUNTTYPE minix msdos ext; do
  96.             if [ $MountStat = 0 -o $k != $MOUNTTYPE ]; then
  97.                 mount -r -t $k $INSTDEV $MNTDIR  >& /dev/null
  98.                 MountStat=$?
  99.                 if [ $MountStat = 0 ]; then
  100.                     MOUNTTYPE=$k
  101.                     return 0;
  102.                 fi
  103.             fi
  104.         done
  105.     done
  106.     exit 1
  107. }
  108.  
  109. function UnmountDisk() {
  110.     if [ "$INSTSRC" = "" ]; then
  111.         umount $INSTDEV > /dev/null
  112.     fi;
  113. }
  114.  
  115. function InstallPkg() {
  116.     if [ -f $1 ]; then
  117.         echo -n "installing `basename $1 .$2`..."
  118.         if [ -e $INSTTOPDIR/$INSTSCRIPT ]; then
  119.             rm $INSTTOPDIR/$INSTSCRIPT
  120.         fi
  121.         if [ "tar" = "$2" ]; then
  122.             (cd $INSTROOT; tar -xvlpf - | sed "/\/$/d" ) < $1 > $INSTDIR/`basename $1 .$2`
  123.         else
  124.             (cd $INSTROOT; $COMPR -dc | tar -xvlpf - | sed "/\/$/d" ) < $1 > $INSTDIR/`basename $1 .$2`
  125.         fi
  126.         if [ -f $INSTTOPDIR/$INSTSCRIPT ]; then
  127.             (cd $INSTROOT; sh $INSTTOPDIR/$INSTSCRIPT -install;)
  128.             mv $INSTTOPDIR/$INSTSCRIPT $INSTSCRDIR/`basename $1 .$2`;
  129.         fi
  130.         if [ "bin" = "`basename $1 .$2`" ]; then
  131.             hash -r
  132.         fi
  133.         echo "done"
  134.     else
  135.         echo "$1 not found"
  136.     fi;
  137. }
  138.  
  139. function InstallDisk() {
  140.     declare -i Status;
  141.     declare -i FileSize;
  142.     for k in 1 2 3; do
  143.         MountDisk $1
  144.         Status=$?
  145.         if [ $Status != 0 ]; then
  146.             return 1;
  147.         fi
  148.         if [ "$INSTSRC" = "" ]; then
  149.             SRCDIR=$MNTDIR
  150.         else
  151.             SRCDIR=$INSTSRC/$1
  152.         fi
  153.         if [ -e $SRCDIR/disk$1 -o $1 = Disk ]; then
  154.             DISKNAME=$SRCDIR/disk*;
  155.             if [ -f $DISKNAME ]; then
  156.                 cat $DISKNAME > $INSTROOT/install/catalog/`basename $DISKNAME`
  157.                 FileSize=`filesize $DISKNAME`;
  158.                 echo "`basename $DISKNAME`      $FileSize" >> $INSTROOT/install/disks/`basename $DISKNAME`
  159.             fi
  160.             for FileExt in taz tpz tar tgz; do
  161.                 for FileZ in $SRCDIR/*.$FileExt; do
  162.                     if [ "$FileZ" = "$SRCDIR/*.$FileExt" ]; then
  163.                         continue;
  164.                     fi
  165.                     if [ $1 = Disk -o "$DOPROMPT" = "true" ]; then
  166.                         echo ""
  167.                         sed 's/^/ /' $SRCDIR/disk* |  \
  168.                             fgrep " `basename $FileZ .$FileExt`:" | \
  169.                             sed 's/^ //';
  170.  
  171.                         FileSize=`filesize $FileZ`/341;  
  172.                         echo -n "Install pkg `basename $FileZ .$FileExt` [\~${FileSize}K] (y/n/q)?"
  173.                         read ans;
  174.                         if [ "$ans" = "Y" -o  "$ans" = "y" ]; then
  175.                             InstallPkg $FileZ $FileExt;
  176.                         elif [ "$ans" = "q" -o  "$ans" = "Q" ]; then
  177.                             UnmountDisk
  178.                             exit 0;
  179.                         fi
  180.                     else
  181.                         InstallPkg $FileZ $FileExt;
  182.                     fi
  183.                     if [ $1 != Disk ]; then
  184.                         echo "`basename $FileZ`      `filesize $FileZ`" >> $INSTROOT/install/disks/`basename $DISKNAME`
  185.                     fi
  186.                 done
  187.             done
  188.             if [ -e $SRCDIR/install.end ]; then
  189.                 Status=1;
  190.             else
  191.                 Status=0;
  192.             fi
  193.             UnmountDisk
  194.             return $Status 
  195.         else
  196.             UnmountDisk
  197.             echo -n "error: wrong disk (file disk$1 not found), try again or skip (y/n/s)?"
  198.             read ans;
  199.             if [ "$ans" = "N" -o  "$ans" = "n" ]; then
  200.                 return 1
  201.             fi
  202.             if [ "$ans" = "S" -o  "$ans" = "s" ]; then
  203.                 return 2
  204.             fi
  205.         fi;
  206.     done
  207. }
  208.  
  209. function RemovePkg() {
  210.     if [ -f $INSTDIR/$1 ]; then
  211.         if [ -f $INSTSCRDIR/$1 ]; then
  212.             (cd $INSTROOT; sh $INSTSCRDIR/$1 -remove;)
  213.             rm $INSTSCRDIR/$1
  214.         fi
  215.         (cd $INSTROOT; xargs /bin/rm -f ) < $INSTDIR/$1 
  216.         rm $INSTDIR/$1
  217.     else
  218.         echo "error: unknown package $1"
  219.     fi
  220. }
  221.  
  222. function DoInstall() {
  223.     declare -i Counter;
  224.     if [ "$1" = "a" ]; then
  225.         Counter=2;
  226.     else
  227.         Counter=1;
  228.     fi
  229.     while [ 0 ]; do
  230.         InstallDisk $1$Counter;
  231.         if [ $? = 1 ]; then
  232.             return 0;
  233.         fi
  234.         Counter=$Counter+1;
  235.     done;
  236. }
  237.  
  238. function ShowInstalled() {
  239.     for i in $INSTDIR/*; do
  240.         echo "`basename $i`";
  241.     done;
  242. }
  243.  
  244. function DoExtract() {
  245.     if [ "$COMPR" = "compress" ]; then
  246.         (cd $INSTROOT; tar -clpf - -T $INSTDIR/$2 ) > $2.tar
  247.         $COMPR $2.tar
  248.         if [ -e $2.tar.Z ]; then
  249.             mv $2.tar.Z $2.taz
  250.         fi
  251.     else
  252.         (cd $INSTROOT; tar -clpf - -T $INSTDIR/$2  | $COMPR ) > $2.$ZEXT
  253.     fi
  254. }
  255.  
  256. if [ $# = 0 ]; then
  257.     PrintUsage;
  258. elif [ "$1" = "-view" ]; then 
  259.     ShowInstalled;
  260. elif [ "$1" = "-everything" ]; then 
  261.     DoInstall a;
  262.     DoInstall b;
  263.     DoInstall c;
  264.     DoInstall d;
  265.     DoInstall s;
  266.     DoInstall t;
  267.     DoInstall x;
  268. elif [ "$1" = "-all" ]; then 
  269.     DoInstall a;
  270.     DoInstall b;
  271.     DoInstall c;
  272.     DoInstall x;
  273. elif [ "$1" = "-base" ]; then 
  274.     DoInstall a;
  275.     DoInstall b;
  276.     DoInstall c;
  277. elif [ "$1" = "-mini" ]; then 
  278.     DoInstall a;
  279. elif [ "$1" = "-rest" ]; then 
  280.     DoInstall b;
  281.     DoInstall c;
  282. elif [ "$1" = "-X11" ]; then 
  283.     DoInstall x;
  284. elif [ "$1" = "-remove" -a $# = 2 ]; then
  285.     RemovePkg $2
  286. elif [ "$1" = "-install" -a $# = 2 ]; then
  287.     if [ "`basename $2 .$ZEXT`" != "`basename $2`" ]; then
  288.         InstallPkg $2 "$ZEXT"
  289.     else
  290.         InstallPkg $2 "tar"
  291.     fi
  292. elif [ "$1" = "-series" -a $# = 2 ]; then
  293.     DoInstall $2
  294. elif [ "$1" = "-extract" -a $# = 2 -o $1 = "-extracttar"  -a $# = 2 ]; then
  295.     if [ -f $INSTDIR/$2 ]; then
  296.         if [ -f $INSTSCRDIR/$2 ]; then
  297.             cp $INSTSCRDIR/$2 $INSTTOPDIR/$INSTSCRIPT
  298.             (cd $INSTROOT; sh $INSTSCRDIR/$2 -extract;)
  299.             if [ $1 = "-extract" ]; then
  300.                 (cd $INSTROOT; tar -clpf - -T $INSTDIR/$2 | $COMPR ) > $2.$ZEXT
  301.             else
  302.                 DoExtract $1 $2
  303.             fi
  304.             (cd $INSTROOT; sh $INSTSCRDIR/$2 -retract;)
  305.             rm $INSTTOPDIR/$INSTSCRIPT
  306.         else
  307.             if [ $1 = "-extract" ]; then
  308.                 (cd $INSTROOT; tar -clpf - -T $INSTDIR/$2 | $COMPR ) > $2.$ZEXT
  309.             else
  310.                 DoExtract $1 $2
  311.             fi
  312.         fi
  313.     else
  314.         echo "$INSTDIR/$2 not found";
  315.     fi;
  316. elif [ "$1" = "-disk" ]; then
  317.     if [ $# = 1 ] ; then
  318.         InstallDisk Disk
  319.     else
  320.         InstallDisk $2
  321.     fi
  322. elif [ "$1" = "-mount" ]; then
  323.     MountDisk;
  324. elif [ "$1" = "-unmount" ]; then
  325.     UnmountDisk;
  326. else
  327.     PrintUsage;
  328. fi;
  329.