#!/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 } 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