Update.sh





UpDate.sh
Download Script Full Package: ZIP tar.gz

UpDate.sh is a bash script that I wrote to update Debian systems with a single commdand.
It works by stringing to gether apt-get update and apt-get upgrade. The script also test to see if the user is root and will add run the commands under sudo if not.
I have also added the apt-get autoremove to the end of the script to remove any unneeded packages. Upon compleation it will run the date and uptime commands.
I have also writen an install script that will install UpDate.sh to /usr/local/bin/.

You can download UpDate.sh from the links on the top and bottem of the page or with wget.
Just the script:

wget efrick.ddns.net/files/update.sh

The full package( useing zip or tar.gz as appropriate:

wget efrick.ddns.net/files/UpDate.sh.zip
wget efrick.ddns.net/files/UpDate.sh.tar.gz

From the Help File:

Command line options are:
y - this option will update without user interaction by adding -y to apt-get upgrade.
a - this option will run the cleanup function without user interaction.
h or help - displays this help message and exits.
v or version - displays the script's version and exits.

Installation Help.

The default installation target is /usr/local/bin/. The install script will prompt if you want a different location.
The instlation will require root privlages. If not run with sudo or as root it will prompt for a password to attempt to use sudo.
Command line options are:
v or version - displays the script's version and exits.

Download Script Full Package: ZIP tar.gz

Full contents of script:

  
#!/bin/bash -i
#This script will update debian based systems fully
#Run this script requires the ability to run as root

#asigning varibules
#this varibule gets the command line option for saying yes to all updates
cmdopt1=$1
cmdopt2=$2
clean=""
version="UpDate.sh version is 1.01\n"
helptitle="UpDate.sh Help File"
helpmsg="UpDate.sh is a shell script writen in bash to update a debian based system automaticaly with one command.\nIt will work with any distribution on the Debian tree (eg Ubuntu and Ubuntu based systems).\nNOTE: This script requiers root privliges. This can be with sudo or by running the script as the root user.\nOptions are:\ny - this option will update without user interaction by adding -y to apt-get upgrade.\na - this option will run the cleanup function without user interaction.\nh or help - displays this help message and exits.\nv or version - displays the script's version and exits\n"

#Version Statement

case $cmdopt1 in
[version]*)
	printf "$version"
	exit
	;;
[v]*)
	printf "$version"
	exit
	;;
esac

case $cmdopt2 in
[version]*)
        printf "$version"
        exit
        ;;
[v]*)
        printf "$version"
        exit
        ;;
esac

#Help section
case $cmdopt1 in
[help]*)
	printf "%*s\n" $(((${#title}+$COLUMNS)/2)) "$helptitle"
	printf "$helpmsg"
	exit
	;;
[h]*)
	printf "%*s\n" $(((${#title}+$COLUMNS)/2)) "$helptitle"
	printf "$helpmsg"
	exit
	;;
esac 

case $cmdopt2 in
[help]*)
	printf "%*s\n" $(((${#title}+$COLUMNS)/2)) "$helptitle"
        printf "$helpmsg"
	exit
        ;;
[h]*)
	printf "%*s\n" $(((${#title}+$COLUMNS)/2)) "$helptitle"
        printf "$helpmsg"
	exit
        ;;
esac


#Testing if the option has been set
if [ "$cmdopt1" == "y" ] || [ "$cmdopt1" == "Y" ] || [ "$cmdopt2" == "y" ] || [ "$cmdopt2" == "Y" ]
then
	if [ $USER == root ] #Testing if user is root
	then
		apt-get update
		apt-get upgrade -y
	else		     #Useing sudo if user is not root
		sudo apt-get update
		sudo apt-get upgrade -y
	fi
#Testing if the varibule is blank
elif [ "$cmdopt1" == "" ]
then
	if [ $USER == root ] #Testing if the user is root
	then
		apt-get update
		apt-get upgrade
	else		    #Useing sudo if the user is not root
		sudo apt-get update
		sudo apt-get upgrade
	fi
#Giving an error if the imput is not expected
else
	echo "That is not a recognized option."
	echo "Please use 'y', 'a' or leave blank."
fi

#Autorun Cleanup if option a is given at command line
if [ "$cmdopt1" == "a" ] || [ "$cmdopt1" == "A" ] || [ "$cmdopt2" == "a" ] || [ "$cmdopt2" == "A" ]
then
	echo "Autorunning Cleanup"
	 if [ $USER == root ] #Testing if user is root
        then
                apt-get autoremove -y
        else
                sudo apt-get autoremove -y
        fi
	echo
	echo
    date
	uptime 
	exit
fi
#Give the option to remove any unnessary pacakages
read -p "Do you want to run cleanup[y/N]:" clean
if [ "$clean" == "n" ] || [ "$clean" == "N" ] || [ "$clean" == "" ]
then
	echo "Skiping Cleanup"

elif [ "$clean" == "y" ] || [ "$clean" == "Y" ]
then	
	echo "Running Autoremove:"
	if [ $USER == root ] #Testing if user is root
	then
		apt-get autoremove
	else
		sudo apt-get autoremove
	fi
else
	echo "That is not a recognized option."
	echo "Please enter 'Y' or 'N'."
fi

echo
echo
date
uptime

exit