2022-04-19 04:37:30 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ "$1" == 'bar' ]; then
|
2024-03-08 19:11:04 +00:00
|
|
|
if [ ! -e ${HOME}/.local/state/apt-upgradeable ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
sudo apt update >/dev/null 2>/dev/null
|
|
|
|
COUNT=`apt list --upgradable 2> /dev/null | wc -l`
|
|
|
|
let COUNT--
|
2024-03-08 19:11:04 +00:00
|
|
|
echo $COUNT > /home/jpm/.local/state/apt-upgradeable
|
2023-01-06 19:41:31 +00:00
|
|
|
else
|
2024-03-08 19:11:04 +00:00
|
|
|
COUNT=`cat ${HOME}/.local/state/apt-upgradeable`
|
2023-01-06 19:41:31 +00:00
|
|
|
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
|
2022-04-19 04:37:30 +00:00
|
|
|
elif [ "$SUDO_USER" != '' ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
echo "Don't run with sudo. Run normally, but with a sudoer user"
|
2022-04-19 04:37:30 +00:00
|
|
|
elif [ $UID -eq 0 ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
echo "Don't run as root. Run normally, but with a sudoer user"
|
2022-04-19 04:37:30 +00:00
|
|
|
elif [ "$1" == 'upgrade' ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
/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--
|
2024-03-08 19:11:04 +00:00
|
|
|
echo $COUNT > /home/jpm/.local/state/apt-upgradeable
|
2023-01-07 13:16:47 +00:00
|
|
|
if [ -e /var/run/reboot-required ]; then
|
|
|
|
grep -B1 -A4 upgrade /var/log/apt/history.log | tail -n 6 | swaynag --config=${HOME}/.dotfiles/sway/swaynag --edge=bottom --message="New packages require restart" --button="Restart Now" "sudo systemctl reboot" --dismiss-button="Later" --detailed-message --detailed-button "Show/Hide Upgrade Details"
|
|
|
|
fi
|
2022-04-19 04:37:30 +00:00
|
|
|
elif [ "$1" == 'update' ]; then
|
2023-01-06 19:41:31 +00:00
|
|
|
sudo apt update >/dev/null 2>/dev/null
|
|
|
|
COUNT=`apt list --upgradable 2> /dev/null | wc -l`
|
|
|
|
let COUNT--
|
2024-03-08 19:11:04 +00:00
|
|
|
echo $COUNT > /home/jpm/.local/state/apt-upgradeable
|
2022-04-19 04:37:30 +00:00
|
|
|
else
|
2023-01-06 19:41:31 +00:00
|
|
|
echo "Missing argument: update, upgrade, bar"
|
2022-04-19 04:37:30 +00:00
|
|
|
fi
|