aysiu
October 12th, 2006, 07:15 AM
Disclaimer: I am not a programmer. I know very little about shell scripts except that they're collections of terminal commands. Most of this code is stuff I stole/adapted from a script written by forum member Nanotube. (http://ubuntuforums.org/member.php?u=66474)
If you see anything you want to improve, please post the improvement.
Since most people who would know enough to do
chmod +x scriptname.sh
./scriptname.sh would know enough to upgrade themselves, I'm not sure how useful this script might be, but I just put it together to see if it was possible to do easily.
Let me know what you think:
#/bin/bash
## Script written on 11 October, 2006 by aysiu
## Most of the syntax is adapted or just plain copied from code originally written by Nanotube for a Firefox installation script
## Make sure that we exit if any commands do not complete successfully.
set -o errexit
trap 'echo "Previous command did not complete successfully. Exiting."' ERR
## Introduction to script
echo "This script will upgrade you to the next version of Ubuntu.
If you're using Warty, it will upgrade you to Hoary.
If you're using Hoary, it will upgrade you to Breezy.
If you're using Breezy, it will upgrade you to Dapper.
If you're using Dapper, it will upgrade you to Edgy.
You should not upgrade more than one version at a time. If you want to upgrade from Breezy to Edgy, you're better off--in terms of time and stability--just installing Edgy from scratch.
This script also assumes you have a broadband internet connection. If you have no internet connection or are on dial-up, please do not use this script."
## Confirmation of desire to proceed
echo -e -n "
Do you still wish to proceed [y/n]? "
while true
do
read ans
case $ans in
Y|y) break ;;
[Yy][Ee][Ss]) break ;;
N|n) exit ;;
[Nn][Oo]) exit ;;
*) echo -n "Invalid command. Please answer yes or no [y/n] " ;;
esac
done
## Stop from running the script people who are already at the latest version.
if grep -q "development" /etc/issue ; then
echo "You're already using the development version. You cannot upgrade to a newer version."
exit 1
elif grep -q "6.10" /etc/issue ; then
echo "At the time of this script's creation, Edgy was already the latest release of Ubuntu."
exit 1
fi
## Prompt for metapackage installation
echo -e -n "
In order to have a more likely success in upgrading, we're going to have to install the appropriate metapackages for your desktop environments. This may involve the installation of additional software."
echo -e -n "
Do you still wish to proceed? [y/n]? "
while true
do
read ans
case $ans in
Y|y) break ;;
[Yy][Ee][Ss]) break ;;
N|n) exit ;;
[Nn][Oo]) exit ;;
*) echo -n "Invalid command. Please answer yes or no [y/n] " ;;
esac
done
## Install metapackages
if [ -f /usr/share/xsessions/gnome.desktop ]; then
echo -e "
Since you have Gnome installed, we're going to make sure ubuntu-desktop is also installed"
sudo aptitude update && sudo aptitude install ubuntu-desktop
fi
if [ -f /usr/share/xsessions/kde.desktop ]; then
echo -e "
Since you have KDE installed, we're going to make sure kubuntu-desktop is also installed"
sudo aptitude update && sudo aptitude install kubuntu-desktop
fi
if [ -f /usr/share/xsessions/xfce.desktop ]; then
echo -e "
Since you have XFCE installed, we're going to make sure xubuntu-desktop is also installed"
sudo aptitude update && sudo aptitude install xubuntu-desktop
fi
## Back up sources.list
echo '
Backing up old sources.list file'
sudo cp /etc/apt/sources.list /etc/apt/sources.list.old
## Revise sources.list
echo '
Replacing with new sources.list for upgrade'
if grep -q "4.10" /etc/issue ; then
sed 's/warty/hoary/g' /etc/apt/sources.list > ~/temp.list && sudo mv ~/temp.list /etc/apt/sources.list
elif grep -q "5.04" /etc/issue ; then
sed 's/hoary/breezy/g' /etc/apt/sources.list > ~/temp.list && sudo mv ~/temp.list /etc/apt/sources.list
elif grep -q "5.10" /etc/issue ; then
sed 's/breezy/dapper/g' /etc/apt/sources.list > ~/temp.list && sudo mv ~/temp.list /etc/apt/sources.list
elif grep -q "6.06" /etc/issue ; then
sed 's/dapper/edgy/g' /etc/apt/sources.list > ~/temp.list && sudo mv ~/temp.list /etc/apt/sources.list
else
echo "
Error: unable to determine what version of Ubuntu you currently have installed."
exit 1
fi
## Do the upgrade
echo "
We're going to start doing the actual upgrade. This could take hours, even on a broadband internet connection. Please be patient."
sudo aptitude update && sudo aptitude dist-upgrade Even if you have nothing to contribute, please let me know if you think this sort of script is worth doing... or if people already know how to upgrade properly...
If you see anything you want to improve, please post the improvement.
Since most people who would know enough to do
chmod +x scriptname.sh
./scriptname.sh would know enough to upgrade themselves, I'm not sure how useful this script might be, but I just put it together to see if it was possible to do easily.
Let me know what you think:
#/bin/bash
## Script written on 11 October, 2006 by aysiu
## Most of the syntax is adapted or just plain copied from code originally written by Nanotube for a Firefox installation script
## Make sure that we exit if any commands do not complete successfully.
set -o errexit
trap 'echo "Previous command did not complete successfully. Exiting."' ERR
## Introduction to script
echo "This script will upgrade you to the next version of Ubuntu.
If you're using Warty, it will upgrade you to Hoary.
If you're using Hoary, it will upgrade you to Breezy.
If you're using Breezy, it will upgrade you to Dapper.
If you're using Dapper, it will upgrade you to Edgy.
You should not upgrade more than one version at a time. If you want to upgrade from Breezy to Edgy, you're better off--in terms of time and stability--just installing Edgy from scratch.
This script also assumes you have a broadband internet connection. If you have no internet connection or are on dial-up, please do not use this script."
## Confirmation of desire to proceed
echo -e -n "
Do you still wish to proceed [y/n]? "
while true
do
read ans
case $ans in
Y|y) break ;;
[Yy][Ee][Ss]) break ;;
N|n) exit ;;
[Nn][Oo]) exit ;;
*) echo -n "Invalid command. Please answer yes or no [y/n] " ;;
esac
done
## Stop from running the script people who are already at the latest version.
if grep -q "development" /etc/issue ; then
echo "You're already using the development version. You cannot upgrade to a newer version."
exit 1
elif grep -q "6.10" /etc/issue ; then
echo "At the time of this script's creation, Edgy was already the latest release of Ubuntu."
exit 1
fi
## Prompt for metapackage installation
echo -e -n "
In order to have a more likely success in upgrading, we're going to have to install the appropriate metapackages for your desktop environments. This may involve the installation of additional software."
echo -e -n "
Do you still wish to proceed? [y/n]? "
while true
do
read ans
case $ans in
Y|y) break ;;
[Yy][Ee][Ss]) break ;;
N|n) exit ;;
[Nn][Oo]) exit ;;
*) echo -n "Invalid command. Please answer yes or no [y/n] " ;;
esac
done
## Install metapackages
if [ -f /usr/share/xsessions/gnome.desktop ]; then
echo -e "
Since you have Gnome installed, we're going to make sure ubuntu-desktop is also installed"
sudo aptitude update && sudo aptitude install ubuntu-desktop
fi
if [ -f /usr/share/xsessions/kde.desktop ]; then
echo -e "
Since you have KDE installed, we're going to make sure kubuntu-desktop is also installed"
sudo aptitude update && sudo aptitude install kubuntu-desktop
fi
if [ -f /usr/share/xsessions/xfce.desktop ]; then
echo -e "
Since you have XFCE installed, we're going to make sure xubuntu-desktop is also installed"
sudo aptitude update && sudo aptitude install xubuntu-desktop
fi
## Back up sources.list
echo '
Backing up old sources.list file'
sudo cp /etc/apt/sources.list /etc/apt/sources.list.old
## Revise sources.list
echo '
Replacing with new sources.list for upgrade'
if grep -q "4.10" /etc/issue ; then
sed 's/warty/hoary/g' /etc/apt/sources.list > ~/temp.list && sudo mv ~/temp.list /etc/apt/sources.list
elif grep -q "5.04" /etc/issue ; then
sed 's/hoary/breezy/g' /etc/apt/sources.list > ~/temp.list && sudo mv ~/temp.list /etc/apt/sources.list
elif grep -q "5.10" /etc/issue ; then
sed 's/breezy/dapper/g' /etc/apt/sources.list > ~/temp.list && sudo mv ~/temp.list /etc/apt/sources.list
elif grep -q "6.06" /etc/issue ; then
sed 's/dapper/edgy/g' /etc/apt/sources.list > ~/temp.list && sudo mv ~/temp.list /etc/apt/sources.list
else
echo "
Error: unable to determine what version of Ubuntu you currently have installed."
exit 1
fi
## Do the upgrade
echo "
We're going to start doing the actual upgrade. This could take hours, even on a broadband internet connection. Please be patient."
sudo aptitude update && sudo aptitude dist-upgrade Even if you have nothing to contribute, please let me know if you think this sort of script is worth doing... or if people already know how to upgrade properly...