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 1 commit
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
22 changes: 19 additions & 3 deletions distro/scripts/startup.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#! /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)"
CONF_PATH="$USERPROFILE/wsl-vpnkit/wsl-vpnkit.conf"

touch $LOG_PATH

mkdir -p "$USERPROFILE/wsl-vpnkit/"
if [ ! -f "$CONF_PATH" ]; then
cp /app/defaults.conf "$CONF_PATH"
fi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To minimize the changes automatically made by the script to the user's machine, I would rather this to be added as part of the startup text so users could manually create the config file. That will remove the need to care about migrating the config if something ever changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. The main motivation was to separate the evaluated variables from the constants.


echo "
wsl-vpnkit $VERSION
This distro is only intended for running wsl-vpnkit.
Expand All @@ -15,6 +21,13 @@ Run the following commands from Windows or other WSL 2 distros to use.
wsl.exe -d $WSL_DISTRO_NAME service wsl-vpnkit start
wsl.exe -d $WSL_DISTRO_NAME service wsl-vpnkit stop

or just create an alias:

echo 'alias vpnkit="wsl.exe -d wsl-vpnkit service wsl-vpnkit"' >/etc/profile.d/vpnkit.sh
source /etc/profile.d/vpnkit.sh
vpnkit start
vpnkit stop
psmolkin marked this conversation as resolved.
Show resolved Hide resolved

The following files will be copied if they do not already exist.

$USERPROFILE/wsl-vpnkit/wsl-vpnkit.exe
Expand All @@ -24,10 +37,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
39 changes: 24 additions & 15 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"
if [ -f "$CONF_PATH" ]; then
. "$CONF_PATH"
echo "loaded $CONF_PATH"

mkdir -p "$USERPROFILE/wsl-vpnkit/"
if [ -f /app/defaults.conf ]; then
if [ ! -f "$CONF_PATH" ]; then
cp /app/defaults.conf "$CONF_PATH"
fi
. /app/defaults.conf
. "$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