summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgn.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/gn.sh b/gn.sh
new file mode 100755
index 0000000..8640e98
--- /dev/null
+++ b/gn.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+# gn logout script
+# call gn to update all packages and make computer go sleepy
+# if theres a song playing let that bad boy finish out
+
+set -e
+
+performUpdates() {
+ echo "Updating packages before we go."
+ sudo pacman -Syu --noconfirm && yay -Sua
+}
+
+handleCtrlC() {
+ kill $pid
+ exit 1
+}
+
+pingForSongChanges() {
+ # https://gist.github.com/red-noise/9789642
+ title=""
+ pingForChanges=true
+ while $pingForChanges
+ do
+ now_title=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$`
+ if [[ "$title" == "" ]]
+ then
+ title="$now_title"
+ fi
+ if [ "$now_title" != "$title" ]
+ then
+ pingForChanges=false
+ fi
+ sleep 1
+ done
+}
+
+performUpdates
+pid=$!
+wait $pid
+status=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus' | grep -Ev "^method" | sed -e 's/"//g' | sed -e 's/ variant string //g'`
+if [[ "$status" == "Playing" ]]
+then
+ echo "Looks like you're still listening, let's finish out this song before we go."
+ pingForSongChanges
+ echo ""
+ echo "Alright, time to head out."
+fi
+echo ""
+echo "Completed installing all available updates, shutting down in three seconds. Press Ctrl+C to cancel."
+sleep 3
+echo ""
+echo "Goodnight."
+shutdown -h now