#!/usr/bin/env bash # Copyright © 2015 Luke Shumaker # This work is free. You can redistribute it and/or modify it under the # terms of the Do What The Fuck You Want To Public License, Version 2, # as published by Sam Hocevar. See the COPYING file for more details. mode="$1" lock=/run/network-online/lock fifo=/run/network-online/"$2" PS4="$mode: " case "$mode" in start) trap 'rm -f -- "$fifo"' EXIT set -x mkdir -p /run/network-online || exit $? exec 8>"$lock" || exit $? flock -s 8 || exit $? systemctl start network-online.target || exit $? mkfifo "$fifo" || exit $? cat "$fifo" exec 8>&- echo stopped >> "$fifo" ;; stop) set -x exec 8>"$lock" || exit $? echo stopping >> "$fifo" || exit $? cat "$fifo" || exit $? if flock -x -n 8; then systemctl stop network-online.target rm -rf /run/network-online fi ;; esac