Commit 84c71c44 authored by Ilja's avatar Ilja
Browse files

add sudo to apt-get upgrade

parent 649760bf
......@@ -2,7 +2,7 @@
This is a small script I wrote to upgrade Kubuntu.
You can doubleclick it, it will show a pop-up that it's checking for updates.
You can doubleclick it, it will show a pop-up that it's checking for updates and will ask for your sudo password.
If no updates are found you'll get a notification that the system is up-to-date.
If there are updates, it will show a pop-up to ask for your password and then upgrade and autoremove.
The pop-up is what is used by the system by default, if no default is set, the script will create a utility in `$HOME/.local/bin` called `my-password-dialog`.
......
......@@ -3,21 +3,7 @@
# This script updates the system and sends a notification when updates start and stops.
# Note that notifications wont work when using cron, only if the script is started in the desktop itself.
# 1. Check how many updates there are
notify-send "Checking for updates..."
apt-get update
# 2. If zero updates => exit properly
number_of_upgrades=$(LC_ALL=C apt-get upgrade -s | tail -n 1 | sed -E "s/ .*//g")
if [ $number_of_upgrades -eq 0 ];
then
notify-send "There are no updates. Awesome! Your system is up to date!"
exit 0;
fi
# 3. Otherwise, do upgrade
# Make sure we have a password pop-up screen
notify-send "There are $number_of_updates updates. Starting update..."
MY_PASSWORD_DIALOG_FOLDER="$HOME/.local/bin"
MY_PASSWORD_DIALOG_FILE="my-password-dialog"
my_password_dialog="$MY_PASSWORD_DIALOG_FOLDER/$MY_PASSWORD_DIALOG_FILE"
......@@ -33,6 +19,21 @@ if [ -z $SUDO_ASKPASS ]
then
export SUDO_ASKPASS=$my_password_dialog
fi
# 1. Check how many updates there are
notify-send "Checking for updates..."
sudo -A apt-get update
# 2. If zero updates => exit properly
number_of_upgrades=$(LC_ALL=C apt-get upgrade -s | grep -E "[0-9]+ upgraded, .*" | sed -E "s/ .*//g")
if [ $number_of_upgrades -eq 0 ];
then
notify-send "There are no updates. Awesome! Your system is up to date!"
exit 0;
fi
# 3. Otherwise, do upgrade
notify-send "There are $number_of_upgrades updates. Starting update..."
# Then upgrade and autoremove
sudo -A apt-get upgrade -y
sudo -A apt autoremove -y
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment