#! /bin/bash # Focus: # - configure package repository # - configure proxy settings # Goal: # - apt/yast possible # read additional information from the environment or from the # identityfile, values given in identityfile have preference! # this file must contain: # OS_TYPE - which OS to install (Debian, Ubuntu, SuSE?) # OS_VERS - which version to install? (etch, lenny, sid, hardy, 10SP2) # OS_ARCH - x86_32 or x86_64? if [ -r ${IDENTITYFILE} ] ; then source ${IDENTITYFILE} else echo "Identity file not readable. Exiting" exit fi # helper toLower() { echo $1 | tr "[:upper:]" "[:lower:]" } # if skiptask is not defined, then the original prepareapt task will be run # at the end and any changes to /etc/apt/... will be overwritten by the files # from the nfsroot!! skiptask prepareapt # rewriting the original prepareapt hook # ftp and http needs resolv.conf in chroot environment, /etc/hosts is useful # think about using fcopy for these two files [ -f /etc/resolv.conf ] && cp /etc/resolv.conf $FAI_ROOT/etc [ -f /etc/hosts ] && cp /etc/hosts $FAI_ROOT/etc # set hostname in $FAI_ROOT if [ -f /var/run/fai/FAI_INSTALLATION_IN_PROGRESS ]; then # check whether my hostname is faiclient-... # if it is, then it's just a placeholder and we have to fetch the # real name from the identity file NAMEOLD=$(hostname) NAMESHORT=$(echo ${NAMEOLD}|cut -d"-" -f1) if [[ ${NAMESHORT} = "host" || ${NAMESHORT} = "faiclient" ]] ; then # update the kernel's view on this echo ${HOSTNAME} > /proc/sys/kernel/hostname echo ${DOMAIN} > /proc/sys/kernel/domainname fi # $HOSTNAME / $DOMAIN now contain the correct values # Step a - set the hostname if [[ ${OS_TYPE} == "Debian" || ${OS_TYPE} == "Ubuntu" ]] ; then echo ${HOSTNAME} > ${target}/etc/hostname elif [[ ${OS_TYPE} == "SLES" ]] ; then echo ${HOSTNAME}.${DOMAIN} > ${target}/etc/HOSTNAME fi # Step b - update /etc/hosts HOSTSTEMPLATE="${FAI}/files/templates/hosts.tmpl" HOSTSFILE="${target}/etc/hosts" # replace PLACEHOLDER with our own ip/name. Keep the nice header and the ipv4/ipv6 localhost footer sed -e "s/^PLACEHOLDER/${IPADDR}\t\t${HOSTNAME}.${DOMAIN}\t${HOSTNAME}/" ${HOSTSTEMPLATE} > ${HOSTSFILE} # Step c - rewrite /etc/resolv.conf # damned either way # a) configure dhcpd / option domain-name to provide the searchlist - which breaks MacOS et al, # since they only expect 1 value - the domainname # b) configure dhcpd to provide the search list via option 119 - which may # or may not be picked up correctly by dhcp-client # let's go for the safeguard. If /etc/resolv.conf contains "search", then use this # if not, then check for a variable SEARCHLIST and replace a possible "domain" setting if [ -z $(grep "^search" /etc/resolv.conf) ] ; then # a line containing a searchlist has been found # use this file and copy it cp /etc/resolv.conf ${target}/etc/resolv.conf else # no such line has been found, check if a searchlist # was requested and rewrite the file accordingly if [ x${SEARCHLIST} != x ] ; then echo "search ${SEARCHLIST}" > ${target}/etc/resolv.conf grep "^nameserver" /etc/resolv.conf >> ${target}/etc/resolv.conf else # no searchlist specified, just copy it cp /etc/resolv.conf ${target}/etc/resolv.conf fi fi fi ## during normal installation, we need a valid sources.list if [ $do_init_tasks -eq 1 ] ; then if [[ ${OS_TYPE} == "Debian" || ${OS_TYPE} == "Ubuntu" ]] ; then if [[ $FAI_ALLOW_UNSIGNED = 1 ]]; then echo "APT::Get::AllowUnauthenticated \"true\";" > $FAI_ROOT/etc/apt/apt.conf.d/10fai echo "Aptitude::CmdLine::Ignore-Trust-Violations yes;" >> $FAI_ROOT/etc/apt/apt.conf.d/10fai fi # sources.list contains the placeholder OSVERS, replace it while copying. sed -e "s/OSVERS/${OS_VERS}/" $FAI/files/etc/apt/sources.list_${OS_TYPE} > $target/etc/apt/sources.list # a local package mirror may be available if [[ ${LOCALMIRROR} != "" ]] ; then tmpfile=$(mktemp -p $target/tmp/) # Debian Sources: # http://ftp.[de.]debian.org/debian OSVERS -> $MIRROR/debian # http://security.debian.org/debian-security OSVERS/updates -> $MIRROR/debian-security # Ubuntu Sources: # http://[de.]archive.ubuntu.com/ubuntu OSVERS -> $MIRROR/ubuntu # http://security.ubuntu.com/ubuntu OSVERS-security -> %MIRROR/ubuntu-security # last sed removes any double dashes, that are not part of http:// cat ${target}/etc/apt/sources.list | \ sed -e "s#http://ftp.*debian\.org/debian#${LOCALMIRROR}debian/#g" | \ sed -e "s#http://security\.debian\.org/debian-security#${LOCALMIRROR}/debian-security/#g" | \ sed -e "s#http://.*archive\.ubuntu\.com/ubuntu#${LOCALMIRROR}/ubuntu/#g" | \ sed -e "s#http://security\.ubuntu\.com/ubuntu#${LOCALMIRROR}/ubuntu-security/#g" | \ sed -e "s#\([a-zA-Z0-9]\)//#\1/#g" > ${tmpfile} cp ${tmpfile} /tmp/fai/sources.list mv ${tmpfile} ${target}/etc/apt/sources.list fi if [[ -n ${LOCALREPO} ]] ; then echo "Configuring local repository: ${LOCALREPO}" REPOSTRING=$(toLower "${OS_TYPE} ${OS_VERS} main") echo "deb ${LOCALREPO}/$REPOSTRING" >> $target/etc/apt/sources.list.d/local.list fi elif [[ ${OS_TYPE} == SLES ]] ; then # additional work for SLES if [[ ${LOCALREPO} != "" ]] ; then echo "Configuring local repository: ${LOCALREPO}" #TODO: call zypper echo "WARN: Not implemented yet!" fi # supply additional mountpoints (SLES11) echo "" >> ${target}/etc/fstab echo "proc /proc proc defaults 0 0" >> ${target}/etc/fstab echo "sysfs /sys sysfs noauto 0 0" >> ${target}/etc/fstab echo "debugfs /sys/kernel/debug debugfs noauto 0 0" >> ${target}/etc/fstab echo "devpts /dev/pts devpts mode=0620,gid=5 0 0" >> ${target}/etc/fstab echo "" >> ${target}/etc/fstab # needed for mkinitrd and package suspend (at least in SLES11) mount --bind /dev ${target}/dev mount -t tmpfs none ${target}/dev/shm # else kernel install throws a warning modprobe dm-mod fi fi