blob: bd307ffa4284793cb519dd51cdaed34e3836cede (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#!/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
|