Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detach config #74

Merged
merged 3 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions distro/scripts/defaults.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Virtual interface name
TAP_NAME="eth1"

# Network configuration
VPNKIT_GATEWAY_IP="192.168.67.1"
VPNKIT_HOST_IP="192.168.67.2"
VPNKIT_LOWEST_IP="192.168.67.3"
VPNKIT_HIGHEST_IP="192.168.67.14"

# Set any to enable debug
VPNKIT_DEBUG=

# Connectivity test endpoints
CHECK_DNS=1.1.1.1
CHECK_HOST=example.com
9 changes: 6 additions & 3 deletions distro/scripts/startup.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/sh

LOG_PATH="/var/log/wsl-vpnkit.log"
USERPROFILE=$(wslpath "$(powershell.exe -c 'Write-Host -NoNewline $env:USERPROFILE')")
USERPROFILE=$(wslpath "$(powershell.exe -NoLogo -NoProfile -c 'Write-Host -NoNewline $env:USERPROFILE')")
sakai135 marked this conversation as resolved.
Show resolved Hide resolved
VERSION="$(cat /app/version)"

touch $LOG_PATH
Expand All @@ -24,10 +24,13 @@ Logs for wsl-vpnkit can be viewed here.

wsl.exe -d $WSL_DISTRO_NAME tail -f $LOG_PATH

Config for wsl-vpnkit can be edited here. See the wsl-vpnkit script for possible values.
Config for wsl-vpnkit can be edited here.

$USERPROFILE/wsl-vpnkit/wsl-vpnkit.conf
wsl.exe -d $WSL_DISTRO_NAME cat /usr/sbin/wsl-vpnkit

Run the following command to see the default values.

wsl.exe -d $WSL_DISTRO_NAME cat /app/defaults.conf

Press [enter] key to continue...
"
Expand Down
2 changes: 1 addition & 1 deletion distro/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ docker export $CONTAINER_ID | gzip > $DUMP
docker container rm $CONTAINER_ID
ls -la $DUMP

wsl.exe --unregister wsl-vpnkit
wsl.exe --unregister wsl-vpnkit || :
wsl.exe --import wsl-vpnkit "$USERPROFILE\\wsl-vpnkit" $DUMP
rm $DUMP
wsl.exe -d wsl-vpnkit
37 changes: 23 additions & 14 deletions wsl-vpnkit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

POWERSHELL="$(command -v powershell.exe || echo '/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe')"
USERPROFILE=$(wslpath "$($POWERSHELL -c 'Write-Host -NoNewline $env:USERPROFILE')")
USERPROFILE=$(wslpath "$($POWERSHELL -NoLogo -NoProfile -c 'Write-Host -NoNewline $env:USERPROFILE')")
CONF_PATH="$USERPROFILE/wsl-vpnkit/wsl-vpnkit.conf"
SOCKET_PATH="/var/run/wsl-vpnkit.sock"
PIPE_PATH="//./pipe/wsl-vpnkit"
Expand All @@ -11,24 +11,33 @@ VPNKIT_STORE="/files/vpnkit/vpnkit.exe"
NPIPERELAY_STORE="/files/npiperelay/npiperelay.exe"
VPNKIT_PATH="$USERPROFILE/wsl-vpnkit/wsl-vpnkit.exe"
NPIPERELAY_PATH="$USERPROFILE/wsl-vpnkit/npiperelay.exe"
TAP_NAME="eth1"
VPNKIT_GATEWAY_IP="192.168.67.1"
VPNKIT_HOST_IP="192.168.67.2"
VPNKIT_LOWEST_IP="192.168.67.3"
VPNKIT_HIGHEST_IP="192.168.67.14"
VPNKIT_WSL2_IP="$VPNKIT_LOWEST_IP"
VPNKIT_DEBUG=
WSL2_GATEWAY_IP="$(cat /etc/resolv.conf | awk '/^nameserver/ {print $2}')"
CHECK_HOST=example.com
DNS_IP="$VPNKIT_GATEWAY_IP"
CHECK_DNS=1.1.1.1

echo "starting wsl-vpnkit"

# Load defaults
if [ -f "/app/defaults.conf" ]; then
. /app/defaults.conf
fi
# Load user config if needed
if [ -f "$CONF_PATH" ]; then
. "$CONF_PATH"
echo "loaded $CONF_PATH"
. "$CONF_PATH"
echo "loaded config: $CONF_PATH"
fi

# Failsafe configuration to run as a standalone script
TAP_NAME=${TAP_NAME:-eth1}
VPNKIT_GATEWAY_IP=${VPNKIT_GATEWAY_IP:-192.168.67.1}
VPNKIT_HOST_IP=${VPNKIT_HOST_IP:-192.168.67.2}
VPNKIT_LOWEST_IP=${VPNKIT_LOWEST_IP:-192.168.67.3}
VPNKIT_HIGHEST_IP=${VPNKIT_HIGHEST_IP:-192.168.67.14}
VPNKIT_DEBUG=${VPNKIT_DEBUG:-}
CHECK_DNS=${CHECK_DNS:-1.1.1.1}
CHECK_HOST=${CHECK_HOST:-example.com}

VPNKIT_WSL2_IP="$VPNKIT_LOWEST_IP"
WSL2_GATEWAY_IP="$(cat /etc/resolv.conf | awk '/^nameserver/ {print $2}')"
DNS_IP="$VPNKIT_GATEWAY_IP"

hash () {
md5sum "$1" | awk '{ print $1 }'
}
Expand Down