diff options
author | FivePixels <o5pxels@gmail.com> | 2022-03-04 15:42:17 -0600 |
---|---|---|
committer | FivePixels <o5pxels@gmail.com> | 2022-03-04 15:42:17 -0600 |
commit | 03f1c9da38316cfb3cd40151d359c658afde73b0 (patch) | |
tree | 78a1497fee0b93402b7bb6208edc0e8c55cb4c7b | |
download | gn-03f1c9da38316cfb3cd40151d359c658afde73b0.tar.xz gn-03f1c9da38316cfb3cd40151d359c658afde73b0.zip |
Initial commit
-rwxr-xr-x | gn.sh | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -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 |