Add unit files.
This commit is contained in:
parent
804008933d
commit
c3b283d51f
4 changed files with 58 additions and 7 deletions
10
Makefile
10
Makefile
|
@ -1,10 +1,14 @@
|
|||
SCRIPT := gre-on-wg.sh
|
||||
SCRIPT_NAME := $(SCRIPT:.sh=)
|
||||
PREFIX ?= /usr/local
|
||||
PREFIX_UNIT ?= /etc
|
||||
|
||||
install: install-bin
|
||||
install: install-bin install-unit
|
||||
|
||||
install-bin: $(SCRIPT)
|
||||
install -D -m 0755 -o root -g root -T $(SCRIPT) $(PREFIX)/bin/$(SCRIPT_NAME)
|
||||
install -D -m 0755 -o root -g root -T $< $(PREFIX)/bin/$(SCRIPT_NAME)
|
||||
|
||||
.PHONY: install install-bin
|
||||
install-unit: gre-on-wg.target gre-on-wg@.service
|
||||
install -D -m 0644 -o root -g root $^ $(PREFIX_UNIT)/systemd/system
|
||||
|
||||
.PHONY: install install-bin install-unit
|
||||
|
|
39
gre-on-wg.sh
39
gre-on-wg.sh
|
@ -2,6 +2,8 @@
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
_="${DEBUG:=}"
|
||||
|
||||
strstrip() {
|
||||
sed -E -e 's/^\s*//' -e 's/\s*$//'
|
||||
}
|
||||
|
@ -90,17 +92,30 @@ create_networks() {
|
|||
finish_br "$br_name" "$local_ip_trans"
|
||||
}
|
||||
|
||||
main() {
|
||||
up() {
|
||||
local filepath translation_filepath
|
||||
local r local_ip remote_ips local_ip_trans
|
||||
filepath="$1"
|
||||
translation_filepath=
|
||||
if [[ "$filepath" =~ .*/.* ]]; then
|
||||
# path, not a name, leave as is
|
||||
:
|
||||
else
|
||||
filepath="/etc/wireguard/$filepath"
|
||||
if [[ $# -eq 1 ]]; then
|
||||
translation_filepath="$filepath"
|
||||
fi
|
||||
filepath="/etc/wireguard/$filepath.conf"
|
||||
fi
|
||||
|
||||
if [[ -z "$translation_filepath" ]]; then
|
||||
translation_filepath="$2"
|
||||
if [[ "$translation_filepath" =~ .*/.* ]]; then
|
||||
# path, not a name, leave as is
|
||||
:
|
||||
else
|
||||
translation_filepath="/etc/gre-on-wg/$filepath.conf"
|
||||
fi
|
||||
fi
|
||||
translation_filepath="$(sort <<< "$2" | uniq)"
|
||||
|
||||
r="$(read_wg_conf "$filepath")"
|
||||
local_ip="$(head -n1 <<< "$r")"
|
||||
|
@ -112,4 +127,20 @@ main() {
|
|||
create_networks "$(basename --suffix='.conf' "$filepath")" "$local_ip" "$local_ip_trans" "$remote_ips"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
down() {
|
||||
local filepath
|
||||
local wg_name link
|
||||
filepath="$1"
|
||||
if [[ "$filepath" =~ .*/.* ]]; then
|
||||
# path, not a name, leave as is
|
||||
:
|
||||
else
|
||||
filepath="/etc/wireguard/$filepath.conf"
|
||||
fi
|
||||
wg_name="$(basename --suffix=.conf "$filepath")"
|
||||
for link in $(ip link list | grep -Eo '^[0-9]+:\s+wg0[^:@]+' | sed -E 's/[0-9]+:\s+//'); do
|
||||
$DEBUG ip link del "$link"
|
||||
done
|
||||
}
|
||||
|
||||
"$@"
|
||||
|
|
2
gre-on-wg.target
Normal file
2
gre-on-wg.target
Normal file
|
@ -0,0 +1,2 @@
|
|||
[Unit]
|
||||
Description=GRETAP over wg-quick
|
14
gre-on-wg@.service
Normal file
14
gre-on-wg@.service
Normal file
|
@ -0,0 +1,14 @@
|
|||
[Unit]
|
||||
Description=GRETAP over wg-quick network for %I
|
||||
After=wg-quick@%I
|
||||
Wants=wg-quick@%I
|
||||
PartOf=gre-on-wg.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/bin/gre-on-wg up %i
|
||||
ExecStop=/usr/bin/gre-on-wg down %i
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in a new issue