#!/bin/sh # # (c) Eko M. Budi for Vector Linux # Released under GNU GPL echo "Install a Vector Linux CDROM from a Linux host" usage() { cat << EOF Usage: vinstall-cd [cdrom-device] If cdrom-device is not specified, the default is /dev/cdrom To run this program, please: - put the Vector Linux CDROM in the device - make a directory with enough space (around 10MB) - cd to that directory, then run this script EOF exit 0 } [ -z $1 ] && usage [ ! -f $1 ] && usage DEVICE=$1 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() { ## Mount the CDROM to get initrd.img umount $DEVICE 2>/dev/null mkdir -p loop umount loop &>/dev/null mount $DEVICE loop || error_exit "Cannot mount CDROM" ## Copy the initrd.img gunzip -c -S img loop/isolinux/initrd.img > $INSTALLRD || \ error_exit "cannot decompress initrd.img from the CDROM" ## Umount the DEVICE umount loop || \ error_exit "cannot umount $DEVICE" } 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" ## Mount the DEVICE inside mkdir -p loop/mnt/source mount $DEVICE loop/mnt/source || \ error_exit "cannot mount $DEVICE as source" ## 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