Add variables and install script

This commit is contained in:
Alexandre CATTEAU 2023-06-03 12:33:17 +02:00
parent e0c7ce3fca
commit 513a95ec4b
5 changed files with 44 additions and 3 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
variables.conf
.disabled

View File

@ -5,5 +5,15 @@ This repository contains setup or configuration files for [LibreELEC](https://li
### WireGuard VPN setup ### WireGuard VPN setup
* copy `~/.config/wireguard/wireguard.config.sample` to a new file, and adjust the parameters (see * copy `~/.config/wireguard/wireguard.config.sample` to a new file, and adjust the parameters (see
https://wiki.libreelec.tv/configuration/wireguard for reference) 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) * `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

23
install.sh Normal file
View File

@ -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

View File

@ -4,6 +4,6 @@ Description=Update IP routes after connecting to VPN
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/usr/sbin/ip route del default dev wg0 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 PH_DNS dev wg0
ExecStart=/usr/sbin/ip route add 192.168.3.0/24 dev wg0 ExecStart=/usr/sbin/ip route add PH_NETWORK dev wg0
ExecStart=/storage/libreelec-conf/set-resolv-conf.sh ExecStart=/storage/libreelec-conf/set-resolv-conf.sh

6
variables.conf.template Normal file
View File

@ -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