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

When on WSL2, check for internal host IP #11

Merged
merged 2 commits into from
Jan 13, 2023
Merged
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: 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}"