PDA

View Full Version : Tip: Easy System Upgrades



onemyndseye
03-23-2007, 05:54 AM
Dont you just hate it when ` apt-get upgrade ` changes your /etc/rc*.d's and starts daemons that you dont need running?

Here is a simple script to help by simply making a backup of your /etc/rc*.d directories and restoring them once the upgrade is finished.

system-upgrade.sh


#!/bin/bash

if [ $UID = "0" ]; then
clear
STATUS=0
echo "Please Wait:"

echo -n "Updating Sources ...."
apt-get -q update >/dev/null 2>&1
echo ".Done."

echo -n "Backing up /etc/rc*.d ...."
TEMP=/tmp/system-upgrade-$RANDOM
mkdir $TEMP
cp -a /etc/rc*.d $TEMP/. >/dev/null
echo ".Done."

echo ""
echo "Performing Upgrade:"
# Set STATUS= according to apt-gets exit status.
# In place for later expansions
apt-get -q upgrade && STATUS=0 || STATUS=1

# For now if STATUS=1 (Error) just exit without cleanup
echo ""
echo -n "Restoring /etc/rc*.d ..."
rm -rfd /etc/rc*.d >/dev/null
cp -a $TEMP/* /etc/.
echo ".Done."
[ $STATUS = 1 ] && exit 1
echo ""
echo -n "Cleaning up ...."
apt-get clean
rm -rfd $TEMP
echo ".Done."

else

echo "This script must be run as root!"

fi





Here is another small script to simply update your sources and check if there are packages that can be upgraded.

checkup.sh


#!/bin/bash

if [ $UID = 0 ]; then
echo "Checking for available upgrades...."
apt-get update >/dev/null
apt-get -s upgrade | grep Inst >/tmp/checkupgrades.out

if [ -s /tmp/checkupgrades.out ]; then
echo ""
echo "... There are new updates for your system!"
echo 1 >/etc/apt/checkupgrades.status
rm -f /tmp/checkupgrades.out
else
echo ""
echo "... There are no new updates for your system!"
echo 0 >/etc/apt/checkupgrades.status
rm -f /tmp/checkupgrades.out
fi
else

echo "This script must be run as root!"
fi


This script can be used in a cron if you null the output ( >/dev/null ) then evaluate /etc/apt/checkupgrades.status with something like:




CHECKUP_STATUS=$(cat /etc/apt/checkupgrades.status)
if [ $CHECKUP_STATUS = 1 ]; then
# There are upgrades
else
# No upgrades
fi



Hoefully someone will find some of this usefull :)
Take Care,
-Justin
One Mynds Eye