#!/bin/sh # # setup 4.1 - install a MINIX distribution # # Changes: # Aug 2005 robustness checks and beautifications (Jorrit N. Herder) # Jul 2005 extended with autopart and networking (Ben Gras) # Dec 20, 1994 created (Kees J. Bot) # setglobal LOCALRC = '/usr/etc/rc.local' setglobal MYLOCALRC = '/mnt/etc/rc.local' setglobal ROOTMB = '16' setglobal ROOTSECTS = $[expr $ROOTMB '*' 1024 '*' 2] setglobal USRKBFILE = '/.usrkb' if test ! -f $USRKBFILE { echo "Are you really running from CD?" echo "No $USRKBFILE file." exit 1 } setglobal USRKB = $[cat /.usrkb] setglobal TOTALMB = $[expr 3 + $USRKB / 1024 + $ROOTMB] setglobal ROOTFILES = $[cat /.rootfiles] setglobal USRFILES = $[cat /.usrfiles] if test $TOTALMB -lt 1 { echo "Are you really running from CD?" echo "Something wrong with size estimate on CD." exit 1 } if test $ROOTFILES -lt 1 { echo "Are you really running from CD?" echo "Something wrong with root files count on CD." exit 1 } if test $USRFILES -lt 1 { echo "Are you really running from CD?" echo "Something wrong with usr files count on CD." exit 1 } setglobal PATH = '/bin:/usr/bin' export PATH proc usage { cat > !2 << ''' Usage: setup # Install a skeleton system on the hard disk. setup /usr # Install the rest of the system (binaries or sources). # To install from other things then floppies: urlget http://... | setup /usr # Read from a web site. urlget ftp://... | setup /usr # Read from an FTP site. mtools copy c0d0p0:... - | setup /usr # Read from the C: drive. dosread c0d0p0 ... | setup /usr # Likewise if no mtools. ''' exit 1 } proc warn { echo -e "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b ! $1" } # No options. while getopts '' opt { usage; } shift $[expr $OPTIND - 1] if test $USER != root { echo "Please run setup as root." exit 1 } # Find out what we are running from. exec !9 9<&0 /dev/null { setglobal step1 = 'ok' } else { warn "invalid keyboard" } } # end Step 1 # begin Step 2 #step2="" #while [ "$step2" != ok ] #do # echo "" # echo " --- Step 2: Select minimal or full distribution -----------------------" # echo "" # echo "You can install MINIX as (M)inimal or (F)ull. (M)inimal" # echo "includes only the binary system and basic system sources." # echo "(F)ull also includes commands sources." # echo "" # echo "Please select:" # echo " (M)inimal install (only basic sources) ($NOSRCMB MB required)" # echo " (F)ull install (full install) ($TOTALMB MB required)" # echo " " # echo -n "Basic (M)inimal or (F)ull install? [F] " # read conf # case "$conf" in # "") step2="ok"; nobigsource="" ;; # [Ff]*) step2="ok"; nobigsource="" ;; # [Mm]*) step2="ok"; nobigsource="1"; TOTALMB=$NOSRCMB; USRFILES=$NOSRCUSRFILES ;; # esac #done # end Step 2 echo "" echo " --- Step 2: Selecting full distribution -------------------------------" echo "" setglobal nobigsource = ''"" # begin Step 3 setglobal step3 = ''"" while [ "$step3" != ok ] { echo "" echo " --- Step 3: Create or select a partition for MINIX 3 -------------------" echo "" echo "Now you need to create a MINIX 3 partition on your hard disk." echo "You can also select one that's already there." echo " " echo "If you have an existing installation, reinstalling will let you" echo "keep your current partitioning and subpartitioning, and overwrite" echo "everything except your s1 subpartition (/home). If you want to" echo "reinstall, select your existing minix partition." echo " " echo "Unless you are an expert, you are advised to use the automated" echo "step-by-step help in setting up." echo "" setglobal ok = ''"" while [ "$ok" = "" ] { echo -n "Press ENTER for automatic mode, or type 'expert': " read mode if test -z $mode { setglobal auto = '"1'"; setglobal ok = '"yes'"; } if test $mode = expert { setglobal auto = ''""; setglobal ok = '"yes'"; } if test $ok != yes { warn "try again"; } } setglobal primary = '' if test -z $auto { # Expert mode echo -n " MINIX needs one primary partition of $TOTALMB MB for a full install, plus what you want for /home. If there is no free space on your disk then you have to choose an option: (1) Delete one or more partitions (2) Allocate an existing partition to MINIX 3 (3) Exit setup and shrink a partition using a different OS To make this partition you will be put in the editor \"part\". Follow the advice under the '!' key to make a new partition of type MINIX. Do not touch an existing partition unless you know precisely what you are doing! Please note the name of the partition (e.g. c0d0p1, c0d1p3, c1d1p0) you make. (See the devices section in usage(8) on MINIX device names.) :" read ret while [ -z "$primary" ] { part || exit echo -n " Please finish the name of the primary partition you have created: (Just type ENTER if you want to rerun \"part\") /dev/" read primary } echo "" echo "This is the point of no return. You have selected to install MINIX" echo "on partition /dev/$primary. Please confirm that you want to use this" echo "selection to install MINIX." echo "" setglobal confirmation = ''"" if test ! -b "/dev/$primary" { echo "/dev/$primary is not a block device." } while [ -z "$confirmation" -o "$confirmation" != yes -a "$confirmation" != no ] { echo -n "Are you sure you want to continue? Please enter 'yes' or 'no': " read confirmation if test $confirmation = yes { setglobal step3 = 'ok'; } } setglobal biosdrivename = '"Actual BIOS device name unknown, due to expert mode.'" } else { if test $auto = "1" { # Automatic mode setglobal PF = '"/tmp/pf'" if autopart -m$TOTALMB -f$PF { if test -s $PF { set $[cat $PF] setglobal bd = $1 setglobal bdn = $2 setglobal biosdrivename = ""Probably, the right command is \"boot $bdn\"."" if test -b "/dev/$bd" { setglobal primary = $bd } else { echo "Funny device $bd from autopart." } } else { echo "Didn't find output from autopart." } } else { echo "Autopart tool failed. Trying again." } # Reset at retries and timeouts in case autopart left # them messy. atnormalize if test -n $primary { setglobal step3 = 'ok'; } } } if test ! -b "/dev/$primary" { echo Doing step 3 again. setglobal step3 = ''"" } else { setglobal devsize = $[devsize /dev/$primary] if test $devsize -lt 1 { echo "/dev/$primary is a 0-sized device." setglobal step3 = ''"" } } } # while step3 != ok # end Step 3 setglobal root = "$(primary)s0" setglobal home = "$(primary)s1" setglobal usr = "$(primary)s2" umount /dev/$root !2 >/dev/null && echo "Unmounted $root for you." umount /dev/$home !2 >/dev/null && echo "Unmounted $home for you." umount /dev/$usr !2 >/dev/null && echo "Unmounted $usr for you." setglobal devsizemb = $[expr $devsize / 1024 / 2] setglobal maxhome = $[expr $devsizemb - $TOTALMB - 1] if test $devsizemb -lt $TOTALMB { echo "The selected partition ($devsizemb MB) is too small." echo "You'll need $TOTALMB MB at least." exit 1 } if test $maxhome -lt 1 { echo "Note: you can't have /home with that size partition." setglobal maxhome = '0' } setglobal TMPMP = '/m' mkdir $TMPMP >/dev/null !2 > !1 setglobal confirm = ''"" while [ "$confirm" = "" ] { setglobal auto = ''"" echo "" echo " --- Step 4: Reinstall choice ------------------------------------------" if mount -r /dev/$home $TMPMP >/dev/null !2 > !1 { umount /dev/$home >/dev/null !2 > !1 echo "" echo "You have selected an existing MINIX 3 partition." echo "Type F for full installation (to overwrite entire partition)" echo "Type R for a reinstallation (existing /home will not be affected)" echo "" echo -n "(F)ull or (R)einstall? [R] " read conf match $conf { with "" setglobal confirm = '"ok'"; setglobal auto = '"r'"; with [Rr]* setglobal confirm = '"ok'"; setglobal auto = '"r'"; with [Ff]* setglobal confirm = '"ok'"; setglobal auto = ''"" } } else { echo "" echo "No old /home found. Doing full install." echo "" setglobal confirm = '"ok'"; } } rmdir $TMPMP setglobal nohome = '"0'" setglobal homesize = ''"" if test ! $auto = r { echo "" echo " --- Step 5: Select the size of /home ----------------------------------" while [ -z "$homesize" ] { # 20% of what is left over after / and /usr # are taken. setglobal defmb = $[expr $maxhome / 5] if test $defmb -gt $maxhome { setglobal defmb = $maxhome } echo "" echo "MINIX will take up $TOTALMB MB, without /home." echo -n "How big do you want your /home to be in MB (0-$maxhome) ? [$defmb] " read homesize if test $homesize = "" { setglobal homesize = $defmb; } if test $homesize -lt 1 { setglobal nohome = '1' echo "Ok, not making a /home." setglobal homesize = '0' } else { if test $homesize -gt $maxhome { echo "That won't fit!" setglobal homesize = ''"" } else { echo "" echo -n "$homesize MB Ok? [Y] " read ok test $ok = Y -o $ok = y -o $ok = "" || setglobal homesize = ''"" } } echo "" } # Homesize in sectors setglobal homemb = ""$homesize MB"" setglobal homesize = $[expr $homesize '*' 1024 '*' 2] } else { setglobal homepart = $[devsize /dev/$home] setglobal homesize = $[expr $homepart / 2 / 1024] if test $homesize -gt $maxhome { echo "Sorry, but your /home is too big ($homesize MB) to leave enough" echo "space on the rest of the partition ($devsizemb MB) for your" echo "selected installation size ($TOTALMB MB)." exit 1 } # Homesize unchanged (reinstall) setglobal homesize = 'exist' setglobal homemb = '"current size'" } setglobal minblocksize = '1' setglobal maxblocksize = '64' setglobal blockdefault = '4' if test ! $auto = "r" { echo "" echo " --- Step 6: Select a block size ---------------------------------------" echo "" echo "The default file system block size is $blockdefault kB." echo "" while [ -z "$blocksize" ] { echo -n "Block size in kilobytes? [$blockdefault] "; read blocksize test -z $blocksize && setglobal blocksize = $blockdefault if test $blocksize -lt $minblocksize -o $blocksize -gt $maxblocksize { warn "At least $minblocksize kB and at most $maxblocksize kB please." setglobal blocksize = ''"" } } } else { setglobal blocksize = $blockdefault } setglobal blocksizebytes = $[expr $blocksize '*' 1024] echo " You have selected to (re)install MINIX 3 in the partition /dev/$primary. The following subpartitions are now being created on /dev/$primary: Root subpartition: /dev/$root $ROOTMB MB /home subpartition: /dev/$home $homemb /usr subpartition: /dev/$usr rest of $primary " # Secondary master bootstrap. installboot -m /dev/$primary /usr/mdec/masterboot >/dev/null || exit # Partition the primary. partition /dev/$primary 1 81:$(ROOTSECTS)* 81:$homesize 81:0+ > /dev/null || exit echo "Creating /dev/$root for / .." mkfs /dev/$root || exit if test $nohome = 0 { if test ! $auto = r { echo "Creating /dev/$home for /home .." mkfs -B $blocksizebytes /dev/$home || exit } } else { echo "Skipping /home" } echo "Creating /dev/$usr for /usr .." mkfs -B $blocksizebytes /dev/$usr || exit if test $nohome = 0 { setglobal fshome = ""home=/dev/$home"" } else { setglobal fshome = ''"" } echo "" echo " --- Step 7: Wait for files to be copied -------------------------------" echo "" echo "All files will now be copied to your hard disk. This may take a while." echo "" mount /dev/$usr /mnt >/dev/null || exit # Mount the intended /usr. shell {cd /usr || exit 1 setglobal list = $[ls | fgrep -v install] for d in [$list] { cpdir -v $d /mnt/$d } } | progressbar $USRFILES || exit # Copy the usr floppy. umount /dev/$usr >/dev/null || exit # Unmount the intended /usr. mount /dev/$root /mnt >/dev/null || exit # Running from the installation CD. cpdir -vx / /mnt | progressbar $ROOTFILES || exit cp /mnt/etc/motd.install /mnt/etc/motd # Fix /var/log rm /mnt/var/log ln -s /usr/log /mnt/var/log # CD remnants that aren't for the installed system rm /mnt/etc/issue /mnt/CD /mnt/.* !2 >/dev/null echo >/mnt/etc/fstab "\ # Poor man's File System Table. root=/dev/$root usr=/dev/$usr $fshome>/mnt/etc/fstab "\ # Poor man's File System Table. root=/dev/$root usr=/dev/$usr $fshome" # National keyboard map. test -n $keymap && cp -p "/usr/lib/keymaps/$keymap.map" /mnt/etc/keymap umount /dev/$root >/dev/null || exit # Unmount the new root. mount /dev/$usr /mnt >/dev/null || exit # Make bootable. installboot -d /dev/$root /usr/mdec/bootblock /boot/boot >/dev/null || exit edparams /dev/$root "rootdev=$root; ramimagedev=$root; minix(1,Start MINIX 3) { image=/boot/image_big; boot; }; newminix(2,Start Custom MINIX 3) { unset image; boot }; main() { echo By default, MINIX 3 will automatically load in 3 seconds.; echo Press ESC to enter the monitor for special configuration.; trap 3000 boot; menu; }; save" || exit setglobal pfile = '"/mnt/src/tools/fdbootparams'" echo "rootdev=$root; ramimagedev=$root; save" >$pfile # Save name of CD drive setglobal cddrive = $[mount | grep usr | awk '{ print $1 }' | sed 's/p.*//] echo "cddrive=$cddrive" >>/mnt/etc/rc.package setglobal bios = $[echo $primary | sed -e 's/d./dX/g' -e 's/c.//g] if test ! $auto = "r" { if mount /dev/$home /home !2 >/dev/null { for u in [bin ast] { setglobal h = $[eval echo "~$u] if mkdir $h { echo " * Creating home directory for $u in $h" cpdir /usr/ast $h chown -R $u:operator $h } else { echo " * Couldn't create $h" } } umount /dev/$home } } echo "Saving random data.." dd if=/dev/random of=/mnt/adm/random.dat bs=1024 count=1 umount /dev/$usr >/dev/null || exit # Networking. echo "" echo " --- Step 8: Select your Ethernet chip ---------------------------------" echo "" mount /dev/$root /mnt >/dev/null || exit mount /dev/$usr /mnt/usr >/dev/null || exit /bin/netconf -p /mnt || echo FAILED TO CONFIGURE NETWORK umount /dev/$usr && echo Unmounted $usr umount /dev/$root && echo Unmounted $root echo " Please type 'shutdown' to exit MINIX 3 and enter the boot monitor. At the boot monitor prompt, type 'boot $bios', where X is the bios drive number of the drive you installed on, to try your new MINIX system. $biosdrivename This ends the MINIX 3 setup script. After booting your newly set up system, you can run the test suites as indicated in the setup manual. You also may want to take care of local configuration, such as securing your system with a password. Please consult the usage manual for more information. "