#!/bin/bash
# Focus:
# -
# -
# Goal:
# -
# choose the correct repository depending on the environment
if ifclass OS_SLES ; then
#### Preparations ####
# all environment variables starting with this string are recognised as
# software repositories (compare '[...]/class/44-repository')
REPOVARID="SUSEREPOSITORY"
# read additional information from the environment
# OS_VERS - which version to install? (etch, lenny, sid, hardy, 10SP2)
# OS_ARCH - x86_32 or x86_64?
# WARNING
# while this script supports cases where zypper is not available it's
# very fragile to manually edit the repository database and should only
# be used in cases where zypper isn't available, e.g. on SuSE Linux
# Enterprise Server 10 without (at least) service pack 2!
#
# caveat: without zypper only $SUSEREPOSITORY is used
# WARNING
#### Preparations complete #####
if [ -n "$(env|grep "^${REPOVARID}")" ] ; then
if [ -e ${target}/usr/bin/zypper ] ; then
echo "Using zypper to add a new repository."
# remove old repositories
if [ -d ${target}/var/lib/zypp/db ] ; then
echo "NOTICE: Old repository data found. Removing."
rm -rf ${target}/var/lib/zypp/db
fi
# zypper options differ between SLES10SP2 and SLES11
# up to SLES10SP1 -> no zypper available
# SLES10 SP2 (v0.6) -> zypper service-add / service-list
# SLES11 GA -> zypper addrepo / repos
#
# TODO: Get rid of cut
ZYPPERVERS=$(${ROOTCMD} zypper -V 2>&1|cut -d" " -f2|sed -r -e "s'\.[0-9]+$''g")
case ${ZYPPERVERS} in
0.6)
echo " legacy mode, using old zypper options"
REPOADD="service-add"
REPOLIST="service-list"
;;
*)
echo " defaulting to new zypper options"
REPOADD="addrepo --refresh"
REPOLIST="repos"
;;
esac
REPOVARS=$(env|grep "^${REPOVARID}"|cut -d"=" -f1)
for REPOVAR in ${REPOVARS} ; do
eval REPO=\$${REPOVAR}
echo " found ${REPOVAR} -> ${REPO}"
REPOID=$(echo ${REPOVAR}|sed -e "s'^${REPOVARID}''")
if [ -n ${REPO} ] ; then
${ROOTCMD} zypper -n ${REPOADD} ${REPO} ${OS_VERS}-${OS_ARCH}${REPOID}
fi
done
${ROOTCMD} zypper ${REPOLIST}
INSTCMD="${ROOTCMD} zypper -n install"
else
echo "Couldn't find zypper. Manually editing repository files."
for file in $(ls ${target}/var/lib/zypp/db/sources/*) ; do
sed -i -e "s#.*#${SUSEREPOSITORY}#" ${file}
done
INSTCMD="${ROOTCMD} yast -i"
fi
else
echo "WARN: Can't update SuSE repository information. \'${REPOVARID}*\' is empty!"
fi
# This doesn't really belong here, but I need this update, before
# instsoft is run and the kernel is installed. While installing the
# kernel the initrd is built and I don't want to do it a second time.
# ToDo: make this snippet aware of the disk-layout file and choose the root-fs module appropriately
if [ -e ${target}/etc/sysconfig/kernel ] ; then
MODULES=" ext3"
source /tmp/fai/disk_var.sh
if [ $(echo $ROOT_PARTITION|cut -f1-3 -d "/") = "/dev/cciss" ] ; then
MODULES="${MODULES} cciss"
fi
sed -i -e "s/^INITRD_MODULES=\"\(.*\)\"$/INITRD_MODULES=\"\1 ${MODULES}\"/" ${target}/etc/sysconfig/kernel
else
echo "SysconfigKernel NOT found! Have a look at this." && exit 800
fi
# some additional work is necessary
# else the kernel package won't properly install
if [ x"$(mount|grep ${target}/proc)" = x ] ; then
mount -t proc none ${target}/proc
fi
if [ x"$(mount|grep ${target}/sys)" = x ] ; then
mount -t sysfs none ${target}/sys
fi
if [ ! -e ${target}/dev/fd ] ; then
ln -s /proc/self/fd ${target}/dev/
fi
if [ ! -e ${target}/dev/pts ] ; then
mkdir ${target}/dev/pts
fi
mount -t devpts none ${target}/dev/pts
# don't need the debian stuff anymore
skiptask updatebase
fi