From 339630a4a9af0a43831f07ba759b4c2ec6110376 Mon Sep 17 00:00:00 2001 From: John Mertz Date: Thu, 26 May 2022 12:08:29 -0400 Subject: [PATCH] waybar-pkg wrapper for apt and rpm-ostree move waybar-apt.sh to waybar-debian.sh and add waybar-fedora-silverblue.sh waybar-pkg checks the OS from /etc/os-release then forwards argument to the correct script --- waybar/{waybar-apt.sh => waybar-debian.sh} | 2 +- waybar/waybar-fedora-silverblue.sh | 38 ++++++++++++++++++++++ waybar/waybar-pkg.sh | 10 ++++++ 3 files changed, 49 insertions(+), 1 deletion(-) rename waybar/{waybar-apt.sh => waybar-debian.sh} (90%) create mode 100755 waybar/waybar-fedora-silverblue.sh create mode 100755 waybar/waybar-pkg.sh diff --git a/waybar/waybar-apt.sh b/waybar/waybar-debian.sh similarity index 90% rename from waybar/waybar-apt.sh rename to waybar/waybar-debian.sh index 961da92..e224a13 100755 --- a/waybar/waybar-apt.sh +++ b/waybar/waybar-debian.sh @@ -12,7 +12,7 @@ if [ "$1" == 'bar' ]; then 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"}' + 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" diff --git a/waybar/waybar-fedora-silverblue.sh b/waybar/waybar-fedora-silverblue.sh new file mode 100755 index 0000000..029c419 --- /dev/null +++ b/waybar/waybar-fedora-silverblue.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +COUNT=0 +function count() { + RESULTS="`rpm-ostree upgrade --check 2> /dev/null | grep 'rpm-md repo' | cut -d: -f3`;" + COUNT=0 + for i in $RESULTS; do + i=`echo $i | sed 's/;//'` + let COUNT=$COUNT+$i + done +} + +if [ "$1" == 'bar' ]; then + if [ ! -e ${HOME}/.spool/ostree-upgradeable ]; then + count + echo $COUNT > /home/jpm/.spool/ostree-upgradeable + else + COUNT=`cat ${HOME}/.spool/ostree-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 "rpm-ostree upgrade" + count + echo $COUNT > /home/jpm/.spool/ostree-upgradeable +elif [ "$1" == 'update' ]; then + count + echo $COUNT > /home/jpm/.spool/ostree-upgradeable +else + echo "Missing argument: update, upgrade, bar" +fi diff --git a/waybar/waybar-pkg.sh b/waybar/waybar-pkg.sh new file mode 100755 index 0000000..e7dabc5 --- /dev/null +++ b/waybar/waybar-pkg.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Get OS "ID" (lowercase name) and "VARIANT_ID" +ID="`grep '^ID=' /etc/os-release | cut -d= -f2`-`grep 'VARIANT_ID=' /etc/os-release | cut -d= -f2`" + +# Trim if no VARIANT exists (eg. 'debian') +ID=`echo $ID | sed -e 's/\-$//'` + +# Run appropriate script from same path as this one +eval `echo $0 $1| sed -e "s/pkg/${ID}/"`