ViitorInstall/.function
kueller fffa1d84ca Kleine verbesserungen. bash -c statt source, sorgt dafÃr, das ein script abbruch nicht alles abbricht...
git-svn-id: svn://svn.compuextreme.de/Viitor/V962/ViitorInstall@5742 504e572c-2e33-0410-9681-be2bf7408885
2010-07-07 17:48:35 +00:00

434 lines
12 KiB
Bash
Executable File

#!/bin/bash
# bash Script Header der RainMaker MultiMedia OHG
# (c) 2001 by RainMaer MultiMedia OHG Bamberg
#
#$Author$
#$Date$
#$Revision$
#
#$Log$
#Revision 1.16 2006/07/17 19:45:34 kueller
#Aenderung beim mounten von /dev -> anpassung an udev im ersatz an devfs
#
#Revision 1.15 2006/06/24 08:48:29 kueller
#korrektur beim read aufruf (-r dass \ mit uebernommen und nicht interpretiert
#wird)
#
#Revision 1.14 2004/10/11 11:48:52 kueller
#Locale Abfrage nun auf Viitor_Install umgestellt
#
#Revision 1.13 2004/10/11 11:45:26 kueller
#Fehlerkorrektur bei der kernel und kernelmodule installation - es war
#noch der alte Pfad (/Monsum) eingestellt. ist nun auch auf /Viitor
#umgestellt
#
#Revision 1.12 2004/10/11 09:25:13 kueller
#Installation der Kernel Module nicht mehr mit cp sondern mit tar. Ausserdem
#CD Erkennung von Monsum in Viitor geändert.
#
#Revision 1.11 2004/10/11 08:50:06 kueller
#Anpassung an neues installpkg verhalten ungenuegend. Nummerierung erfolgt 2
#stellig. Fehler korrigiert
#
#Revision 1.10 2004/10/06 20:50:38 kueller
#Ausfuehrung der postinstallation scripts - speziell den spezialfall config -
#an neue version von installpkg angepasst
#
#Revision 1.9 2004/09/19 14:57:45 kueller
#An DVD Installation angepasst, so dass alle postinstall nach der eigentlichen
#installation ausgefuehrt werden.
#
#Revision 1.8 2002/08/13 20:01:16 hkueller
#while schleife zu read kommando vereinfacht
#
#Revision 1.7 2002/07/03 08:40:11 hkueller
#Unterstützung für ext3fs hinzugefügt
#
#Revision 1.6 2002/06/12 12:52:30 hkueller
#Installationsroutine make_base_install erweitert. getargsauswertung der
#Optionen, Verwendung unterschiedlicher pkg configurationen wird nun
#unterstützt. Standart ist BaseSystem.cfg mit installroot in /mnt
#mit -c können alternative .cfg Dateien angegeben werden. Mitgeliefert:
#All.cfg : installation aller Distributionsdateien
#Workstation.cfg: Normale Workstation Installation
#Ausserdem Localisierung der Installationroutine eingeführt
#
#Revision 1.5 2002/05/15 15:16:45 hkueller
#Installationsfunktion installpkg entfernt - wird nun durch neues installpkg
#script ersetzt
#
#Revision 1.4 2002/02/11 15:25:08 hkueller
#Korrektur der Kernel Installation - nicht vmlinuz (boot Kernel für CD) sondern
#vmlinuz.inst und System.map.inst muessen installiert werden
#(installation Kernel)
#
#Revision 1.3 2002/02/08 01:52:42 hkueller
#Verzeichniss angaben der aktuellen CD Strucktur angepasst (Kernel Installation
#suchte noch unter /RMMLinux die Daten)
#Damit sollte der lästige Fehler in den Kernelmodulen nach der Installation
#der Vergangenheit angehören
#
#Revision 1.2 2001/10/08 22:50:51 kueller
#Anzeige beim Kopieren der Module ausgeschalten
#
#Revision 1.1 2001/09/24 14:33:30 kueller
#Neustart wg. datenverlust
#
#Revision 1.2 2001/08/25 20:52:43 kueller
#
#Statusmeldungen an die neue Monsum Version angepasst
#
#Revision 1.1.1.1 2001/08/06 22:09:47 kueller
#Aufnahme in CVS Überwachung
#
#
COL=70
SET_COL="echo -en \\033[${COL}G"
NORMAL="echo -en \\033[0;39m"
SUCCESS="echo -en \\033[1;42m"
FAILURE="echo -en \\033[1;41m"
print_status(){
if [ $# = 0 ]
then
echo "Usage: print_status {success|failure}"
exit 1
fi
case "$1" in
success)
$SET_COL
$SUCCESS
echo -n " READY "
$NORMAL
echo ""
;;
failure)
$SET_COL
$FAILURE
echo -n " FAILED "
$NORMAL
echo ""
;;
esac
}
print() {
STRING=$1
shift
printf "`gettext -d Viitor_Install "$STRING"`\n" $*
}
make_FileSystem() {
KONFIG=$1
DEST=$2
MOUNTPOINTS=""
cat $KONFIG/fstab|awk '{print $1":"$2":"$3":"$4":"$5":"$6}' >/tmp/fstab
for i in `cat /tmp/fstab`; do
MOUNTPOINTS="$MOUNTPOINTS `echo $i|cut -d ":" -f 2`"
if [ "reiserfs" == `echo $i |cut -d ":" -f 3` ]; then
case "`echo $i|cut -d ":" -f 2`" in
"/")
ROOT=`echo $i|cut -d ":" -f 1`
yes|mkreiserfs $ROOT
;;
"/usr")
USR=`echo $i|cut -d ":" -f 1`
yes|mkreiserfs $USR
;;
"/opt")
OPT=`echo $i|cut -d ":" -f 1`
yes|mkreiserfs $OPT
;;
"/var")
VAR=`echo $i|cut -d ":" -f 1`
yes|mkreiserfs $VAR
;;
esac
fi
if [ "xfs" == `echo $i |cut -d ":" -f 3` ]; then
case "`echo $i|cut -d ":" -f 2`" in
"/")
ROOT=`echo $i|cut -d ":" -f 1`
mkfs.xfs -f $ROOT
;;
"/usr")
USR=`echo $i|cut -d ":" -f 1`
mkfs.xfs -f $USR
;;
"/opt")
OPT=`echo $i|cut -d ":" -f 1`
mkfs.xfs -f $OPT
;;
"/var")
VAR=`echo $i|cut -d ":" -f 1`
mkfs.xfs -f $VAR
;;
esac
fi
if [ "ext2" == `echo $i |cut -d ":" -f 3` ]; then
case "`echo $i|cut -d ":" -f 2`" in
"/")
ROOT=`echo $i|cut -d ":" -f 1`
mkfs $ROOT
;;
"/usr")
USR=`echo $i|cut -d ":" -f 1`
mkfs $USR
;;
"/opt")
OPT=`echo $i|cut -d ":" -f 1`
mkfs $OPT
;;
"/var")
VAR=`echo $i|cut -d ":" -f 1`
mkfs $VAR
;;
esac
fi
if [ "ext3" == `echo $i |cut -d ":" -f 3` ]; then
case "`echo $i|cut -d ":" -f 2`" in
"/")
ROOT=`echo $i|cut -d ":" -f 1`
mkfs -t ext3 $ROOT
;;
"/usr")
USR=`echo $i|cut -d ":" -f 1`
mkfs -t ext3 $USR
;;
"/opt")
OPT=`echo $i|cut -d ":" -f 1`
mkfs -t ext3 $OPT
;;
"/var")
VAR=`echo $i|cut -d ":" -f 1`
mkfs -t ext3 $VAR
;;
esac
fi
if [ "swap" == `echo $i | cut -d ":" -f 3` ]; then
case "`echo $i|cut -d ":" -f 2`" in
"swap")
SWAP=`echo $i|cut -d ":" -f 1`
print "Initializing swap on %b" $SWAP
mkswap -c $SWAP
swapon $SWAP
;;
esac
fi
done
$DEBUG mount $ROOT $DEST
if [ -n $OPT ]; then
mkdir $DEST/opt
mount $OPT $DEST/opt
fi
if [ -n $USR ]; then
mkdir $DEST/usr
mount $USR $DEST/usr
fi
if [ -n $VAR ]; then
mkdir $DEST/var
mount $VAR $DEST/var
fi
for i in $MOUNTPOINTS; do
if [ ! -d $DEST/$i ] && [ ! "$i" == "swap" ]; then
mkdir $DEST/$i
fi
done
}
gen_name() {
basename $1|sed -e "s/\.tbz//"
}
install_kernel() {
if [ -f /boot/vmlinuz ] && [ ! -f /Viitor/VERSION ]; then
print "installing available system kernel"
$DEBUG cp /boot/vmlinuz $1/boot/vmlinuz
$DEBUG cp /boot/System.map $1/boot/System.map
if [ -f /boot/vmlinuz.old ]; then
$DEBUG cp /boot/vmlinuz.old $1/boot/vmlinuz.old
$DEBUG cp /boot/System.old $1/boot/System.old
fi
print_status success
print "installing available kernel modules"
$DEBUG mkdir $1/lib/modules
cd /lib/modules
tar -cf - `uname -r`|\
tar -C $1/lib/modules -xf -
cd -
print_status success
else
print "No kernel found"
print "installing standard kernel"
print "Kernel installation:"
$DEBUG cp /boot/vmlinuz $1/boot/vmlinuz.viitor
$DEBUG cp /boot/initrd.gz $1/boot/initrd.gz
$DEBUG cp /Viitor/boot/System.map $1/boot/System.map
if [ ! -d $1/lib/modules ]; then
mkdir $1/lib/modules
fi
cd $1/lib/modules
tar -zxf /Viitor/boot/modules.tgz
print_status success
fi
}
FindHDDev() {
PART=$1
DEVICE=`basename $PART`
DEVICE=`find /sys/block/[sh]d? -name $DEVICE`
if [ ${DEVICE} ]; then
DEVICE=`dirname $DEVICE`
basename $DEVICE
fi
}
make_boot() {
INSTROOT=$1
INSTROOT=`echo $INSTROOT|sed -e "s%/$%%"`
$DEBUG mount -o bind /dev $INSTROOT/dev
$DEBUG mount -t proc none $INSTROOT/proc
ROOTPART=`mount|grep "on $INSTROOT "|awk '{print $1}'`
ROOTPART=`basename $ROOTPART`
ROOTDEV=`FindHDDev $ROOTPART`
sed -e "s/^\(boot=\/dev\/\)<YourBootDev>/\1$ROOTDEV/" \
-e "s/^.*\(root = \/dev\/\)<YourBootPartition>/\1$ROOTPART/" \
$INSTROOT/etc/lilo.conf >/tmp/lilo.conf
mv /tmp/lilo.conf $INSTROOT/etc/lilo.conf
print "Add $ROOTPART to your lilo.conf as ViitorOrginal"
WINNTPART=`fdisk -l /dev/hda|sed -e "s/\*//" |awk '{ if ( $5 == "7" ) print $1}'`
if [ ${WINNTPART} ]; then
WINNTPART=`basename $WINNTPART`
WINNTHD=`FindHDDev $WINNTPART`
sed -e "s/#\(other = \/dev\/\).*$/\1$WINNTPART/" \
-e "s/#.*\(\label = \)windows/ \1WinNT/" \
-e "s/#.*\(table = \/dev\/\).*$/ \1$WINNTHD/" \
$INSTROOT/etc/lilo.conf >/tmp/lilo.conf
mv /tmp/lilo.conf $INSTROOT/etc/lilo.conf
print "Add $WINNTHD as WinNT boot to your lilo.conf"
fi
if [ ! -f $INSTROOT/tmp/NOQUEST ]; then
print "You can now switch to the new System and edit your lilo.conf"
print "by the way to install a new kernel, or build a new kernel"
print "if you say \"no\", this script will install the CD Boot Kernel"
print "with special boot support for HD"
print "Would you like to edit your lilo.conf ?[Y/n]"
read
if [ ! "$REPLY" == "y" ]; then
$DEBUG chroot $INSTROOT /sbin/lilo
else
print "The root is now changed to the new System for this task"
$DEBUG chroot $INSTROOT /usr/bin/env -i HOME=/root TERM=$TERM /bin/bash --login
fi
$DEBUG umount $INSTROOT/dev
$DEBUG umount $INSTROOT/proc
print "your System is now installed. please remove the CD/DVD"
print "and reboot your System"
fi
}
install_cluster() {
CFGFILE=$1
INSTALLROOT=$2
INSTSOURCE=$3
sed -e "/^#/d" -e "/^ *$/d" $CFGFILE >/tmp/install$$
NUMOFPKG=`cat /tmp/install$$|wc -l`
exec 3</tmp/install$$
if [ ! -z ${NO_DEV} ]; then
INSTOPT="${INSTOPT} -e"
fi
if [ ! -z ${NO_MAN} ]; then
INSTOPT="${INSTOPT} -a"
fi
while read -r <&3 INSTCD PKGPATH SHNAME; do
echo -n "$NUMOFPKG: "
INSTPKG=`grep "SN=$SHNAME;.*PP=$PKGPATH\$" $INSTSOURCE/$PKGLIST|awk -F";" '{print $2}'|sed -e "s/PF=//"`
if [ "$INSTCD" == "Boot" ]; then
installpkg ${INSTOPT} -m $INSTALLROOT -doi $INSTSOURCE/$PKGPATH/$INSTPKG
else
echo "$INSTCD $INSTPKG" >>$INSTALLROOT/var/install/pkg_to_do
fi
(( NUMOFPKG-- ))
done
if [ -f $INSTALLROOT/root/.bash_profile ]; then
cp $INSTALLROOT/root/.bash_profile $INSTALLROOT/root/.bash_profile.store
fi
if [ -f $INSTALLROOT/tmp/afterinstall/[0-9][0-9].config-[0-9]*.postinstall ]; then
source $INSTALLROOT/tmp/afterinstall/[0-9][0-9].config-[0-9]*.postinstall $INSTALLROOT
rm $INSTALLROOT/tmp/afterinstall/[0-9][0-9].config-[0-9]*.postinstall
fi
echo "export INSTROOT=$INSTALLROOT" >>$INSTALLROOT/root/.bash_profile
echo "cd /" >>$INSTALLROOT/root/.bash_profile
echo "ldconfig" >>$INSTALLROOT/root/.bash_profile
echo "chmod 1777 tmp" >>$INSTALLROOT/root/.bash_profile
echo "if [ -d /tmp/afterinstall ]; then" >>$INSTALLROOT/root/.bash_profile
echo "for i in /tmp/afterinstall/*; do" >>$INSTALLROOT/root/.bash_profile
echo "chmod 755 \$i" >>$INSTALLROOT/root/.bash_profile
echo "bash -c \$i /" >>$INSTALLROOT/root/.bash_profile
echo "cd - >/dev/null" >>$INSTALLROOT/root/.bash_profile
echo "rm \$i" >>$INSTALLROOT/root/.bash_profile
echo "done" >>$INSTALLROOT/root/.bash_profile
echo "rm -r /tmp/afterinstall" >>$INSTALLROOT/root/.bash_profile
echo "fi" >>$INSTALLROOT/root/.bash_profile
echo "exit" >>$INSTALLROOT/root/.bash_profile
mknod $INSTALLROOT/dev/console c 5 1
mknod $INSTALLROOT/dev/null c 1 3
mkdir $INSTALLROOT/media
mount -o bind /dev $INSTALLROOT/dev
mount -o bind /proc $INSTALLROOT/proc
chroot $INSTALLROOT /usr/bin/env -i HOME=/root TERM=$TERM /bin/bash --login
if [ -f "$INSTALLROOT/root/.bash_profile" ]; then
mv $INSTALLROOT/root/.bash_profile.store $INSTALLROOT/root/.bash_profile
fi
umount $INSTALLROOT/proc
umount $INSTALLROOT/dev
}
ScanInstalledPackages() {
ALLPACKAGES=$1
OUTFILE=$2
cat /var/install/contents|\
awk -F";" '{print $1}'|\
sort -u|\
sed -e "s/^PN=//" >/tmp/allprogs$$
if [ ! -f $ALLPACKAGES ]; then
echo "$ALLPACKAGES not found"
exit 10
fi
exec 3< $ALLPACKAGES
while read -r <&3 CDROM PKGPATH PACKAGE; do
if grep -q $PACKAGE /tmp/allprogs$$; then
echo "$CDROM $PKGPATH $PACKAGE"
echo "$PACKAGE" >>/tmp/foundprogs$$
fi
done >$OUTFILE
exec 3>&-
for i in `cat /tmp/allprogs$$`; do
if ! grep -q "${i}" /tmp/foundprogs$$; then
if [ ! "$i" == "tmp" ]; then
echo $i
fi
fi
done
rm /tmp/allprogs$$
rm /tmp/foundprogs$$
}
FindDiskDevices() {
for i in `\ls /dev/{h,s}d? 2>/dev/null`; do
DEVNAME=`basename $i`
if [ "`cat /sys/block/$DEVNAME/device/type 2>/dev/null`" == "0" ] || \
[ "`cat /sys/block/$DEVNAME/device/media 2>/dev/null`" == "disk" ] ; then
if [ "`cat /sys/block/$DEVNAME/removable 2>/dev/null`" == "0" ]; then
echo $DEVNAME
fi
fi
done
}