| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# Wrapper script for networking set up and teardown via unit file |
| 4 |
# |
| 5 |
# Thu, 01 Oct 2020 22:47:43 +0200 |
| 6 |
# -- Maximilian Wilhelm <[email protected]> |
| 7 |
# |
| 8 |
|
| 9 |
STATE_DIR="/run/ifsate" |
| 10 |
|
| 11 |
# Make sure the state dir is present |
| 12 |
if [ ! -d "${STATE_DIR}" ]; then |
| 13 |
mkdir "${STATE_DIR}" |
| 14 |
fi |
| 15 |
|
| 16 |
# Check for require binaries |
| 17 |
if [ ! -x /sbin/ifup -o ! -x /sbin/ifdown ]; then |
| 18 |
echo "ifup and/or ifdown not found!" >&2 |
| 19 |
exit 1 |
| 20 |
fi |
| 21 |
|
| 22 |
# Apply defaults if present (verbose mode, kill switch, etc.) |
| 23 |
CONFIGURE_INTERFACES=yes |
| 24 |
|
| 25 |
if [ -f /etc/default/networking ]; then |
| 26 |
. /etc/default/networking |
| 27 |
fi |
| 28 |
|
| 29 |
ARGS="" |
| 30 |
if [ "${VERBOSE}" = yes ]; then |
| 31 |
ARGS="-v" |
| 32 |
fi |
| 33 |
|
| 34 |
# Let's go |
| 35 |
case "$1" in |
| 36 |
start) |
| 37 |
if [ "${CONFIGURE_INTERFACES}" = no ]; then |
| 38 |
echo "Not configuring network interfaces, see /etc/default/networking" |
| 39 |
exit 0 |
| 40 |
fi |
| 41 |
|
| 42 |
ifup -a ${ARGS} |
| 43 |
;; |
| 44 |
|
| 45 |
stop) |
| 46 |
if [ "${SKIP_DOWN_AT_SYSRESET}" = "yes" ] && systemctl list-jobs | egrep -q '(shutdown|reboot|halt|poweroff)\.target'; then |
| 47 |
echo ${NAME}':' "Skipping deconfiguring network interfaces" |
| 48 |
exit 0 |
| 49 |
fi |
| 50 |
|
| 51 |
ifdown -a ${ARGS} |
| 52 |
;; |
| 53 |
|
| 54 |
restart) |
| 55 |
ifupdown_init |
| 56 |
ifdown -a ${ARGS} |
| 57 |
ifup -a ${ARGS} |
| 58 |
;; |
| 59 |
|
| 60 |
# reload missing here! |
| 61 |
|
| 62 |
*) |
| 63 |
echo "Usage: $0 {start|stop|restart}" |
| 64 |
exit 1 |
| 65 |
;; |
| 66 |
esac |
| 67 |
|
| 68 |
exit 0 |