#!/bin/sh # # script to upgrade Annvix releases: 2.0-RELEASE to 3.0-RELEASE # # $Id: 2.0-to-3.0-upgrade.sh 756 2007-12-26 18:01:37Z vdanen $ oldver="2.0-RELEASE" oldapt="2_0_RELEASE" newver="3.0-RELEASE" newapt="3_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: 2.0-to-3.0-upgrade.sh 756 2007-12-26 18:01:37Z 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/3.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" mkdir /tmp/upgrade log="`mktemp /tmp/upgrade/upgrade.log.XXXXXX`" echo "Upgraded started at `date`" >${log} printf "${star} Modifying /etc/apt/sources.list... " perl -pi -e "s|${oldapt}|${newapt}|g" /etc/apt/sources.list 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 # before we do anything, remove the network subsys file to trick the upgrade into thinking the network # isn't running and thus does not need to be restarted rm -f /var/lock/subsys/network # XXX: needed? ## 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/ 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} echo ${service} >>${srvlist} fi done printf " done\n" printf "${star} Executing apt-get dist-upgrade... " echo "Executing apt-get dist-upgrade" >>${log} runapt "update" runapt "dist-upgrade -q --yes" printf " done\n" printf "${star} Executing apt-get --fix-broken install..." runapt "--fix-broken install --yes" printf " done\n" printf "${star} Looking for obsolete libraries and packages...\n" echo "Looking for obsolete libraries and packages" >>${log} echo "" >>${log} if [ "`rpm -q rsbac-admin >/dev/null 2>&1; echo $?`" == "0" ]; then printf "${ystar} Removing RSBAC packages...\n" echo "Removing RSBAC packages" >>${log} for pkg in rsbac-admin pam_rsbac nss_rsbac ${lib}rsbac1 ${lib}rsbac1-devel ${lib}rsbac1-static-devel; do rpm -e ${pkg} --nodeps >>${log} 2>&1 done [[ -d /var/lib/rsbac ]] && rm -rf /var/lib/rsbac fi # try to remove obsolete libs if we can for pkg in ${lib}expat0 ${lib}newt0.51 ${lib}python2.4 ${lib}rsbac1 ${lib}slang1 ${lib}clamav2 ${lib}ssp0; 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" printf "${ystar} You may have to rebuild some ports packages and remove ${pkg} manually\n" 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 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} 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" # 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 # also remove some *.rpmnew files if [ -f /etc/localtime.rpmnew ]; then rm -f /etc/localtime.rpmnew fi if [ -f /etc/apt/sources.list.rpmnew ]; then rm -f /etc/apt/sources.list.rpmnew fi # make sure the exim alternatives symlink is valid update-alternatives --install /usr/bin/exim exim /usr/bin/exim-4.68 10 printf "${star} Creating a bloated mkinitrd to cover all IDE modules...." initrdimg=`ls -1 /boot/initrd-2.6.22*` kernver=`echo ${initrdimg} | cut -d '-' -f 2- | cut -d 'a' -f 1` addmod="" mods=`pushd /lib/modules/${kernver}avxsmp/kernel/drivers/ide/pci >/dev/null 2>&1; ls -1 | cut -d '.' -f 1; popd >/dev/null 2>&1` for i in ${mods} do addmod="${addmod} --with=${i}" done echo "+ Calling mkinitrd -f -v ${initrdimg} ${addmod} ${kernver}avx" >>${log} mkinitrd -v -f ${initrdimg} ${addmod} ${kernver}avxsmp >>${log} 2>&1 printf " done\n" # clean /boot/grub/grub.conf; we don't want mention of rsbac_cap_process_hiding anymore perl -pi -e 's| rsbac_cap_process_hiding||g' /boot/grub/grub.conf printf "${star} Modifying /etc/init.d/rc.local to probe IDE controllers at reboot..." echo "+ Setting up /etc/init.d/rc.local to probe IDE controllers at reboot" >>${log} # now comes the fun part cat </root/ide-probe.sh #!/bin/sh for i in \`grep "driver:" /etc/sysconfig/hwconf|grep -v '/'|awk '{print \$2}'\` do if [ "\${i}" != "unknown" ]; then if [ "\`find /lib/modules/${kernver}avxsmp/kernel/drivers/ide -name \${i}*\`" != "" ]; then echo "Found IDE device \${i}" if [ "\`lsmod|grep -q \${i}; echo $?\`" == "1" ]; then modprobe \${i} fi ide="\${ide} /sbin/modprobe \${i};" let idecount=\${idecount}+1 fi fi done if [ "\${idecount}" != "0" -a "\${ide}" != "" ]; then echo "install ide-controller \${ide} /bin/true" >>/etc/modprobe.conf fi mv -f /etc/init.d/rc.local.upgrade /etc/init.d/rc.local echo "Regenerating initrd image" mkinitrd -f ${initrdimg} ${kernver}avxsmp rm -f /root/ide-probe.sh EOF cp -f /etc/init.d/rc.local /etc/init.d/rc.local.upgrade echo "/bin/sh /root/ide-probe.sh" >>/etc/init.d/rc.local printf " done\n" # due to no longer owning this file, on uninstall of the old version # it is saved as a .rpmsave, so we need to move it back since the new # logrotate doesn't own it if [ -f /var/lib/logrotate.status.rpmsave ]; then mv /var/lib/logrotate.status.rpmsave /var/lib/logrotate.status fi # call update-localtime due to changes in the timezone package /usr/sbin/update-localtime printf "${star} Removing RSBAC-specific users (rsbadmin, rsbdata, rsbtpmgr)..." userdel rsbadmin userdel rsbdata userdel rsbtpmgr printf " done\n" 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 # put our network subsys file back touch /var/lock/subsys/network 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} Execute 'find /etc -name *.rpmnew' and merge in any changed configs\n" printf "${ystar} Reboot (twice)\n" printf "${ystar} After the reboot, feel free to remove the old 2.6.16 kernel\n" printf "\nWARNING! PLEASE READ THE FOLLOWING CAREFULLY! WARNING!\n" printf "\nYou will need to reboot twice in order to get your system to it's proper\n" printf "state. The first boot will use a bloated initrd image to load all known IDE\n" printf "drivers and then the system will auto-detect which are actually necessary and\n" printf "setup /etc/modprobe.conf for you, then re-generate a proper initrd image based\n" printf "on what was detected. You will want to reboot twice to ensure this does\n" printf "in fact happen properly!\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