#!/bin/bash # $Id$ # get a suitable environment source /etc/profile PATH="/etc/mage-profile:${PATH}" MAGERC="/etc/mage.rc" MAGEPROFILE="alx-060" NEW_MAGE_DISTRIBUTION="unstable" #NEW_RSYNC="rsync://magellan-linux.de/mage-alx-0.6.0" #NEW_MIRRORS="http://magellan-linux.de/magellan/alx-0.6.0/${NEW_MAGE_DISTRIBUTION}" NEW_RSYNC="rsync://128.20.41.110/mage-alx-060" NEW_MIRRORS="http://128.20.41.110/magellan/alx-060" NEW_PACKAGES_SERVER_PATH='packages/${ARCH}' NEW_MAGE_UNINSTALL_TIMEOUT=0 CONFIGRC="/etc/alxconfig-ng/config.rc" NEW_ALX_NETWORKING="dhcp" NEW_ALX_DHCP_PROG="/sbin/udhcpc" NEW_ALX_DHCP_START="-T 10 -t 5 -n -i" NEW_ALX_DHCP_STOP="" NEW_MIN_DISK_SPACE="85000" NEW_ALX_PLUGINS="/usr/lib/alxconfig-ng/plugins" NEW_ALX_FUNCTIONS="/usr/lib/alxconfig-ng/functions" # fake mage upgrade to prevent annoying error messages if [[ ! -x /usr/sbin/mageupgrade ]] then mageupgrade() { true; }; export -f mageupgrade fi read_value() { local file=$1 local var=$2 local value [[ ! -e ${file} ]] && return 1 value=$(source ${file}; echo $(eval echo \${${var}})) echo "${value}" return 0 } updateconfig() { local variables="$@" local value local i if [[ -z ${CONFIG} ]] then echo "You must define \$CONFIG varibale first!" return 1 fi for i in ${variables} do value="$(eval echo \${NEW_${i}})" if [[ ! -z $(grep "^${i}=" ${CONFIG}) ]] then echo "fixing ${i} -> ${value}" sed -i "s|^\(${i}=\).*|\1\"${value}\"|" ${CONFIG} else echo "adding ${i}=${value}" echo "${i}=\"${value}\"" >> ${CONFIG} fi done } updategrub2() { # create a device.map if [[ ! -f /boot/grub/device.map ]] then grub-mkdevicemap fi # needed by grub-mkconfig on the first run if [[ ! -f /boot/grub/video.lst ]] then install -m0644 /lib/grub/*/video.lst /boot/grub/video.lst fi # update grub.cfg grub-mkconfig -o /boot/grub/grub.cfg # install bootloader to disk local bootdisk bootdisk="$(grub-probe --target=drive /boot | sed 's:(\(.*\),.*):(\1):')" # Generate core.img, but don't let it be installed in boot sector grub-install --no-floppy "${bootdisk}" } # checks size of the mbr, if we are able to install grub2 check_mbr_size() { local hdd="$1" local geometry_sectors local partition_start_sector local retval hdd="$(mount | grep '/dev/' | grep ' / ' | cut -d' ' -f1 | sed 's:\(.*\)[0-9].*:\1:')" if [[ -z ${hdd} ]] then echo "check_mbr_size(): No hdd given, aborting" return 1 fi # fix permissions chmod +x /etc/mage-profile/sfdisk > /dev/null # default retval is 0 retval=0 # check only if disk size is below 256mb if [[ $(sfdisk -s ${hdd}) -lt 257000 ]] then geometry_sectors=$(sfdisk -g ${hdd} | sed 's:.*,\ \([0-9].*\)\ sectors.*:\1:') partition_start_sector=$(sfdisk -d /dev/hda | grep /dev/hda1 | sed -e 's:.*start=\(.*\), size.*:\1:' -e 's:\ ::g') # check start_sector / geomtry > 1 then everything is fine, else abort setup as grub may not install! if [[ $(expr ${partition_start_sector} / ${geometry_sectors}) -gt 1 ]] then echo "Current partition setup is big enough, to install grub2 mbr to this disk." retval=0 else echo "Warning: Current partition setup to small, cannot install grub2 boot-sector to this disk." echo "Maybe this is a *RANGEE* with a flash-disk =<256MB. Please re-install this client." echo "Upgrade *not* supported!" retval=1 killall mage &> /dev/null killall update-alx &> /dev/null fi else echo "Current disk is big enough, to install grub2 mbr to this disk." retval=0 fi return "${retval}" } # fix mage.rc CONFIG="${MAGERC}" updateconfig RSYNC MIRRORS MAGE_DISTRIBUTION PACKAGES_SERVER_PATH MAGE_UNINSTALL_TIMEOUT # fix config.rc CONFIG="${CONFIGRC}" updateconfig ALX_NETWORKING ALX_DHCP_PROG ALX_DHCP_START ALX_DHCP_STOP MIN_DISK_SPACE ALX_PLUGINS ALX_FUNCTIONS # fix profile if [[ $(readlink /etc/mage-profile) != */${MAGEPROFILE} ]] then echo "fixing profile link -> /usr/mage/profiles/${MAGEPROFILE}" ln -snf /usr/mage/profiles/${MAGEPROFILE} /etc/mage-profile fi # fix missing /dev/root device if [[ ! -e /dev/root ]] then echo "fixing missing /dev/root symlink ..." rootdev=$(basename $(mount | grep ' / ' | cut -d' ' -f1)) [[ -e /dev/${rootdev} ]] && ln -snf ${rootdev} /dev/root fi check_mbr_size || exit 1 # update mage3 -> mage4 if [[ -z $(magequery -n mage) ]] then # update mage tree mage update # mage3 has problems with md5 rm -rf /usr/mage/app-mage/mage/md5 if [[ ${NEW_MAGE_DISTRIBUTION} = unstable ]] then USE_UNSTABLE=true MAGE_DISTRIBUTION=unstable mage install mage elif [[ ${NEW_MAGE_DISTRIBUTION} = testing ]] then USE_TESTING=true MAGE_DISTRIBUTION=testing mage install mage else mage install mage fi # drop all virtuals :> /var/db/mage/virtuals # enable run of orphaned files check touch /.orphaned # tell that we're running an dist-upgrade touch /.dist-upgrade fi # only run this if X11R6 is a directory and not a symlink if [[ -d /usr/X11R6 ]] && [[ ! -L /usr/X11R6 ]] then # check for -f option if [[ -n $(magequery -h | grep -- -f) ]] then # uninstall all /usr/X11R6 packages first for i in $(magequery -f /usr/X11R6 | sed 's:.*/\(.*\)-.*-r.*:\1:') do mage uninstall ${i} done fi # if there are any files after uninstall, simply delete them [ -d /usr/X11R6 ] && rm -rf /usr/X11R6 fi # install new toolchain if not exist TOOLCHAIN="$(< /etc/mage-profile/toolchain.defaults)" if [[ -z $(magequery -n ${TOOLCHAIN}) ]] then # export bootstrap to not start any services export MAGE_BOOTSTRAP=true mage install ${TOOLCHAIN} unset MAGE_BOOTSTRAP # enable run of orphaned files check touch /.orphaned # tell that we're running an dist-upgrade touch /.dist-upgrade fi # install new basesystem BASESYSTEM="$(< /etc/mage-profile/basesystem.defaults)" if [[ -z $(magequery -n ${BASESYSTEM}) ]] then # first keep some important files # export bootstrap to not start any services export MAGE_BOOTSTRAP=true mage install ${BASESYSTEM} unset MAGE_BOOTSTRAP # # fix locale # echo "LANG=\"de_DE\"" > /etc/conf.d/locale # enable run of orphaned files check touch /.orphaned # tell that we're running an dist-upgrade touch /.dist-upgrade fi # install remserial, if the plugin was enabled if [[ ! -z $(magequery -n remserial-alx) ]] then mage install remserial # enable run of orphaned files check touch /.orphaned fi # clean mage cache mage clean echo "Searching for deprecated packages ..." for i in $(magequery -i | grep -- -alx | sed 's:.*/\(.*\)-.*-.*:\1:') do # excludes case ${i} in alxconfig-ng) continue ;; alxinstall-ng) continue ;; kernel-alx) continue ;; kernel26-alx) continue ;; kernel-sources-alx) continue ;; kernel26-sources-alx) continue ;; esac echo "Removing deprecated mage-target '${i}'" mage uninstall ${i} done if [[ -f /.orphaned ]] then echo "Searching for orphaned files and directories ..." bash /etc/mage-profile/prune-orphaned-files rm -f /.orphaned fi if [[ -f /.dist-upgrade ]] then # busybox gets installed before the new busybox initscripts # and the syslog daemon gets started at the wrong runlevels (rc3.d instead of rc.sysinit) # these runlevel symlinks will be deleted by the prune-orphaned-files script # and syslogd will be left never started. so add syslogd here rc-config add syslogd # array of wireless opts WIRELESS_OPTS=( WIRELESS_BITRATE WIRELESS_CHANNEL WIRELESS_ESSID WIRELESS_FREQUENCY WIRELESS_MODE WIRELESS_NICK WIRELESS_AUTH_MODE WIRELESS_KEY_LENGTH WIRELESS_KEY WIRELESS_KEY_ASCII WIRELESS_WPA_DRIVER ) # fixing current dhcp network settings #for i in $(grep -irl NETWORKING=.*dhcp.* /etc/conf.d/net.*) for i in $(grep -irl DHCP_PROG=.*dhcpcd.* /etc/conf.d/net.*) do case ${i} in */net.sample) continue ;; */net.routes) continue ;; esac echo "fixing current dhcp network settings in '${i}'" mv ${i}{,.orig} onboot="$(read_value ${i}.orig ONBOOT)" echo "ONBOOT=\"${onboot}\"" > ${i} echo 'NETWORKING="dhcp"' >> ${i} # check wireless extensions for opt in ${WIRELESS_OPTS[*]} do value="$(read_value ${i}.orig ${opt})" if [[ ! -z ${value} ]] then echo "${opt}=\"${value}\"" >> ${i} fi done rm -f ${i}.orig done # search modules files for i in $(find /etc/modules.d -name net.\*) do install -d /etc/modprobe.d mv ${i} /etc/modprobe.d/${i%.conf}.conf done mount /boot &> /dev/null # install an appropriate uvesafb.conf install -d /etc/modprobe.d || die echo "options uvesafb mode_option=1024x768-32@60 scroll=ywrap" > /etc/modprobe.d/uvesafb.conf || die # install an appropriate viafb.conf echo "options viafb viafb_mode=1024x768 viafb_refresh=60" > /etc/modprobe.d/viafb.conf || die # create an updated initrd DISKMODS="sd_mod" OLDPATAMODS="amd74xx piix sis5513 via82cxxx" PATAMODS="ata_piix pata_amd pata_mpiix pata_oldpiix pata_sis pata_via" SATAMODS="sata_via sata_sis sata_nv" DRMMODS="i915 mga nouveau r128 radeon savage sis tdfx ttm via" if [ -x /usr/sbin/alx-hwdetection ] then case $(/usr/sbin/alx-hwdetection system) in zotac) FBMODS="" ;; rangee) FBMODS="" ;; ## fallback to vesafb, viafb does not run on all CLE266 boards standard) FBMODS="uvesafb" ;; # unkown, use nothing to be safe *) FBMODS="" ;; esac else # unkown, use nothing to be safe FBMODS="" fi echo "MODULES=\"${FORMAT_FILESYSTEM} ${DISKMODS} ${OLDATAMODS} ${PATAMODS} ${SATAMODS} ${DRMMODS} ${FBMODS}\"" > /etc/conf.d/mkinitrd kernelver=$(readlink /boot/vmlinuz | sed 's:kernel-::') # run depmod before depmod -aF /boot/System.map-${kernelver} mkinitrd -f /boot/initrd-${kernelver}.img ${kernelver} # update grub bootloader updategrub2 fi if [[ -f /.dist-upgrade ]] then echo "preparing for a reboot in 60 seconds ..." # reboot via cronjob [[ ! -d /var/spool/cron/crontabs ]] && install -d /var/spool/cron/crontabs # setup a proper cronjob tmp=$(mktemp) :> ${tmp} # fake mageupgrade to fix annoying error messages if [[ ! -x /sbin/mageupgrade ]] then echo '#!/bin/sh' > /sbin/mageupgrade echo 'exit 0' >> /sbin/mageupgrade chmod +x /sbin/mageupgrade echo "* * * * * rm /sbin/mageupgrade" >> ${tmp} fi echo "* * * * * crontab -r && reboot -f" >> ${tmp} crontab ${tmp} [[ -f ${tmp} ]] && rm -f ${tmp} # start cron daemon in background crond -b -S rm -f /.dist-upgrade fi exit 0