#!/bin/bash # # $Id: modified-iso-install,v 1.3 2008/05/17 07:00:42 suter Exp $ # Copyright (C) 2003 Mark Suter # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## Our "die" function (think perl) function die () { echo "$@" 1>&2 ; exit 1 ; } ## Test for needed binaries hash test perl date cat sfdisk mkfs mkswap mkdir mount umount gzip cpio chmod sync chroot || die $0: required binaries not present ## Record our starting time start=$( date +%s ) ## Find the first disk disk=$( perl -ne 'm{ [hs] d [a-z] $ }x and print $& and exit' /proc/partitions ) ## Are you sure? test "$( id -u )" == "0" || die $0: script must be run as root cat <&2 ################################################################# This script will repartition /dev/$disk and install a base system. You will lose all existing data on that hard disk drive. Enter "Execute" at the prompt below to proceed. EOF while [ "${resp}" != "Execute" ] ; do read -p "? " resp done cat <&2 Proceeding with installation... ################################################################# EOF ## Exit on any error, display the commands set -x -e ## Partition the disk, according to size gib=$( grep ${disk}\$ /proc/partitions | perl -ane 'print int $F[2] / 2** 20' ) if [ $gib -ge 20 ] ; then echo -e "0,5120\n,2048,S\n,10240\n;" | sfdisk -uM /dev/$disk || die $0: partitioning failed elif [ $gib -ge 10 ] ; then echo -e "0,2048\n,1024,S\n,3072\n;" | sfdisk -uM /dev/$disk || die $0: partitioning failed elif [ $gib -ge 5 ] ; then echo -e "0,1024\n,1024,S\n,1536\n;" | sfdisk -uM /dev/$disk || die $0: partitioning failed else die $0: first disk seems too small at approx $gib GiB - try manually installing fi ## Make the filesystems mkfs -t ext3 -L root -O filetype /dev/${disk}1 mkswap /dev/${disk}2 mkfs -t ext3 -L var -O filetype /dev/${disk}3 mkfs -t ext3 -L home -O filetype /dev/${disk}4 ## Mount the new system mkdir -p /ebbe mount /dev/${disk}1 /ebbe mkdir -p /ebbe/{var,home} mount /dev/${disk}3 /ebbe/var mount /dev/${disk}4 /ebbe/home ## Copy the files over (or from an existing server using ssh?) # ( cd /ebbe ; ssh XXX cd / \; find . -print0 \| cpio --null --format=crc --create | cpio --make-directories --preserve-modification-time --extract ) ( cd /ebbe ; gzip -dc /mnt/cdrom/ebbe.cpio.gz | cpio --make-directories --preserve-modification-time --extract ) ## Make the system bootable (chroot to avoid library problems) sync ; sync ; sync chroot /ebbe /usr/sbin/grub --batch --device-map=/dev/null <&2 ################################################################# Done in ${elapsed}s with the newly prepared system now under /ebbe for you to examine, then reboot and remove the cd. ################################################################# EOF