home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / sls / old / a1.5 / bin / doinstall < prev    next >
Encoding:
Text File  |  1993-07-31  |  10.9 KB  |  437 lines

  1. #!/bin/sh
  2. echo "Welcome to the SLS installation program (copyright Softlanding Software)"
  3. echo " "
  4.  
  5. function usage()  {
  6.     echo " "
  7.     echo "Installs SLS onto a hard disk from floppies, tape, CD, HD or Network"
  8.     echo "usage: doinstall PART [ PART2 MNT2 ...]"
  9.     echo "where: PART is the partition to install to, optionally followed by" 
  10.     echo "partition/directory pairs to mount on root.   for example"
  11.     echo "       doinstall                       # does menu driven install"
  12.     echo "       doinstall /dev/hda2"
  13.     echo "       doinstall /dev/hda2 /dev/hda3 /usr /dev/hdb1 /usr/spool"
  14.     exit 1
  15. }
  16.  
  17. function domount() {
  18.     if [ ! -b $1 ]; then
  19.         echo "Error: $1 is not a block device, can not mount on $2";
  20.         usage;
  21.         exit 2
  22.     fi
  23.     MOUNTTYPE="ext2"
  24.     mount -t $MOUNTTYPE $1 $2
  25.     MNTSTAT=$?;
  26.     if [ $MNTSTAT != 0 ]; then
  27.         echo "Error: can not mount $1.  Did you use: mke2fs -c $1 SIZE"
  28.         echo "where SIZE is the number of blocks shown by fdisk?"
  29.         exit 1;
  30.     fi
  31.     if [ "$2" = "/root/" ]; then
  32.         echo "$1    /        $MOUNTTYPE    defaults" > /root/fstab.tmp
  33.     else
  34.         echo "$1    $2        $MOUNTTYPE    defaults" >> /root/fstab.tmp
  35.     fi
  36. }
  37.  
  38. function partdetect()
  39. {
  40. (fdisk $1 << EOF
  41. q
  42. EOF
  43. ) >& /dev/null 
  44. return $?
  45. }
  46.  
  47. function partshow()
  48. {
  49. (fdisk $1 << EOF
  50. p
  51. q
  52. EOF
  53. echo "") | fgrep '/dev/' | sed '/Disk/d'
  54. }
  55.  
  56. function partsize () { partshow `echo $1 | cut -c1-8` | fgrep $1 | cut -c38-45 }
  57.  
  58. declare -i DISKCOUNT
  59.  
  60. function partdisplay()
  61. {
  62.     echo 'Following is your current partition setup:'
  63.     DISKCOUNT=0;
  64.     DISKLIST=""
  65.     for i in hda hdb sda sdb sdc sdd sde sdf; do
  66.         partdetect /dev/$i  && 
  67.         DISKCOUNT=$DISKCOUNT+1 &&
  68.         DISKLIST="/dev/$i $DISKLIST" && 
  69.         partshow /dev/$i &&
  70.         if [ "$EXPART" = "" ]; then
  71.             EXPART=/dev/${i}1
  72.         fi
  73.     done
  74.     if [ $DISKCOUNT = 0 ]; then
  75.         echo "Sorry, Linux can not find any hard disks $DISKLIST";  
  76.         exit 1
  77.     fi
  78.  
  79. function runfdisk()
  80. {    
  81.     if [ $DISKCOUNT = 1 ]; then
  82.         CURDISK=$DISKLIST;
  83.     else
  84.         echo -n "which disk do you wish to partition [$DISKLIST]"
  85.         read CURDISK
  86.     fi
  87.     fdisk $CURDISK;
  88.     echo "If you wrote any changes, please (hard) reboot your PC now"
  89.     exit 0
  90. }
  91.  
  92. function domkfs()
  93. {
  94.     if [ "$1" = "" ]; then
  95.         return 1
  96.     fi
  97.     if [ ! -b $1 ]; then
  98.         echo "$1 is not a valid partition"
  99.         return 1
  100.     fi
  101.     if [ "`echo $1 | cut -c9`" = "" ]; then
  102.         echo "invalid partition"
  103.         return 1
  104.     fi
  105.     echo "Preparing Hard Drive.  This will take a few minutes, please standby..."
  106.     echo " "
  107.     mke2fs -c $1 `partsize $1` || (echo "mke2fs failed"; exit 1)
  108. }
  109.  
  110. function partsetup()
  111. {
  112.     if [ "$ROOTDEVICE"  = "" ]; then
  113.         echo -n "enter the name of the partition to use as root (eg. $EXPART): "
  114.         read ROOTDEVICE
  115.         NEWPART=$ROOTDEVICE
  116.         NEWDIR=
  117.     else
  118.         echo -n "enter the name of the partition to use as root (eg. $EXPART):"
  119.         read NEWPART
  120.         echo -n "what directory should this partition be mounted on (eg. /home): "
  121.         read NEWDIR
  122.     fi
  123.     domkfs $NEWPART || exit 1
  124.     if [ "$NEWDIR" != "" ]; then
  125.          mkdir /root/$NEWDIR || exit
  126.     fi
  127.     domount $NEWPART /root/$NEWDIR
  128. }
  129.  
  130. function linuxsetup()
  131. {    partdisplay
  132.     while [ 1 ]; do
  133.         echo '           Disk Setup Procedure '
  134.         echo ' '
  135.         echo '  1   Setup Linux partitions (first one will be used as the root)'
  136.         echo '  2   Setup a swap PARTITION (required for 4 Megs RAM or less)'
  137.         echo '  3   Setup a swap FILE on root (must do 1 above first)'
  138.         echo '  4   Display partition sizes'
  139.         echo '  5   Run fdisk to change partition sizes (will require a reboot)'
  140.         echo '  6   Abort installation'
  141.         echo '  7   Done (commence installation)'
  142.         echo ' '
  143.         echo -n " Select one of the above (1-7): "
  144.         read func;
  145.         case $func in
  146.         1) partsetup;;
  147.         [2,3])    if [ "$swapsize" != "" ]; then
  148.                 echo "Sorry: swap area was already created"
  149.                 continue;
  150.             fi
  151.             if [ "$func" = "2" ]; then
  152.                 echo -n "Use which partition for swapping (eg. $EXPART): "
  153.                 read swappart;
  154.                 swapsize=`partsize $swappart`
  155.             else
  156.                 if [ "$PARTNAMES" = "" ]; then
  157.                     echo "Sorry, you must setup the root first";
  158.                     continue;
  159.                 fi
  160.                 echo -n "How big a swap file in Megs (max 16): "
  161.                 declare -i swapmegs
  162.                 read swapmegs
  163.                 swapsize = swapmegs * 1024;
  164.                 swappart=/root/swap
  165.             fi
  166.             mkswap $swappart $swapsize &&
  167.             swapon $swappart &&
  168.             if [ -f /root/fstab.tmp ]; then
  169.                 echo "$1    $2        swap" >> /root/fstab.tmp
  170.             fi
  171.             ;;
  172.         4) partdisplay;;
  173.         5) runfdisk ;;
  174.         6) exit 0;;
  175.         7) break;; 
  176.         esac
  177.     done
  178. }
  179.  
  180. function mountsource() {
  181.     case $1 in 
  182.     harddrive)
  183.         INSTSRC=/mnt/install
  184.         echo -n "Enter the partition that the source is on (eg. /dev/hda1):"
  185.         read hdloc;
  186.         echo -n "Enter the type of the filesystem (minix/ext2/msdos)";
  187.         read hdtype;
  188.         mount -t $hdtype $hdloc /mnt
  189.     ;;
  190.     cdrom)
  191.         INSTSRC=/mnt/install
  192.         echo -n "Is this a Mitsumi CDROM player (y/n)"
  193.         read ans;
  194.         if [ "$ans" = "y" ]; then
  195.             echo -n "Enter the IRQ,BASEADDR (eg 7,280):"
  196.             readn ans;
  197.             echo "mitsumi=$ans" >> /root/etc/hwconfig
  198.             mount -t iso9660 /dev/mcd0 /mnt
  199.         else
  200.             echo "Assuming SCSI CDROM"
  201.             mount -t iso9660 /dev/sr0 /mnt
  202.             echo "CDROM SCSI" >> /root/etc/hwconfig
  203.         fi
  204.     ;;
  205.     network)
  206.         INSTSRC=/mnt/install
  207.         echo "Following is your current IP setup"
  208.         cat /etc/hosts
  209.         echo -n "Do you wish to change or set your IP address(y/n)?: "
  210.         read ans;
  211.         if [ "y" = "$ans" ]; then
  212.             echo -n "Enter your IP address (eg, 192.0.2.129): "
  213.             read ans;
  214.             echo "$ans    `hostname`" > /etc/hosts
  215.             echo -n "Enter your Network address (eg, 192.0.2.0): "
  216.             read ans;
  217.             echo "$ans    network" >> /etc/hosts
  218.             echo -n "Enter your Router address, if any (eg, 192.0.2.1): "
  219.             read ans;
  220.             if [ "" != "$ans" ]; then
  221.                 echo "$ans    router" >> /etc/hosts
  222.             fi
  223.             echo "127.0.0.1    localhost" >> /etc/hosts
  224.             sync
  225.             echo "IP setup is now changed";
  226.         fi
  227.         if [ "$RCNET_RUN" = "" ]; then
  228.             /etc/rc.net
  229.         fi
  230.         RCNET_RUN=1
  231.         echo -n "Enter IP address of NFS server:"
  232.         read ipaddr;
  233.         echo -n "Enter directory on server where SLS source dir ./install/ is located:"
  234.         read path;
  235.         while [ 1 ]; do
  236.             mount -t nfs $ipaddr:$path /mnt  && break;
  237.             echo -n "mount failed (sometimes takes 2-3 tries). Try again (y/n): "
  238.             read ans;
  239.             if [ "$ans" != "y" ]; then
  240.                 break;
  241.             fi
  242.         done
  243.     ;;
  244.     esac
  245.     MNTSTAT=$?
  246.     if [ $MNTSTAT != 0 ]; then
  247.         echo "error: can not mount source"
  248.         exit 2;
  249.     fi
  250.     if [ -d $INSTSRC/a4 -a -d $INSTSRC/a3 ]; then
  251.         return
  252.     else
  253.         echo "error: SLS distribution files not found in $INSTSRC"
  254.         usage
  255.     fi
  256. }
  257.  
  258. umount /root >& /dev/null
  259. if [ $# -lt 1 ]; then
  260.     linuxsetup
  261. else
  262.     ROOTDEVICE=$1
  263.     domount $ROOTDEVICE /root
  264. fi
  265. INSTDEV=/dev/fd0
  266. INSTSRC=
  267. INSTTYPE=
  268. INSTMEDIA=
  269.  
  270. if [ "/dev/ram /" = "`rdev`" ]; then
  271.     if [ -f /bin/vi ]; then
  272.         rm -f /bin/vi /bin/telnet /bin/ping
  273.         SWAPSIZE=400
  274.     else
  275.         SWAPSIZE=200
  276.     fi
  277.     if [ -f /zImage -a ! -f /swap ]; then
  278.         rm /zImage
  279.         dd if=/dev/zero of=/swap bs=1k count=$SWAPSIZE >& /dev/null
  280.         mkswap /swap $SWAPSIZE
  281.         swapon /swap
  282.     fi
  283. fi
  284. while [ 0 ]; do
  285.     umount /mnt >& /dev/null
  286.     echo '           Install Source '
  287.     echo ''
  288.     echo '  1  Install from Floppy Disks'
  289.     echo '  2  Install from Hard Disk'
  290.     echo '  3  Install from Tape'
  291.     echo '  4  Install from CDROM'
  292.     echo '  5  Install from Network (via NFS)'
  293.     echo '  6  Install just bootdisk to HD'
  294.     echo ' '
  295.     echo -n 'Where will you be installing SLS from (1-6): '
  296.     read ans;
  297.     case $ans in
  298.         1 ) INSTMEDIA=floppy
  299.         while [ 0 ];do 
  300.             echo " "
  301.             echo '    1)  Drive A: 5 1/4 inch'
  302.             echo '    2)  Drive A: 3 1/2 inch'
  303.             echo '    3)  Drive B: 5 1/4 inch'
  304.             echo '    4)  Drive B: 3 1/2 inch'
  305.             echo " "
  306.             echo -n "Enter Drive You Will Be Doing The Installation From (1/2/3/4): "
  307.             read answer; 
  308.             case $answer in
  309.                 1) INSTDEV=/dev/fd0h1200;;
  310.                 2) INSTDEV=/dev/fd0H1440;;
  311.                 3) INSTDEV=/dev/fd1h1200;;
  312.                 4) INSTDEV=/dev/fd1H1440;;
  313.                 *) continue;;
  314.             esac
  315.             umount $INSTDEV
  316.             break;
  317.         done 
  318.         ;;
  319.         2 ) INSTMEDIA=harddrive; mountsource harddrive ;;
  320.         3 ) INSTMEDIA=tape ;;
  321.         4 ) INSTMEDIA=cdrom; mountsource cdrom ;;
  322.         5 ) INSTMEDIA=network; mountsource network ;;
  323.         6 ) umount /proc; cp -ax /[a-qs-z]* /root; mkdir /root/root; sync
  324.             echo "Reboot now using ALT at LILO prompt and \"harddisk root=$ROOTDEVICE\""
  325.                     exit 0 ;;
  326.         *) echo "$ans invalid, pick again"; continue;; 
  327.     esac
  328.     break;
  329. done
  330. while [ "$INSTMEDIA" != tape ]; do
  331.     echo ' '
  332.     echo '    1 - Install a minimal system (12 Meg)'
  333.     echo '    2 - Install the full base system (50 Meg)'
  334.     echo '    3 - Install base system + X11 (70 Meg)'
  335.     echo '    4 - Install everything (90 Meg)'
  336.     echo " "
  337.     echo -n 'Enter type of install (1/2/3/4)'
  338.     read ans;
  339.     if [ $ans = 1 ]; then
  340.         INSTTYPE="mini"
  341.         break;
  342.     elif [ $ans = 2 ]; then
  343.         INSTTYPE="base"
  344.         break;
  345.     elif [ $ans = 3 ]; then
  346.         INSTTYPE="all"
  347.         break;
  348.     elif [ $ans = 4 ]; then
  349.         INSTTYPE="everything"
  350.         break;
  351.     fi
  352. done
  353. mkdir -p /root/etc
  354. echo -n "" > /root/etc/hwconfig
  355. mkdir -p /root/install/installed
  356. mkdir -p /root/install/disks
  357. mkdir -p /root/install/scripts
  358. mkdir -p /root/install/catalog
  359. while [ "$NEWPART" = "" ]; do
  360.     if [ "" != "$2" -a "" != "$3" ]; then
  361.         mkdir /root$3
  362.         domount $2 /root$3
  363.         shift 2;
  364.     else
  365.         break;
  366.     fi
  367. done
  368. if [ -f /root/doinst.sh ]; then
  369.     sh /root/doinst.sh;
  370. fi
  371. if [ "$INSTMEDIA" != tape ]; then
  372.     echo -n 'Do you want to be prompted, with a description, before installing each package? (y/n): '
  373.     read ans
  374.     if [ "$ans" = "y" ]; then
  375.         DOPROMPT="-doprompt"
  376.     fi
  377. fi
  378. if [ "$INSTSRC" != "" ]; then
  379.     INSTSRC="-instsrc $INSTSRC"
  380. fi
  381. if [ "$INSTMEDIA" = tape ]; then
  382.     export DOPROMPT
  383.     tarsh /dev/rmt0 /bin/tapeinstall
  384. else
  385.     echo "sysinstall -instdev $INSTDEV $INSTSRC -instroot /root $DOPROMPT -$INSTTYPE"
  386.     sysinstall -instdev $INSTDEV $INSTSRC -instroot /root $DOPROMPT -$INSTTYPE
  387. fi
  388. hash -r
  389. mv /root/fstab.tmp /root/etc/fstab
  390. if [ "$INSTDEV" != "" ]; then
  391.     if [ $INSTDEV =  /dev/fd1H1440 ]; then
  392.         INSTDEV=/dev/fd0h1200;
  393.     elif [ $INSTDEV =  /dev/fd1h1200 ]; then
  394.         INSTDEV=/dev/fd0H1440;
  395.     fi
  396.     echo "FLOPPYA $INSTDEV" >> /root/etc/hwconfig
  397. fi
  398. echo "ROOTDEV $ROOTDEVICE" >> /root/etc/hwconfig
  399. VGAMODE=-3
  400. if [ "/dev/ram /" = "`rdev`" ]; then
  401.     echo -n 'Now put a formatted floppy into your boot drive and hit enter: '
  402.     read ans;
  403.     dd if=/root/zImage of=$INSTDEV
  404.     rdev $INSTDEV $ROOTDEVICE
  405.     echo -n "Do you wish to have the video mode preset at boot time? (y/n): "
  406.     read ans;
  407.     if [ "$ans" = "y" ]; then
  408.         echo -n "Enter the mode (-1 for 80x25 mode, or the key 1, 2, 3, ...): "
  409.         read VGAMODE;
  410.         rdev -v $INSTDEV $VGAMODE
  411.     fi
  412.     sync
  413. fi
  414. echo "VGAMODE $VGAMODE" >> /root/etc/hwconfig
  415. if [ -x /root/etc/syssetup ]; then
  416.     (cd /root; etc/syssetup -instroot /root -install )
  417. fi
  418. ANOTHER=""
  419. while [ 1 ]; do
  420.     echo -n "If there is a$ANOTHER patch disk to install, insert it in A: and type y (y/n): "
  421.     read ans;
  422.     if [ "$ans" = "y" ]; then
  423.         sysinstall -disk && echo "Patch disk installed..."
  424.         ANOTHER=" another"
  425.     else
  426.         break;
  427.     fi
  428. done
  429. sync
  430. echo "Installation is complete.  You may now hard reset your computer and start"
  431. echo "using SLS from your hard drive.  Alternatively, you can boot from the"
  432. echo "newly created boot disk, or you can boot from the install disk as follows:"
  433. echo '     - when you see the word "LILO", hold down the ALT key'
  434. echo "     - type \"harddisk root=$ROOTDEV\" to boot to your installation"
  435. echo 'Once there, you can use "makebootdisk" to create a boot floppy'
  436.