blob: 7004a918e883328d4c057b07a33f1a6618e38e72 (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#!/bin/sh
# shellcheck shell=sh disable=SC1008
CONFDIR="@CONFDIR@"
LIBEXECDIR="@LIBEXECDIR@/sh"
INITDIR="@INITDIR@"
INIT=systemd
usage() {
echo "netifrc systemd wrapper"
echo "Usage:"
echo " systemd-wrapper.sh -i <interface> <command>"
echo " where command is start|stop"
}
die() {
echo "$@"
exit 1
}
while getopts "i:" opt; do
case $opt in
i)
RC_IFACE=$OPTARG;;
esac
done
shift $((OPTIND -1))
[ -z "$RC_IFACE" ] && die "Missing Parameter Interface"
RC_SVCPREFIX="net"
RC_SVCNAME="$RC_SVCPREFIX"."$RC_IFACE"
RC_UNAME=$(uname)
# XXX Find out the systemd way of doing this
RC_GOINGDOWN=no
# In Openrc systems this has value /run/openrc
SVCDIR="/run/netifrc"
# OpenRC saves values in $SVCDIR/options/$SVCNAME/$OPTION
# In non OpenRC setting this is saved in /run/netifrc/options/$SVCNAME/$OPTION
OPTIONSDIR="${SVCDIR}/options/${RC_SVCNAME}"
STATEDIR="${SVCDIR}/${RC_SVCNAME}"
# Source the config file
if [ -f "$CONFDIR/$RC_SVCPREFIX" ]; then
. "$CONFDIR/$RC_SVCPREFIX"
fi
# Source the actual runscript
if [ -f "$INITDIR/${RC_SVCPREFIX}.lo" ]; then
. "$INITDIR/${RC_SVCPREFIX}.lo"
else
die "$INITDIR/${RC_SVCPREFIX}.lo : Init file missing or invalid path"
fi
netifrc_init() {
# Ensure OPTIONSDIR is present and writeable
mkdir -p "$OPTIONSDIR"
if [ ! -w "$OPTIONSDIR" ]; then
eerror "${OPTIONSDIR} does not exist or is not writeable"
exit 1
fi
# Ensure STATEDIR is present and writeable
mkdir -p "$STATEDIR"
if [ ! -w "$STATEDIR" ]; then
eerror "${STATEDIR} does not exist or is not writeable"
exit 1
fi
}
netifrc_cleanup() {
# Delete all the saved values
rm -f ${OPTIONSDIR}/*
}
rc=0
case $1 in
start)
netifrc_init
start
rc=$?;;
stop)
stop
netifrc_cleanup
rc=$?;;
*)
die "Unrecognised command $1";;
esac
exit $rc
# vi: ts=4 sw=4 noexpandtab
|