Skip to content

Commit

Permalink
Merge pull request #11 from RolandRosier/use_internal_wsl2_host_ip
Browse files Browse the repository at this point in the history
When on WSL2, check for internal host IP
  • Loading branch information
mviereck authored Jan 13, 2023
2 parents b56a972 + 85e0655 commit 6b28460
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions runx
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,6 @@ check_host() { # Check host environment
Did not detect WSL, Cygwin or MSYS2." ;;
esac

[ "$0" = "$BASH_SOURCE" ] && Sourced="no" || Sourced="yes"
verbose "Script is being sourced yes/no: $Sourced"

case $Winsubsystem in
MSYS2|CYGWIN)
Winsubmount="$(cygpath.exe -u "c:/" | rmcr | sed s%/c/%%)"
Expand All @@ -326,6 +323,7 @@ check_host() { # Check host environment

# Get IP of Windows host
[ "$Hostip" = "localhost" ] && Hostip="127.0.0.1"
[ "$Hostip" ] || [ "$Winsubsystem" = "WSL2" ] && Hostip="$(ip route list default | awk '{print $3}')"
[ "$Hostip" ] || Hostip="$(ipconfig.exe | rmcr | grep 'IPv4' | grep -o '192\.168\.[0-9]*\.[0-9]*' | head -n1 )"
[ "$Hostip" ] || Hostip="$(ipconfig.exe | rmcr | grep 'IPv4' | grep -o '10\.0\.[0-9]*\.[0-9]*' | head -n1 )"
[ "$Hostip" ] || Hostip="$(ipconfig.exe | rmcr | grep 'IPv4' | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' | head -n1 )"
Expand Down Expand Up @@ -644,6 +642,9 @@ declare_variables() {
parse_options() {
local Shortoptions Longoptions Parsererror

[ "$0" = "$BASH_SOURCE" ] && Sourced="no" || Sourced="yes"
verbose "Script is being sourced yes/no: $Sourced"

Shortoptions="dghv"
Longoptions="cleanup,clipboard::,desktop,display:,gpu,help,no-auth,size:,vcxsrv,verbose,version,xwin"
Longoptions="$Longoptions,ip:" # experimental
Expand All @@ -659,7 +660,7 @@ parse_options() {
-d|--desktop) Desktopmode="yes" ;;
--display) Newdisplaynumber="${2:-}" ; shift ;;
-g|--gpu) Sharegpu="yes" ;;
-h|--help) usage; finish ;;
-h|--help) usage; Exitcode=0 ;;
--ip) Hostip="${2:-}" ; shift ;;
--no-auth) Xauthentication="no" ;;
--size) Screensize="${2:-}" ; shift ;;
Expand Down Expand Up @@ -777,8 +778,8 @@ export XAUTHORITY=$XAUTHORITY" > "$Xenvfile"

trap finish EXIT
declare_variables
check_host
parse_options "$@"
[ "$Cleanup" = "yes" ] && cleanup && Exitcode="${Exitcode:-0}"
[ -z "$Exitcode" ] && main
[ -z "$Exitcode" ] && check_host
[ -z "$Exitcode" ] && [ "$Cleanup" = "yes" ] && cleanup && Exitcode="${Exitcode:-0}"
[ -z "$Exitcode" ] && main
finish "${Exitcode:-0}"

0 comments on commit 6b28460

Please sign in to comment.