#!/bin/sh # # (c) Eko M. Budi for Vector Linux # Released under GNU GPL echo "Install Vector Linux from a Linux host." usage() { cat << EOF vinstall - boot a Vector Linux install image Usage: vinstall [initrd.img] If not specified, initrd.img must exist in the current directory. You may get the initrd.img from Vector Linux FTP site or CDROM under isolinux/ directory Make sure you have the Vector Linux media, either: - a partition with /veclinux directory on it. - a Vector Linux install CDROM (but try vinstall-cd instead) - a partition with vl*.iso file on it (but try vinstall-iso). EOF exit 0 } INITRD=${1:-initrd.img} [ ! -f $INITRD ] && usage INSTALLRD="initrd.vinstall" error_exit () { echo "ERROR: $1" # umount loop/source 2>/dev/null && sleep 1 umount loop 2>/dev/null && sleep 1 rm -f $INSTALLRD 2>/dev/null exit 1 } check_user() { [ "$UID" = "0" ] && return 0 cat << EOF ERROR: must run as root Please login as root or call su first EOF exit 1 } check_console() { [ -z "$DISPLAY" ] && return 0 cat << EOF ERROR: It is a bad idea to install from a GUI. Remember these steps (write it on a paper): 1. Quit from this GUI 2. Drop to a console (press Crtl-Alt-F1) 3. Login as root 4. Switch to runlevel 2 (init 2) 5. Go to my directory (cd $PWD) 6. Call me again ($0 $@) EOF exit 1 } check_runlevel() { RUNLEVEL=`runlevel | cut -f2 -d ' '` case "$RUNLEVEL" in 1|2|3) return 0 ;; esac cat << EOF ERROR: The system is not running on runlevel 2, or 3 For stability reason, use vinstall on runlevel 2, or 3. To switch into the appropriate runlevel, you may: - call "init 2" after this, or - reboot this Linux with "linux 2" parameter EOF exit 1 } check_mount() { if mount | grep -v 'on / ' | grep -qe '^/dev'; then echo echo "WARNING: these partitions are mounted:" mount | grep -e '^/dev' cat < Press to continue or - to cancel. EOF read pause fi } get_initrd() { ## prepare loop dir ## Copy the initrd.img gunzip -c -S img $INITRD > $INSTALLRD || \ error_exit "cannot decompress $INITRD" } do_install() { ## Check validity file $INSTALLRD | grep -q "ext2 filesystem" || \ error_exit "invalid initrd file" ## Mount the initrd mount -o loop $INSTALLRD loop || \ error_exit "cannot mount initrd file" ## Check if this is the right initrd [ -f loop/usr/sbin/setup ] || \ error_exit "initrd contains no setup program" ## Mount the /proc inside mkdir -p loop/proc mount -o bind /proc loop/proc || \ error_exit "cannot mount /proc filesystem" mkdir -p loop/sys mount -o bind /sys loop/sys || \ error_exit "cannot mount /sys filesystem" mkdir -p loop/dev mount -o bind /dev loop/dev || \ error_exit "cannot mount /dev directory" ## Make a fake mtab ROOT_DEV=`mount | grep -e 'on / ' | cut -f 1 -d ' '` echo "$ROOT_DEV / auto defaults 0 1 > loop/etc/mtab echo "none /proc proc defaults 0 1 > loop/etc/mtab ## prepare the excluded partitions EXCLUDE_PARTITIONS="" for PART in `mount | grep -e '^/dev' | cut -f1 -d ' '`; do EXCLUDE_PARTITIONS="$EXCLUDE_PARTITIONS $PART" done export EXCLUDE_PARTITIONS ## HERE WE GO .... chroot loop /usr/sbin/setup --hosted ## Welcomeback if [ $? = 255 ]; then clear echo "Installation has finished ..." echo "You may reboot the computer to start using Vector Linux" else clear echo "Hmmm, did the installer make it ?" echo "If yes, you may reboot the computer" fi ## Cleanup #umount loop/mnt/source 2> /dev/null #sleep 1 umount loop/dev 2> /dev/null sleep 1 umount loop/sys 2> /dev/null sleep 1 umount loop/proc 2> /dev/null sleep 1 umount loop 2> /dev/null sleep 1 rm -f $INSTALLRD exit 0 } ################################################ # Main program check_user check_console check_runlevel check_mount get_initrd do_install