From 513a95ec4b92c157c0c65de8d50b03031b508a70 Mon Sep 17 00:00:00 2001 From: Alexandre CATTEAU Date: Sat, 3 Jun 2023 12:33:17 +0200 Subject: [PATCH] Add variables and install script --- .gitignore | 2 ++ README.md | 12 +++++++++- install.sh | 23 +++++++++++++++++++ .../set-ip-routes.service | 4 ++-- variables.conf.template | 6 +++++ 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 install.sh rename set-ip-routes.service => systemd-templates/set-ip-routes.service (62%) create mode 100644 variables.conf.template diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99a3140 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +variables.conf +.disabled diff --git a/README.md b/README.md index 721d388..941ae09 100644 --- a/README.md +++ b/README.md @@ -5,5 +5,15 @@ This repository contains setup or configuration files for [LibreELEC](https://li ### WireGuard VPN setup * copy `~/.config/wireguard/wireguard.config.sample` to a new file, and adjust the parameters (see https://wiki.libreelec.tv/configuration/wireguard for reference) + +### Files * `set-resolv-conf.sh` moves last DNS entry up in `/etc/resolv.conf` (is called after VPN initialization) -* TOFINISH +* `variables.conf.template` contains examples variables definitions, and should be copied locally to `variables.conf` + (with any required modifications). +* `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. + +### TODO +* Define a trigger diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..7fdf8d0 --- /dev/null +++ b/install.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +run_directory=$(dirname $(readlink -f "$0")) + +source "$run_directory/variables.conf" + +if [ -f $run_directory/.disabled ]; then + echo "Installation is disabled. Exiting..." + exit 0 +fi + +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 + +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 "Finished install. Exiting..." +exit 0 diff --git a/set-ip-routes.service b/systemd-templates/set-ip-routes.service similarity index 62% rename from set-ip-routes.service rename to systemd-templates/set-ip-routes.service index 01748dc..86e22ef 100644 --- a/set-ip-routes.service +++ b/systemd-templates/set-ip-routes.service @@ -4,6 +4,6 @@ Description=Update IP routes after connecting to VPN [Service] Type=oneshot ExecStart=/usr/sbin/ip route del default dev wg0 -ExecStart=/usr/sbin/ip route add 192.168.0.63 dev wg0 -ExecStart=/usr/sbin/ip route add 192.168.3.0/24 dev wg0 +ExecStart=/usr/sbin/ip route add PH_DNS dev wg0 +ExecStart=/usr/sbin/ip route add PH_NETWORK dev wg0 ExecStart=/storage/libreelec-conf/set-resolv-conf.sh diff --git a/variables.conf.template b/variables.conf.template new file mode 100644 index 0000000..3404257 --- /dev/null +++ b/variables.conf.template @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# Copy this file as variables.conf, with the correct values + +dns_server=192.168.0.63 +target_network=192.168.3.0/24