cfg/bin/lock

48 lines
1.1 KiB
Text
Raw Permalink Normal View History

#!/bin/bash
set -euo pipefail
program_kills=(
'electron.*discord/resources/app.asar'
)
program_starts=(
discord
)
systemd_services=(
streamdeck
)
function log() {
echo "$@" >&2
}
# Stop MPD playback when mpc client was found
(which mpc >/dev/null 2>&1) && mpc stop || true
# Disable systemd user services
for svc in "${systemd_services[@]}"; do
systemctl --user is-active ${svc} >/dev/null 2>&1 && systemctl --user stop ${svc} || log "Service ${svc} not active / not found"
done
# Terminate Discord in order to get mobile notifications
for prog in "${program_kills[@]}"; do
kill -TERM $(pgrep -fo "${prog}") || true
done
# Mute default sink & source
pactl set-sink-mute @DEFAULT_SINK@ true || true
pactl set-source-mute @DEFAULT_SOURCE@ true || true
i3lock -e -f -n -c 000000
# Restart user-services
for svc in "${systemd_services[@]}"; do
systemctl --user is-enabled ${svc} >/dev/null 2>&1 && systemctl --user start ${svc} || log "Service ${svc} not enabled, skipping start"
done
# Restart programs
for cmd in "${program_starts[@]}"; do
which ${cmd} >/dev/null 2>&1 && i3-msg "exec ${cmd}" || true
done