2024-03-24 09:21:07 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
2024-06-15 07:42:04 +00:00
|
|
|
#!nix-shell -i bash -p bash -p s6 -p s6-rc
|
2024-03-24 09:21:07 +00:00
|
|
|
|
2024-03-24 12:22:54 +00:00
|
|
|
# for default $PATH to take precedence over nix-shell PATH if invoked interactively,
|
|
|
|
# otherwise we invoke a s6-rc which does not know where to find files.
|
|
|
|
export PATH="/etc/profiles/per-user/$(whoami)/bin:/run/current-system/sw/bin:$PATH"
|
|
|
|
|
2024-03-24 09:21:07 +00:00
|
|
|
action="$1"
|
2024-05-27 00:06:03 +00:00
|
|
|
service="$2"
|
2024-03-24 09:21:07 +00:00
|
|
|
|
2024-03-24 12:22:54 +00:00
|
|
|
log() {
|
2024-04-15 21:29:17 +00:00
|
|
|
if [ -n "$SWAYNC_DEBUG" ]; then
|
2024-03-24 12:22:54 +00:00
|
|
|
printf "%s\n" "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-03-24 09:21:07 +00:00
|
|
|
checkActive() {
|
2024-05-27 00:06:03 +00:00
|
|
|
# simulate a dry-run start. if no actions would be performed, then the service is up.
|
|
|
|
# alternative is s6-svstat, but that doesn't support oneshots
|
|
|
|
test -z "$(s6-rc -n 0 -b start "$service")" && echo true || echo false
|
2024-03-24 09:21:07 +00:00
|
|
|
}
|
|
|
|
startService() {
|
2024-03-24 12:22:54 +00:00
|
|
|
log "startService: $service"
|
2024-05-27 00:06:03 +00:00
|
|
|
s6-rc -b start "$service"
|
2024-03-24 09:21:07 +00:00
|
|
|
}
|
|
|
|
stopService() {
|
2024-03-24 12:22:54 +00:00
|
|
|
log "stopService: $service"
|
2024-05-27 00:06:03 +00:00
|
|
|
s6-rc -b stop "$service"
|
2024-03-24 09:21:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$action" in
|
|
|
|
print)
|
|
|
|
checkActive
|
|
|
|
;;
|
|
|
|
toggle)
|
|
|
|
case "$(checkActive)" in
|
|
|
|
false)
|
2024-03-24 12:22:54 +00:00
|
|
|
startService
|
2024-03-24 09:21:07 +00:00
|
|
|
;;
|
|
|
|
true)
|
2024-03-24 12:22:54 +00:00
|
|
|
stopService
|
2024-03-24 09:21:07 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|