From 63e45329503f2015aacd91ac89deec7ebfe9d26f Mon Sep 17 00:00:00 2001 From: John Mertz Date: Tue, 19 Apr 2022 00:37:30 -0400 Subject: [PATCH] Add waybar function for apt Can fetch the current number of available package updates, then allow installation by clicking. --- waybar/waybar-apt.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 waybar/waybar-apt.sh diff --git a/waybar/waybar-apt.sh b/waybar/waybar-apt.sh new file mode 100755 index 0000000..961da92 --- /dev/null +++ b/waybar/waybar-apt.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +if [ "$1" == 'bar' ]; then + if [ ! -e ${HOME}/.spool/apt-upgradeable ]; then + sudo apt update >/dev/null 2>/dev/null + COUNT=`apt list --upgradable 2> /dev/null | wc -l` + let COUNT-- + echo $COUNT > /home/jpm/.spool/apt-upgradeable + else + COUNT=`cat ${HOME}/.spool/apt-upgradeable` + fi + if [ $COUNT -eq 0 ]; then + echo '{"text": "🗹", "tooltip": "Up-to-date", "class": "up-to-date"}' + else + echo '{"text": "⭳ '$COUNT'", "tooltip": "'$COUNT' updates available (click to download)", "class": "updateable"}' + fi +elif [ "$SUDO_USER" != '' ]; then + echo "Don't run with sudo. Run normally, but with a sudoer user" +elif [ $UID -eq 0 ]; then + echo "Don't run as root. Run normally, but with a sudoer user" +elif [ "$1" == 'upgrade' ]; then + /usr/bin/uxterm -e "sudo apt-get update && sudo apt-get full-upgrade -y && sudo apt-get autoremove -y && sudo apt-get clean -y && exit" + COUNT=`apt list --upgradable 2> /dev/null | wc -l` + let COUNT-- + echo $COUNT > /home/jpm/.spool/apt-upgradeable +elif [ "$1" == 'update' ]; then + sudo apt update >/dev/null 2>/dev/null + COUNT=`apt list --upgradable 2> /dev/null | wc -l` + let COUNT-- + echo $COUNT > /home/jpm/.spool/apt-upgradeable +else + echo "Missing argument: update, upgrade" +fi