32 lines
1.3 KiB
Bash
Executable File
32 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# /proc/cmdline parser (from Gentoo Wiki)
|
|
cmdline() {
|
|
local value
|
|
value=" $(cat /proc/cmdline) "
|
|
value="${value#* $1=}"
|
|
value="${value%% *}"
|
|
[ "$value" != "" ] && echo "$value"
|
|
}
|
|
|
|
[ -f "/etc/wireguard/adlin.token" ] && WGTOKEN=$(cat /etc/wireguard/adlin.token)
|
|
[ -z "${WGTOKEN}" ] && WGTOKEN=$(cmdline adlin.token)
|
|
[ -z "${WGTOKEN}" ] && {
|
|
echo -n "You didn't define your token to connect the network. Please copy it into /var/lib/adlin/wireguard/adlin.token and reboot."
|
|
exit 1
|
|
}
|
|
[ -f "/etc/wireguard/adlin.conf" ] && WGPRVKEY=$(sed 's/^.*PrivateKey *= *//p;d' /etc/wireguard/adlin.conf)
|
|
[ -z "${WGPRVKEY}" ] && WGPRVKEY=$(/usr/bin/wg genkey)
|
|
WGPUBKEY=$(echo $WGPRVKEY | /usr/bin/wg pubkey)
|
|
while ! { echo -e "[Interface]\nPrivateKey = ${WGPRVKEY}"; /usr/bin/curl -f -d '{"pubkey": "'$WGPUBKEY'"}' https://adlin.nemunai.re/api/wg/$(echo -n "$WGTOKEN" | /usr/bin/sha512sum | /usr/bin/cut -d ' ' -f 1); } > /etc/wireguard/adlin.conf
|
|
do
|
|
exit 1
|
|
done
|
|
echo -n "${WGTOKEN}" > /etc/wireguard/adlin.token
|
|
/sbin/ip link add dev wg0 type wireguard
|
|
/usr/bin/wg setconf wg0 /etc/wireguard/adlin.conf
|
|
/sbin/ip address add dev wg0 $(sed 's/^.*MyIPv6=//p;d' /etc/wireguard/adlin.conf)
|
|
/sbin/ip link set up dev wg0
|
|
/sbin/ip -6 route del default
|
|
/sbin/ip -6 route add default via $(sed 's/^.*GWIPv6=//p;d' /etc/wireguard/adlin.conf) pref high
|