From c4c272b2eb84dbc21a11fc87087318f7e49db9df Mon Sep 17 00:00:00 2001 From: dadevel Date: Fri, 28 May 2021 11:31:21 +0200 Subject: [PATCH] add setup script --- .gitignore | 1 - README.md | 15 +++++++-------- setup.sh | 9 +++++++++ wg-netns.py | 1 - wg-netns@.service | 5 +++-- 5 files changed, 19 insertions(+), 12 deletions(-) create mode 100755 setup.sh diff --git a/.gitignore b/.gitignore index 372c13e..c18dd8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ __pycache__/ - diff --git a/README.md b/README.md index 588c5ab..a57b630 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,21 @@ # wg-netns -[wg-quick](https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8) with support for linux network namespaces. -It's a simple python script that implements the steps described at [wireguard.com/netns](https://www.wireguard.com/netns/#ordinary-containerization). +[wg-quick](https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8) with support for Linux network namespaces. +A simple Python script that implements the steps described at [wireguard.com/netns](https://www.wireguard.com/netns/#ordinary-containerization). ## Setup Requirements: -- Linux - Python 3.7 or newer -- `ip` from `iproute2` -- `wg` from `wireguard-tools` +- `ip` from iproute2 +- `wg` from wireguard-tools -Just download the script and make it executable. +Installation: ~~~ bash -mkdir -p ~/.local/bin/ && curl -o ~/.local/bin/wg-netns https://raw.githubusercontent.com/dadevel/wg-netns/master/wg-netns.py && chmod 0755 ~/.local/bin/wg-netns +git clone --depth 1 https://github.com/dadevel/wg-netns.git +sudo ./wg-netns/setup.sh ~~~ ## Usage @@ -144,4 +144,3 @@ socat tcp-listen:1234,reuseaddr,fork "exec:ip netns exec ns-example socat stdio # terminal 3, test access curl http://127.0.0.1:1234/hello.txt ~~~ - diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..ca40084 --- /dev/null +++ b/setup.sh @@ -0,0 +1,9 @@ +#!/bin/sh +PS4='> ' +set -eux + +PREFIX="${PREFIX:-/usr/local}" + +cd "$(dirname "$0")" +install -m 0755 -D ./wg-netns.py "$PREFIX/bin/wg-netns" +install -m 0644 -D ./wg-netns@.service "$PREFIX/lib/systemd/system/wg-netns@.service" diff --git a/wg-netns.py b/wg-netns.py index b4933f7..0af7e76 100755 --- a/wg-netns.py +++ b/wg-netns.py @@ -211,4 +211,3 @@ if __name__ == '__main__': raise print(f'error: {e} ({e.__class__.__name__})', file=sys.stderr) sys.exit(2) - diff --git a/wg-netns@.service b/wg-netns@.service index fd92867..8b2a860 100644 --- a/wg-netns@.service +++ b/wg-netns@.service @@ -9,9 +9,10 @@ Environment=WG_ENDPOINT_RESOLUTION_RETRIES=infinity Environment=DEBUG_LEVEL=1 ExecStart=wg-netns up ./%i.json ExecStop=wg-netns down ./%i.json -WorkingDirectory=%E/wg-netns RemainAfterExit=yes +WorkingDirectory=%E/wg-netns +ConfigurationDirectory=wg-netns + [Install] WantedBy=multi-user.target -