#!/bin/sh # # script to upgrade Annvix releases: 1.2-RELEASE to 2.0-RELEASE # # $Id: 1.2-to-2.0-upgrade.sh 597 2007-02-04 04:02:26Z vdanen $ # until 2.0-RELEASE is out, this needs to be 2.0-CURRENT oldver="1.2-RELEASE" newver="2.0-RELEASE" # target is "current" or "release" target="release" star=$' \e[36;01m*\e[0m' ystar=$' \e[33;01m*\e[0m' date="`date +%Y-%m-%d`" smp=$(uname -r | grep -q 'smp'; echo $?) if [ `whoami` != "root" ] then printf "${0}: must be root to upgrade\n" exit 1 fi runapt() { aptargs="${1}" aptflag=0 while [ "${aptflag}" == "0" ]; do apt-get ${aptargs} >>${log} 2>&1 if [ "$?" != "0" ]; then echo "++ FAILED: A problem occurred while running apt!" >>${log} printf " failed!\n\nThere was a problem while running apt!\n" read -e -p "Do you wish to try again? (Y/n) " doapt if [ "${doapt}" == "" -o "${doapt}" == "Y" -o "${doapt}" == "y" ]; then aptflag=0 else aptflag=1 printf "Exiting the installer.\n\n" echo "++ User chose to quit the installer" >>${log} exit 1 fi else aptflag=1 fi done unset aptflag unset doapt return 0 } clear printf "Annvix upgrade script: \$Id: 1.2-to-2.0-upgrade.sh 597 2007-02-04 04:02:26Z vdanen $\n\n" printf "Upgrades Annvix ${oldver} to Annvix ${newver}\n\n" printf "This upgrade script attempts to be as nice to your system as possible\n" printf "and do things in as clean a fashion as possible, however there are no\n" printf "guarantees so if your data means anything at all to you PRESS CTRL-C AND\n" printf "PERFORM A BACKUP!!\n\n" printf "This script will first upgrade all RPM packages and then will convert\n" printf "some sysconfig files to the new envdir system and will also upgrade the\n" printf "current shadow-based password system to the newer tcb-based password\n" printf "system.\n\n" printf "As a result we highly recommend you have another terminal opened to the\n" printf "system and logged in as the root user in case we mess something up and\n" printf "at least you'll have a free console from which to attempt to unbork\n" printf "things.\n\n" printf "Finally, please review http://annvix.org/Release_Notes/2.0\n" printf "before doing anything that could potentially damage your system.\n\n" read -s -e -p "Press any key to continue or CTRL-C to abort" foo unset foo printf "\n\n" url=`egrep '^annvix' /etc/urpmi/urpmi.cfg | cut -d ' ' -f 2 | sed "s/${oldver}/${newver}/"` if [ "${url}" = "" ]; then printf "You do not have a medium named 'annvix' defined for urpmi which means\n" printf "that you cannot use this script to upgrade this system.\n\n" exit 1 fi mkdir /tmp/upgrade log="`mktemp /tmp/upgrade/upgrade.log.XXXXXX`" echo "Upgraded started at `date`" >${log} printf "${star} Removing old annvix medium for ${oldver}... " urpmi.removemedia annvix >>${log} 2>&1 printf " done\n" printf "${star} Adding new ${newver} annvix medium... " urpmi.addmedia annvix ${url} with media_info/hdlist.cz >>${log} 2>&1 printf " done\n" printf "\nStarting the upgrade of ${oldver} to ${newver}...\n\n" printf "Please be patient; this may take a few minutes depending on the speed of\n" printf "your network connection and size of installation.\n\n" printf "You may see exactly what is going on by watching ${log}\n\n" arch=`uname -m` if [ "${arch}" == "x86_64" ]; then lib="lib64" tarch="x86_64" else lib="lib" tarch="i586" fi # apache unfortunately gets removed due to the big changes, so if it's installed, let's note it httpdlist=/tmp/upgrade/i_dont_exist if [ "`rpm -q httpd >/dev/null 2>&1; echo $?`" == "0" ]; then httpdlist="`mktemp /tmp/upgrade/httpd-list.XXXXXX`" for i in `rpm -qa | grep httpd`; do rpm -q --queryformat="%{name}\n" ${i} >>${httpdlist} done fi # there is a problem with courier-imap's %postun script so let's note it was installed and get rid of it courierlist="/tmp/upgrade/reinstall_courier" if [ "`rpm -q courier-imap >/dev/null 2>&1; echo $?`" == "0" ]; then rpm -e courier-imap --nodeps --noscripts echo "courier-imap" >>${courierlist} fi if [ "`rpm -q courier-imap-pop >/dev/null 2>&1; echo $?`" == "0" ]; then rpm -e courier-imap-pop --nodeps --noscripts echo "courier-pop" >>${courierlist} fi # kudzu(?) seems to be reconfiguring network interfaces which is bad so copy everything mkdir /tmp/upgrade/network-scripts cp -f /etc/sysconfig/network-scripts/ifcfg* /tmp/upgrade/network-scripts/ # remove root's crontab due to changes in dcron if [ "`rpm -V dcron|grep -q '/etc/crontab'; echo $?`" == "0" ]; then cp -f /var/spool/dcron/crontabs/root /root/crontab-root.backup printf "${ystar} NOTE: The root user's crontab has been backed up to /root/crontab-root.backup\n" printf "${ystar} The new dcron does not require system-wide cron events to be in root's crontab\nany longer and as a result has been deleted.\n" printf "${ystar} Merge in any approriate changes as required.\n" echo "++ Root's old crontab is saved in /root/crontab-root.backup" >>${log} fi crontab -d root printf "${star} Shutting down running services during the upgrade... " echo "Shutting down running services for the upgrade" >>${log} srvlist="`mktemp /tmp/upgrade/services.XXXXXX`" for service in `srv --list | grep up | awk '{print $1}'`; do # don't shut down socklog, mingetty-tty[12], or sshd if [ "`echo ${service} | egrep -q -v '(socklog|sshd|tty1|tty2)'; echo $?`" == "0" ]; then srv --down ${service} >/dev/null 2>&1 echo "++ shutting down ${service}" >>${log} if [ "${service}" == "httpd" ]; then touch /tmp/upgrade/httpd-was-up elif [ "`echo ${service} | grep -v log | grep -q courier >/dev/null 2>&1; echo $?`" == "0" ]; then echo ${service} >>/tmp/upgrade/courier-was-up else echo ${service} >>${srvlist} fi fi done printf " done\n" printf "\n${star} First pass urpmi upgrade... " echo "First pass urpmi upgrade" >>${log} urpmi perl perl-URPM urpmi rpm apt --auto >>${log} 2>&1 if [ "$?" == "0" ]; then printf " done\n" else printf " failed!\n\nThere was a problem upgrading packages with urpmi!\nAborting!\n\n" echo "++ FATAL: Couldn't upgrade with urpmi; aborting" >>${log} mv -f ${log} /root/.upgrade.log-${date}.aborted exit 1 fi printf "${star} Configuring apt... " echo "Configuring apt" >>${log} apturl=$(echo ${url} | perl -pi -e "s|/${newver}.*||" | perl -pi -e "s|file://|file:/|") echo "rpm ${apturl} ${tarch} ${target} ${target}-doc" >>/etc/apt/sources.list runapt "update" printf " done\n" printf "${star} Performing first-step selective install with apt... " echo "Performing first-step selective install with apt" >>${log} runapt "-q install tcb setup pam ${lib}pam0 --yes" printf " done\n" printf "${star} Performing dist-upgrade with apt... " echo "Performing dist-upgrade with apt" >>${log} # remove some packages in order to allow for the upgrade of others; it's ugly but we need to do it echo "Removing ${lib}intl3" >>${log} rpm -e ${lib}intl3 --nodeps >>${log} 2>&1 echo "Running --fix-broken-install" >>${log} runapt "--fix-broken install --yes" echo "Running dist-upgrade" >>${log} runapt "-q dist-upgrade --yes" printf " done\n" printf "${star} Installing other required packages... " if [ "${smp}" == 0 ]; then kernel=kernel-smp else kernel=kernel-up fi echo "Installing ${kernel}" >>${log} runapt "-q install ${kernel} --yes" if [ "$?" == "0" ]; then printf " kernel " fi if [ -f ${httpdlist} ]; then echo "Reinstalling httpd packages" >>${log} for i in `cat ${httpdlist}`; do echo "-- ${i}" >>${log} runapt "-q install ${i} --yes" done printf " httpd " fi if [ -f ${courierlist} ]; then echo "Reinstalling courier-imap" >>${log} for i in `cat ${courierlist}`; do echo "-- ${i}" >>${log} runapt "-q install ${i} --yes" done printf " courier-imap " fi printf "\n" printf "${star} Looking for obsolete libraries and packages...\n" echo "Looking for obsolete libraries and packages" >>${log} echo "" >>${log} # try to remove obsolete libs if we can for pkg in ${lib}apr-util0 ${lib}apr0 ${lib}curl3 ${lib}pq4 ${lib}user1-devel libuser ${lib}user1 ${lib}db4.1 cracklib-dicts \ ${lib}crack2 ${lib}pwdb0 pwdb-conf; do if [ "`rpm -q ${pkg} >/dev/null 2>&1; echo $?`" == "0" ]; then # package is installed, let's try to remove it if [ "`rpm -e --test ${pkg} >/dev/null 2>&1; echo $?`" == "0" ]; then printf "${ystar} Removing unrequired package: ${pkg}\n" echo "Removing unrequired package: ${pkg}" >>${log} else printf "${ystar} Unable to remove package: ${pkg}\n" echo "You may have to rebuild some ports packages and remove ${pkg} manually" fi # we can safely call rpm -e here because if we're not able to remove it, it will print out what requires # it which is what we want rpm -e ${pkg} >>${log} 2>&1 fi done if [ -f /etc/shadow.rpmsave ]; then mv -f /etc/shadow.rpmsave /etc/shadow fi printf "${star} Converting shadow passwords to tcb passwords... " echo "Converting shadow passwords to tcb passwords..." >>${log} chown root:chkpwd /usr/${lib}/chkpwd chown root:shadow /usr/${lib}/chkpwd/tcb_chkpwd tcb_convert >>${log} 2>&1 if [ "$?" == "0" ]; then rm -f /etc/shadow /etc/shadow- printf " done\n" else printf " failed!\n\nThere was a problem migrating to tcb passwords.\nPlease check the upgrade logfile for more details.\nThe old shadow files have not been removed.\n" fi printf "${star} Adding USB support to /etc/modprobe.conf... " echo "Adding USB support to /etc/modprobe.conf" >>${log} # add usb support to modprobe conf if it's not already there if [ "`grep -q usb-interface /etc/modprobe.conf; echo $?`" == "1" ]; then usbinstall="" if [ "`grep -q uhci-hcd /etc/sysconfig/hwconf; echo $?`" == "0" ]; then usbinstall="${usbinstall}/sbin/modprobe uhci-hcd; " fi if [ "`grep -q ohci-hcd /etc/sysconfig/hwconf; echo $?`" == "0" ]; then usbinstall="${usbinstall}/sbin/modprobe ohci-hcd; " fi if [ "`grep -q ehci-hcd /etc/sysconfig/hwconf; echo $?`" == "0" ]; then usbinstall="${usbinstall}/sbin/modprobe ehci-hcd; " fi if [ "${usbinstall}" != "" ]; then echo "install usb-interface ${usbinstall}/bin/true" >>/etc/modprobe.conf fi fi printf " done \n" printf "${star} Doing a final pass to ensure everything is updated... " echo "Doing a final pass to ensure everything is updated..." >>${log} runapt "-q dist-upgrade --yes" if [ "$?" == "0" ]; then printf " done\n" fi printf "${star} Converting sysconfig files to environment directories... " echo "Converting sysconfig files to environment directories... " >>${log} convert-envdir >>${log} 2>&1 printf " done\n" # due to some changes I can't pinpoint, we *must* have a mdadm.conf file if we're using RAID setupraid=0 if [ "`rpm -q mdadm >/dev/null 2>&1; echo $?`" == "0" ]; then setupraid=1 if [ -f /etc/mdadm.conf ]; then printf "${star} Moving old /etc/mdadm.conf to /etc/mdadm.conf.pre-upgrade..." echo "++ moved /etc/mdadm.conf to /etc/mdadm.conf.pre-upgrade" >>${log} mv /etc/mdadm.conf /etc/mdadm.conf.pre-upgrade printf " done\n" fi printf "${star} Creating new /etc/mdadm.conf... " echo "# mdadm configuration auto-generated by ${0} (\$Id: 1.2-to-2.0-upgrade.sh 597 2007-02-04 04:02:26Z vdanen $)" >/etc/mdadm.conf echo "" >>/etc/mdadm.conf for i in `cat /proc/mdstat | egrep '^md' | awk '{print $1}' | sort -n`; do mdline=`grep ${i} /proc/mdstat` devmd=`echo ${mdline} | awk '{print $1}'` count=0 for dev in `echo ${mdline}`; do if [ "`echo ${dev} | egrep '^(hd|sd)'`" != "" ]; then devhd="`echo ${dev} | cut -d '[' -f 1`" if [ "${count}" == "0" ]; then devline="devices=/dev/${devhd}" else devline="${devline},/dev/${devhd}" fi count=1 fi done echo "ARRAY /dev/${devmd} ${devline}" >>/etc/mdadm.conf done echo "" >>/etc/mdadm.conf cat /etc/mdadm.conf.pre-upgrade >>/etc/mdadm.conf echo "++ updated /etc/mdadm.conf" >>${log} printf " done\n" fi printf "${star} Checking network configuration files..." echo "Checking network configuration files" >>${log} for file in `ls -1 /tmp/upgrade/network-scripts/*`; do cmp /tmp/upgrade/network-scripts/${file} /etc/sysconfig/network-scripts/${file} >/dev/null 2>&1 if [ "$?" == "1" ]; then echo "Replacing changed file /etc/sysconfig/network-scripts/${file} with original" >>${log} cp -f /tmp/upgrade/network-scripts/${file} /etc/sysconfig/network-scripts/${file} fi done printf " done\n" printf "${star} Doing final cleanup... \n" # remove the old dcron spool directory [[ -d /var/spool/dcron ]] && rmdir /var/spool/dcron >/dev/null 2>&1 # i18n is simple now -- all english printf "${ystar} Checking i18n settings...\n" [[ -f /etc/sysconfig/i18n.rpmnew ]] && mv -f /etc/sysconfig/i18n.rpmnew /etc/sysconfig/i18n # make sure the exim symlink exists [[ ! -L /usr/bin/exim ]] && ln -s ../../etc/alternatives/exim /usr/bin/exim # make sure /etc/hosts contains a FQDN for us or apache will freak myhost="`hostname`" if [ "`grep -q ${myhost} /etc/hosts >/dev/null 2>&1; echo $?`" == "1" ]; then myip="`ifconfig eth0 | grep inet | awk '{print $2}' | cut -d ':' -f 2`" printf "${myip}\t\t${myhost}\n" >>/etc/hosts printf "${ystar} Added missing FQDN for this host to /etc/hosts\n" echo "Added missing FQDN for this host to /etc/hosts" >>${log} fi # remove the vcsa user and cleanup the group/passwd.rpmnew files; we can safely remove # the .rpmnew files since setup should merge in the appropriate user changes userdel vcsa rm -f /etc/passwd.rpmnew /etc/group.rpmnew # also remove the localtime.rpmnew file rm -f /etc/localtime.rpmnew printf "${star} Bringing back up downed services...\n" echo "Bringing back up downed services" >>${log} for service in `cat ${srvlist} | grep -v '/log'`; do echo "++ bringing up ${service}" >>${log} srv --up ${service} done if [ -f /tmp/upgrade/httpd-was-up ]; then echo "++ adding and bringing up httpd" >>${log} srv --add httpd srv --up httpd/log >/dev/null 2>&1 fi if [ -f /tmp/upgrade/courier-was-up ]; then for i in `cat /tmp/upgrade/courier-was-up`; do echo "++ adding and bringing up ${i}" >>${log} srv --add ${i} srv --up ${i}/log >/dev/null 2>&1 done fi echo "Upgraded finished at `date`" >>${log} mv ${log} /root/.upgrade.log-${date} rm -rf /tmp/upgrade printf "\nYour system has been upgraded to ${newver}; the log output is in\n" printf "/root/.upgrade.log-${date}... you should examine this for errors.\n\n" printf "You must still manually perform the following steps:\n\n" printf "${ystar} Add any administrative users to the ctools group to use a compiler\n" if [ "${setupraid}" == "1" ]; then printf "${ystar} You MUST make sure that /etc/mdadm.conf is configured sufficiently or\n you may not be able to reboot properly!\n" fi printf "${ystar} Execute 'find /etc -name *.rpmnew' and merge in any changed configs\n" printf "${ystar} Reboot\n" printf "${ystar} After the reboot, feel free to remove the old 2.4 kernel\n" printf "\nPlease be sure to visit the Annvix website at http://annvix.org/ for\n" printf "any information regarding this upgrade if you haven't done so already.\n\n" printf "Also, please reboot to ensure the system comes up clean and view the\n" printf "afterboot manpage for information on programs and services installed.\n\n" printf "Thank you from the Annvix development team.\n\n" exit 0