From 216702239d95e87893a469081d9379ad30a003e9 Mon Sep 17 00:00:00 2001 From: Alexandre CATTEAU Date: Sat, 3 Jun 2023 12:54:27 +0200 Subject: [PATCH] Add Systemd path as trigger for service --- README.md | 4 ++-- install.sh | 5 +++-- systemd-templates/set-ip-routes.path | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 systemd-templates/set-ip-routes.path diff --git a/README.md b/README.md index 941ae09..b1581d4 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ https://wiki.libreelec.tv/configuration/wireguard for reference) * `systemd-templates/` contains Systemd units templates for detecting VPN connection, and apply routes and DNS modifications. #### Installation -* `install.sh` script copies Systemd templates to their destination, and enables trigger. +* `install.sh` script copies Systemd templates to their destination, and enables trigger (Systemd path). ### TODO -* Define a trigger +* RAS diff --git a/install.sh b/install.sh index 7fdf8d0..7f0286b 100644 --- a/install.sh +++ b/install.sh @@ -13,11 +13,12 @@ echo "Copying Systemd units to system directory..." $sudo cp $run_directory/systemd-templates/set-ip-routes.service /etc/systemd/system/ $sudo sed -i -e "s/PH_DNS/$dns_server/g" /etc/systemd/system/set-ip-routes.service $sudo sed -i -e "s:PH_NETWORK:$target_network:g" /etc/systemd/system/set-ip-routes.service +$sudo cp $run_directory/systemd-templates/set-ip-routes.path /etc/systemd/system/ echo "Reloading Systemd..." $sudo systemctl daemon-reload -echo "Enabling timer (not starting it, either do it manually or reboot)..." # TODO replace by new trigger -$sudo systemctl enable conf-sync.timer +echo "Enabling path unit (not starting it, either do it manually or reboot)..." +$sudo systemctl enable set-ip-routes.path echo "Finished install. Exiting..." exit 0 diff --git a/systemd-templates/set-ip-routes.path b/systemd-templates/set-ip-routes.path new file mode 100644 index 0000000..c239118 --- /dev/null +++ b/systemd-templates/set-ip-routes.path @@ -0,0 +1,6 @@ +[Unit] +Description=Detect WireGuard VPN activation + +[Path] +PathExists=/sys/class/net/wg0 +Unit=set-ip-routes.service