Upgrade script....

"Gary L. Greene Jr." <[email protected]> Fri, 4 Mar 2005 20:12:12 -0500
Newsgroups gmane.linux.arklinux.devel
Organization Paradise Technology Group
Message-ID <[email protected]>
This can be modified since it's under GPL for whatever reason...


-- 
Gary L. Greene, Jr.
Sent from uriel
 20:10:02 up 4 days, 11:46,  6 users,  load average: 0.08, 0.06, 0.04
signature.asc (application/pgp-signature, 190 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.9.12 (GNU/Linux)

iD8DBQBCKQdxpYIGqyXDl5wRAgT+AJ9vd8e0L3A+7GsJpvEujAXP/pARzwCfZkgr
4rFAD40yGtKQQzDjW7pWQNY=
=TyiS
-----END PGP SIGNATURE-----
a2b-update-tool.sh (application/x-shellscript, 10 KB)
#!/bin/bash

############################################################################## 
# 
# Author Gary Greene
# Copyright 2004
# licensed GPL v2
#
##############################################################################

trap "" 1 2 3 9

AllDone() {
    clear
    echo -en '\033[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\033[0m'
    echo ""
    echo ""
    echo "The update has completed. Please wait while rebooting your PC."
    echo ""
    echo ""
    echo ""
    sleep 15s
    reboot now
}

RestoreSysData() {
    clear
    echo -en '\033[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\033[0m'
    echo ""
    echo ""
    echo "Restoring system configuration."
    cp /mnt/dest/XF86Config* /mnt/dest/etc/X11/
    cp /mnt/dest/host* /mnt/dest/etc/
    cp /mnt/dest/modules.* /mnt/dest/etc/
    cp /mnt/dest/shadow /mnt/dest/etc/
    cp /mnt/dest/gshadow /mnt/dest/etc/
    cp /mnt/dest/passwd /mnt/dest/etc/
    cp /mnt/dest/group /mnt/dest/etc/
    cp -r /mnt/dest/samba /mnt/dest/etc/
    cp -r /mnt/dest/sysconfig /mnt/dest/etc/
    umount /mnt/dest
    AllDone
}

InstallGrubby() {
    clear
    echo -en '\033[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\033[0m'
    echo ""
    echo ""
    echo "Cleaning up bootloader...."
    /mnt/dest/grubby --remove-kernel=/mnt/dest/boot/vmlinuz-2.4* --grub
    cd /mnt/dest/boot
    rm -rf vmlinuz-2.4*
    rm -rf System.map-2.4*
    rm -rf autoconf.h-2.4*
    rm -rf config-2.4*
    rm -rf initrd-2.4*
    rm -rf module-info-2.4*
    rm -rf version.h-2.4*
    RestoreSysData
}

InstallUpdate() {
    clear
    echo -en '\033[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\033[0m'
    echo ""
    echo ""
    echo "Installing Ark Linux Beta1..."
    cd /RPMS
    destination=/mnt/dest
    rpm --initdb --root=$destination
    rpmoptions="-ivh --nodeps --force --root=$destination"
    for package in *
    do
        if [ $package == "kernel-2*.rpm" ]; then
            cd `uname -p`
            if [ $smpval == 'y' ]; then
                rpm $rpmoptions kernel-smp*.rpm
            else
                rpm $rpmoptions kernel-2*.rpm
            fi
            cd -
        elif [ $package == "glibc*" ];then
            cd `uname -p`
            rpm $rpmoptions glibc*.rpm
            cd -
        else
            rpm $rpmoptions $package
        fi
    done
    InstallGrubby
}

DeleteSystem() {
    clear
    echo -en '\033[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\033[0m'
    echo ""
    echo ""
    echo "Preparing previous install for updates. This may take several minutes..."
    cd /mnt/dest/
    echo -n "   Processing:              "
    rm -rf bin
    echo -n "#####"
    rm -rf dev
    echo -n "######"
    rm -rf lib
    echo -n "######"
    rm -rf opt
    echo -n "#####"
    rm -rf sbin
    echo -n "#####"
    rm -rf srv
    echo -n "#####"
    rm -rf tmp
    echo -n "#####"
    rm -rf usr
    echo -n "#######"
    rm -rf var
    echo -n "######"
    echo ""
    echo ""
    echo "Creating backup of system configuration data..."
    tar -cjf /mnt/dest/etc.tar.bz2 /mnt/dest/etc
    cp etc/X11/XF86Config* /mnt/dest/
    cp etc/host* /mnt/dest/
    cp etc/modules.* /mnt/dest/
    cp etc/shadow /mnt/dest/
    cp etc/gshadow /mnt/dest/
    cp etc/passwd /mnt/dest/
    cp etc/group /mnt/dest/
    cp -r etc/samba /mnt/dest/
    cp -r etc/sysconfig /mnt/dest/
    rm -rf etc
    InstallUpdate
}

Continue2input() {
    echo "This is your final confirmation!"
    echo "Do you still want to continue? [y,n] "
    read continueAnswer
    if [ $continueAnswer == "y" ]; then
        DeleteSystem
    else
        echo "Incorrect input."
        Continue2
    fi
}

Continue2() {
    clear
    echo -en '\033[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\033[0m'
    echo ""
    echo ""
    echo -e "\033[5;1mFINAL WARNING! \033[25;0m"
    echo "Are you sure you wish to continue? If you do, your personal data"
    echo "will remain safe, however, as previous stated, all programs will"
    echo "be reset!"
}

SMPCheckInput() {
    echo -n "Is this a multiprocessor system? [y/n]"
    read smpval
    if [ $smpval == 'y' -o $smpval == 'n' ] ; then
	export smpval;
        Continue2
    else
        echo "Incorrect input."
        SMPCheck
    fi
}

SMPCheck() {
    clear
    echo -en '\033[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\033[0m'
    echo ""
    echo ""
    echo "Computers with multiple CPUs require special setup in order to achieve"
    echo "optimal performance.  If your computer has multiple CPUs, you should "
    echo "select 'Y' now.  If you are not sure, it is safe to select 'Y' here."
    echo "Otherwise, select 'N' now."
    echo ""
    SMPCheckInput
}

Continue1input() {
    echo "Do you still want to continue? [y,n] "
    read continueAnswer
    if [ $continueAnswer == "y" ]; then
        SMPCheck
    else
        echo "Incorrect input."
        Continue1
    fi
}


Continue1() {
    clear
    echo -en '\033[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\033[0m'
    echo ""
    echo ""
    echo -e "\033[5;1mIMPORTANT! \033[25;0m"
    echo "Any 3rd party applications and software from the online apt repository will"
    echo "be removed!"
    Continue1input
}

ConfirmUdateContinue() {
    clear
    echo -en '\E[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\E[0m'
    echo ""
    echo ""
    echo "Found your Ark Linux installation."
    echo ""
    echo "To update your computer, this tool will remove all programs from"
    echo "your computer and then install the new versions from the install CD."
    echo "Your personal data, and system configuration will not be deleted."
    echo ""
    echo "Should we continue the update? [y,n] "
    Continue1
}

AutoDiscovery() {
    line_count=$( wc -l < /proc/partitions )
    destination="/mnt/dest"
    for partline in `seq $line_count`
    do
        read nil1 nil2 nil3 partname
        if mount -t ext3 /dev/$partname $destination 2>/dev/null; then
            if [ -e $destination/etc/ark-release ]; then
                true
            else
                umount $destination 2>/dev/null
            fi
        fi
    done </proc/partitions
    ConfirmUdateContinue
}

AutomaticPartSelection() {
    clear
    echo -en '\E[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\E[0m'
    echo ""
    echo ""
    echo "Please Wait while we discover which disk and partition holds your"
    echo "Ark Linux install...."
    echo ""
    echo ""
    echo "Please wait while finding your root partition...."
    sleep 5s
    AutoDiscovery
}

ManualPartSelection() {
    clear
    echo -en '\E[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\E[0m'
    echo ""
    echo ""
    echo "Please enter the partition in the format of hdxx, where xx is"
    echo "the disks letter (a through g) and partition number (1 through 10)"
    echo -c "(SCSI and SATA disk partitions use sdxx): "
    read partition
    echo ""
    echo ""
    destination="/mnt/dest"
    mount -t ext3 /dev/$partition $destination
    if [ $? -eq 0 ]; then
        echo "Partition Mounted OK."
        ConfirmUdateContinue
    else
        echo "ERROR!!! Partition mounted with errors! Cannot continue!"
        exit 1
    fi
}

CheckPartitionsInput() {
    echo -n "How should we detect your partition? [1,2] "
    read response
    if [ $response -eq 1 ]; then
        ManualPartSelection
    elif [ $response -eq 2 ]; then
        AutomaticPartSelection
    else
        echo "Incorrect input."
        CheckPartitionsInput
    fi
}

CheckPartitions() {
    clear
    echo -en '\E[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\E[0m'
    echo ""
    echo ""
    echo "The first thing we need to check is where Ark Linux is installed on"
    echo "your computer. If you know which partition it is installed on,"
    echo "please select the manual partition selection. If not, let the "
    echo "updater choose the partition for you automatically."
    echo ""
    echo ""
    echo "        1. Manual partition selection"
    echo "        2. Automatic partition selection ( RECOMMENDED )"
    echo ""
    CheckPartitionsInput
}

WelcomeInput() {
    echo -n "Do you wish to proceed? [y,n] "
    read line
    if [ $line == "y" ]; then
        CheckPartitions;
    elif [ $line == "n" ]; then
        echo "Thank you for choosing Ark Linux."
    else
        echo "Incorrect input."
        WelcomeInput
    fi
}

Welcome() {
    clear
    echo -en '\E[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\E[0m'
    echo ""
    echo ""
    echo "This tool will update your Ark Linux 1.0.0-alpha12.2 system to"
    echo "1.0.0-beta1. Before running this update, we need to gather a little"
    echo "information to allow the update to run smoothly."
    echo ""
    WelcomeInput
}

Help() {
    clear
    echo -en '\E[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\E[0m'
    echo ""
    echo "This tool is for use to upgrade a Ark Linux Alpha12 system to Beta1."
    echo "Following is the options that can be passed to the utility:"
    echo
    echo "\t -h: Shows this help text and exits"
    echo "\t -v: Displays the version of this utility"
    echo
    exit 0;
}

Version() {
    clear
    echo -en '\E[4m''\E[31m'"Ark "
    echo -en '\E[34m'"Linux"
    echo -e '\E[39m'" Alpha12 to Beta1 update tool"'\E[0m'
    echo ""
    echo "Version 1.0-b1"
    echo 'Author  Gary Greene <[email protected]>'
    exit 0;
}



case $1 in
    -h)
        Help
    ;;
    -v)
        Version
    ;;
    *)
        Welcome;
    ;;
esac    

exit 0;