#!/bin/bash # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/bin/update-alx-new.sh,v 1.1 2005-12-15 08:27:49 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 # defaults if nothing was given # in kilobytes ! min 50MB are needed !! #MIN_SPACE=50000 #SERVER_SHARE="//${SQL_HOST}/magetmp" #USER="${SQL_USER}" #PASS="${SQL_PASS}" usage() { echo echo "Usage: $(basename $0) [command] [arg] ..." echo echo "Required settings:" echo " short long opts" echo echo " -h --help shows this help" echo " -u --user smb username used to connect to server" echo " -p --pass smb password used to connect to server" echo " -s --server-share smb server share //server/share" echo " -m --min-space sets minimal space needed to updare without a server" echo echo "Optional settings" echo " -p --proxy proxy-server which will used by mage (ftp & http)" echo " --ftp-proxy force a specific ftp proxy server" echo " --http-proxy force a specific http proxy server" echo " --no-proxy list of addresses to exclude from proxy list" echo echo " -o --mirrors list of alx package mirrors" echo " -h --rsync rsync server which contains the mage db updates" echo " -f --profile select the mage-profile used for upgrade" echo exit 1 } # exit if no param was given # very basic getops for i in $* do case $1 in --user|-u) shift; USER="$1" ;; --pass|-p) shift; PASS="$1" ;; --server-share|-s) shift; SERVER_SHARE="$1" ;; --min-space|-m) shift; MIN_SPACE="$1" ;; --proxy|-p) shift; http_proxy="$1"; ftp_proxy="$1" export http_proxy ftp_proxy ;; --ftp-proxy) shift; export ftp_proxy="$1" ;; --http-proxy) shift; export ftp_proxy="$1" ;; --no-proxy) shift; export no_proxy="$1" ;; --mirrors|-o) shift; MIRRORS="$1" if [ -n "$(grep -ir MIRRORS /etc/mage.rc)" ] then # remove dash if exists sed -i -e "s:#.*MIRRORS=:MIRRORS=:g" /etc/mage.rc # modify the mirrors sed -i -e "s:^\(MIRRORS=\).*:\1\"${MIRRORS}\":g" /etc/mage.rc else echo "MIRRORS=\"${MIRRORS}\"" >> /etc/mage.rc fi ;; --rsync|-r) shift; RSYNC="$1" if [ -n "$(grep -ir RSYNC /etc/mage.rc)" ] then # remove dash if exists sed -i -e "s:#.*RSYNC=:RSYNC=:g" /etc/mage.rc # modify the mirrors sed -i -e "s:^\(RSYNC=\).*:\1\"${RSYNC}\":g" /etc/mage.rc else echo "RSYNC=\"${RSYNC}\"" >> /etc/mage.rc fi ;; --profile|-f) shift; ln -snf ${MAGEDIR}/profiles/$1 /etc/mage-profile ;; --help|-h) usage ;; esac shift done # sanity checks; abort if not given [ -z "${USER}" ] && usage [ -z "${PASS}" ] && usage [ -z "${SERVER_SHARE}" ] && usage [ -z "${MIN_SPACE}" ] && usage 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" # 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