Created
July 7, 2022 22:19
-
-
Save shvchk/675c363f8f241ec2d3300295d86de5cd to your computer and use it in GitHub Desktop.
Wive-NG WireGuard client startup script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
LOG="logger -t wireguard" | |
. /etc/scripts/global.sh | |
iface="wgcli0" | |
included_routes="/pss/wg_client_included_routes" | |
$LOG "WireGuard custom routes script: started" | |
$LOG "Waiting for $iface" | |
until ip route | grep "default dev $iface"; do sleep 1; done | |
ip route del default dev "$iface" | |
$LOG "Adding routes" | |
if [ -s "$included_routes" ]; then | |
dos2unix -u "$included_routes" | |
filtered_included_routes="/tmp/$(basename $included_routes).$(date +%s)" | |
grep -oE '^([0-9]+\.){3}[0-9]+(/[0-9]+)?' "$included_routes" > "$filtered_included_routes" | |
while IFS= read -r dest; do | |
[ -z "$dest" ] && continue | |
$LOG -p debug "route replace $dest dev $iface metric $wgmetric" | |
ip -4 route replace "$dest" dev "$iface" metric "$wgmetric" | |
done < "$filtered_included_routes" | |
$LOG "Added total $(wc -l $filtered_included_routes) routes" | |
rm -f "$filtered_included_routes" | |
fi | |
$LOG "WireGuard custom routes script: finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment