#!/bin/bash # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/bin/update-alx.sh,v 1.4 2006-02-20 14:49:30 niro Exp $ die() { echo echo "Error: $@. Update *not* successfull." exit 1 } diskfree() { local dev="$1" df -kP "${dev}" |grep "${dev}" | xargs | cut -d' ' -f4 } mount_server() { [ ! -d ${TEMPDIR} ] && install -d ${TEMPDIR} # use cifs only if supported modprobe cifs &> /dev/null if [ -n "$(cat /proc/filesystems | grep cifs)" ] then mount -t cifs "${SERVER_SHARE}" \ ${TEMPDIR} \ -o user="${USER}",pass="${PASS}" else # unix extensions must be enabled on server-side ! mount -t smbfs "${SERVER_SHARE}" \ ${TEMPDIR} \ -o username="${USER}",password="${PASS}" fi sleep 3 } umount_server() { umount ${TEMPDIR} sleep 3 [ -d ${TEMPDIR} ] && rm -rf ${TEMPDIR} } is_mounted() { local dev="$1" # the spaces are neccessary -> to locate " / " [ -n "$(cat /proc/mounts | grep " ${dev} ")" ] && return 0 return 1 } [[ $(whoami) != root ]] && ( echo "you must be r00t ..."; exit 1 ) source /etc/mage.rc source /etc/alxconfig-ng/config.rc # in kilobytes ! min 50MB are needed !! MIN_SPACE=50000 SERVER_SHARE="${SMB_UPDATE_HOST}" USER="${SMB_UPDATE_USER}" PASS="${SMB_UPDATE_PASS}" # setup mage.rc sed -i -e "s@^\(MIRRORS=\).*@\1\"${MAGE_MIRRORS}\"@" \ -e "s@^\(RSYNC=\).*@\1\"${MAGE_RSYNC}\"@" \ /etc/mage.rc || die "fixing /etc/mage.rc" if [ $(diskfree /) -le ${MIN_SPACE} ]; then echo "Mounting server '${SERVER_SHARE}' ..." # make a secure tmp dir if [ -x /bin/mktemp ]; then TEMPDIR="$(/bin/mktemp -d)" else TEMPDIR="/tmp/tmp-$$" fi # mount the server share to TEMPDIR mount_server # now fake a new builddir so that multiple clients # can use one server share install -d ${TEMPDIR}/${HOSTNAME}/{mage,packages,tmp} mount -o bind ${TEMPDIR}/${HOSTNAME}/tmp ${BUILDDIR} # mount -o bind ${TEMPDIR}/${HOSTNAME}/mage ${MAGEDIR} mount -o bind ${TEMPDIR}/${HOSTNAME}/packages ${PKGDIR} fi echo "Running update ..." # fetching new db echo "Fetching mage database update ..." mage update > /dev/null || die "mage update" ### demo hotfix### #cp /usr/mage/profiles/alx-041/* /etc/mage-profile #cp /usr/mage/fake/basesystem041-alx/basesystem041-alx-0.3-r1.mage \ # /usr/mage/fake/basesystem-alx/basesystem-alx-0.3-r1.mage #sed -i 's:PKGNAME="basesystem041-alx-0.3-${ARCH}-r1":PKGNAME="basesystem-alx-0.3-${ARCH}-r1":g' \ # /usr/mage/fake/basesystem-alx/basesystem-alx-0.3-r1.mage # an to be sure mount boot (kernel updates !) mount /boot &> /dev/null # first update mage mage install mage-alx || die "install mage" # than clean forcefully all packages that does not fit the profile if [ -f /etc/mage-profile/forced-uninstall ] then sh /etc/mage-profile/forced-uninstall fi # than update the whole system mageupgrade --no-calc --autoclean --autoanswer || die "system upgrade" #--debug # umount BUILDDIR if is_mounted ${BUILDDIR}; then umount ${BUILDDIR} fi # umount MAGEDIR if is_mounted ${MAGEDIR}; then umount ${MAGEDIR} fi if is_mounted ${PKGDIR}; then umount ${PKGDIR} fi # umount TEMPDIR if is_mounted ${TEMPDIR}; then umount_server fi ### check mage version for 0.>4.x-rxx #/sbin/mage version | egrep v0.[4-9].[0-9]-r??