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

-NoNewLine not supported #5

Open
goffinf opened this issue Jun 15, 2020 · 8 comments
Open

-NoNewLine not supported #5

goffinf opened this issue Jun 15, 2020 · 8 comments
Assignees
Labels
bug Something isn't working priority:high
Milestone

Comments

@goffinf
Copy link

goffinf commented Jun 15, 2020

Hey,

Thanks for recognising this issue and putting something out there that can help.

I appreciate this script is provided with a '.. use at your own risk' caveat, but, I found the following when trying to run reset ... which you probably already know about but could consider documenting ?

wslsync.ps1 -r

>> We're going to change old WSL IP's to new. Do you want to continue?
[Enter to continue / CTRL + C to abort]:

>> 🤔 Last known WSL IP:
>> 🤖 Current WSL IP:

Method invocation failed because [System.Object[]] does not contain a method named 'Trim'.
At C:\images\wsl2\wslsync\modules\r.ps1:24 char:5
+ if ($lastIP.Trim() -eq $newIP.Trim()) {
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

... then later ...

>> ✅ Updated config
Out-String : A parameter cannot be found that matches parameter name 'NoNewLine'.
At C:\images\wsl2\wslsync\modules\restart.ps1:9 char:56
+ ... ningDistro = (wsl --list --running -q | Out-String -NoNewLine).Trim() ...
+                                                        ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Out-String], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.OutStringCommand

I am running this version of POSH from an Administrator prompt on WIndows 10 Pro (build 2004):

$PSversionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Neither the config.json nor hosts file were actually changed.

Kind Regards

Fraser.

@widersky widersky added the bug Something isn't working label Jun 15, 2020
@widersky widersky self-assigned this Jun 15, 2020
@widersky
Copy link
Owner

Hi!

Thank you for your report, I will correct this issue in the near future :)

@widersky widersky added this to the v1.0.0 milestone Jun 16, 2020
@widersky
Copy link
Owner

widersky commented Jun 17, 2020

@goffinf

Need some info with this issue:

  1. Do you use Windows Terminal or the built-in powershella?
  2. You got any problems besides that?

In my case, on POSH 5.1, the script is spreading errors at every step. I will look into this problem, but I need to know the answers to these questions :)

@widersky widersky added the question Further information is requested label Jun 17, 2020
@goffinf
Copy link
Author

goffinf commented Jun 17, 2020

Hey @widersky (Adrian),

I was just using a regular POSH admin command prompt NOT from Windows Terminal.

By other problems, if you mean with running other Powershell scripts, then 'No', not that I am aware of.

Interestingly I just tried this again using a POSH admin command prompt AND a POSH tab in Windows Terminal (started as Admin) and got a slightly different outcome than earlier (and exactly the same in both terminals).

This was from the POSH command-line:

scriptSettings = C:\images\wsl2\wslsync\config.json

💻 WSLSync v1.0.0 Beta 1
📋 Author: widersky (https://github.com/widersky/)
🐛 Issues? Ideas? Feel free to write here: https://github.com/widersky/wslsync/issues

✋ The script is at an early stage of development. You use it at your own risk!


======================================================================================


>> We're going to change old WSL IP's to new. Do you want to continue?
[Enter to continue / CTRL + C to abort]:

>> 🤔 Last known WSL IP: 172.21.204.97
>> 🤖 Current WSL IP:

You cannot call a method on a null-valued expression.
At C:\images\wsl2\wslsync\modules\r.ps1:24 char:5
+ if ($lastIP.Trim() -eq $newIP.Trim()) {
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 C 172.17.0.1 o 172.17.0.1 p 172.17.0.1 y 172.17.0.1 r 172.17.0.1 i 172.17.0.1 g 172.17.0.1 h 172.17.0.1 t 172.17.0.1   172.17.0.1 ( 172.17.0.1 c 172.17.0.1 ) 172.17.0.1   172.17.0.1 1 172.17.0.1 9 172.17.0.1 9 172.17.0.1 3 172.17.0.1 - 172.17.0.1 2 172.17.0.1 0 172.17.0.1 0 172.17.0.1 9 172.17.0.1   172.17.0.1 M 172.17.0.1 i 172.17.0.1 c 172.17.0.1 r 172.17.0.1 o 172.17.0.1 s 172.17.0.1 o 172.17.0.1 f 172.17.0.1 t 172.17.0.1   172.17.0.1 C 172.17.0.1 o 172.17.0.1 r 172.17.0.1 p 172.17.0.1 . 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 T 172.17.0.1 h 172.17.0.1 i 172.17.0.1 s 172.17.0.1   172.17.0.1 i 172.17.0.1 s 172.17.0.1   172.17.0.1 a 172.17.0.1   172.17.0.1 s 172.17.0.1 a 172.17.0.1 m 172.17.0.1 p 172.17.0.1 l 172.17.0.1 e 172.17.0.1   172.17.0.1 H 172.17.0.1 O 172.17.0.1 S 172.17.0.1 T 172.17.0.1 S 172.17.0.1   172.17.0.1 f 172.17.0.1 i 172.17.0.1 l 172.17.0.1 e 172.17.0.1   172.17.0.1 u 172.17.0.1 s 172.17.0.1 e 172.17.0.1 d 172.17.0.1   172.17.0.1 b 172.17.0.1 y 172.17.0.1   172.17.0.1 M 172.17.0.1 i 172.17.0.1 c 172.17.0.1 r 172.17.0.1 o 172.17.0.1 s 172.17.0.1 o 172.17.0.1 f 172.17.0.1 t 172.17.0.1   172.17.0.1 T 172.17.0.1 C 172.17.0.1 P 172.17.0.1 / 172.17.0.1 I 172.17.0.1 P 172.17.0.1   172.17.0.1 f 172.17.0.1 o 172.17.0.1 r 172.17.0.1   172.17.0.1 W 172.17.0.1 i 172.17.0.1 n 172.17.0.1 d 172.17.0.1 o 172.17.0.1 w 172.17.0.1 s 172.17.0.1 . 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 T 172.17.0.1 h 172.17.0.1 i 172.17.0.1 s 172.17.0.1   172.17.0.1 f 172.17.0.1 i 172.17.0.1 l 172.17.0.1 e 172.17.0.1   172.17.0.1 c 172.17.0.1 o 172.17.0.1 n 172.17.0.1 t 172.17.0.1 a 172.17.0.1 i 172.17.0.1 n 172.17.0.1 s 172.17.0.1   172.17.0.1 t 172.17.0.1 h 172.17.0.1 e 172.17.0.1   172.17.0.1 m 172.17.0.1 a 172.17.0.1 p 172.17.0.1 p 172.17.0.1 i 172.17.0.1 n 172.17.0.1 g 172.17.0.1 s 172.17.0.1   172.17.0.1 o 172.17.0.1 f 172.17.0.1   172.17.0.1 I 172.17.0.1 P 172.17.0.1   172.17.0.1 a 172.17.0.1 d 172.17.0.1 d 172.17.0.1 r 172.17.0.1 e 172.17.0.1 s 172.17.0.1 s 172.17.0.1 e 172.17.0.1 s 172.17.0.1   172.17.0.1 t 172.17.0.1 o 172.17.0.1   172.17.0.1 h 172.17.0.1 o 172.17.0.1 s 172.17.0.1 t 172.17.0.1   172.17.0.1 n 172.17.0.1 a 172.17.0.1 m 172.17.0.1 e 172.17.0.1 s 172.17.0.1 . 172.17.0.1   172.17.0.1 E 172.17.0.1 a 172.17.0.1 c 172.17.0.1 h 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 e 172.17.0.1 n 172.17.0.1 t 172.17.0.1 r 172.17.0.1 y 172.17.0.1   172.17.0.1 s 172.17.0.1 h 172.17.0.1 o 172.17.0.1 u 172.17.0.1 l 172.17.0.1 d 172.17.0.1   172.17.0.1 b 172.17.0.1 e 172.17.0.1   172.17.0.1 k 172.17.0.1 e 172.17.0.1 p 172.17.0.1 t 172.17.0.1   172.17.0.1 o 172.17.0.1 n 172.17.0.1   172.17.0.1 a 172.17.0.1 n 172.17.0.1   172.17.0.1 i 172.17.0.1 n 172.17.0.1 d 172.17.0.1 i 172.17.0.1 v 172.17.0.1 i 172.17.0.1 d 172.17.0.1 u 172.17.0.1 a 172.17.0.1 l 172.17.0.1   172.17.0.1 l 172.17.0.1 i 172.17.0.1 n 172.17.0.1 e 172.17.0.1 . 172.17.0.1   172.17.0.1 T 172.17.0.1 h 172.17.0.1 e 172.17.0.1   172.17.0.1 I 172.17.0.1 P 172.17.0.1   172.17.0.1 a 172.17.0.1 d 172.17.0.1 d 172.17.0.1 r 172.17.0.1 e 172.17.0.1 s 172.17.0.1 s 172.17.0.1   172.17.0.1 s 172.17.0.1 h 172.17.0.1 o 172.17.0.1 u 172.17.0.1 l 172.17.0.1 d 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 b 172.17.0.1 e 172.17.0.1   172.17.0.1 p 172.17.0.1 l 172.17.0.1 a 172.17.0.1 c 172.17.0.1 e 172.17.0.1 d 172.17.0.1   172.17.0.1 i 172.17.0.1 n 172.17.0.1   172.17.0.1 t 172.17.0.1 h 172.17.0.1 e 172.17.0.1   172.17.0.1 f 172.17.0.1 i 172.17.0.1 r 172.17.0.1 s 172.17.0.1 t 172.17.0.1   172.17.0.1 c 172.17.0.1 o 172.17.0.1 l 172.17.0.1 u 172.17.0.1 m 172.17.0.1 n 172.17.0.1   172.17.0.1 f 172.17.0.1 o 172.17.0.1 l 172.17.0.1 l 172.17.0.1 o 172.17.0.1 w 172.17.0.1 e 172.17.0.1 d 172.17.0.1   172.17.0.1 b 172.17.0.1 y 172.17.0.1   172.17.0.1 t 172.17.0.1 h 172.17.0.1 e 172.17.0.1   172.17.0.1 c 172.17.0.1 o 172.17.0.1 r 172.17.0.1 r 172.17.0.1 e 172.17.0.1 s 172.17.0.1 p 172.17.0.1 o 172.17.0.1 n 172.17.0.1 d 172.17.0.1 i 172.17.0.1 n 172.17.0.1 g 172.17.0.1   172.17.0.1 h 172.17.0.1 o 172.17.0.1 s 172.17.0.1 t 172.17.0.1   172.17.0.1 n 172.17.0.1 a 172.17.0.1 m 172.17.0.1 e 172.17.0.1 . 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 T 172.17.0.1 h 172.17.0.1 e 172.17.0.1   172.17.0.1 I 172.17.0.1 P 172.17.0.1   172.17.0.1 a 172.17.0.1 d 172.17.0.1 d 172.17.0.1 r 172.17.0.1 e 172.17.0.1 s 172.17.0.1 s 172.17.0.1   172.17.0.1 a 172.17.0.1 n 172.17.0.1 d 172.17.0.1   172.17.0.1 t 172.17.0.1 h 172.17.0.1 e 172.17.0.1   172.17.0.1 h 172.17.0.1 o 172.17.0.1 s 172.17.0.1 t 172.17.0.1   172.17.0.1 n 172.17.0.1 a 172.17.0.1 m 172.17.0.1 e 172.17.0.1   172.17.0.1 s 172.17.0.1 h 172.17.0.1 o 172.17.0.1 u 172.17.0.1 l 172.17.0.1 d 172.17.0.1   172.17.0.1 b 172.17.0.1 e 172.17.0.1   172.17.0.1 s 172.17.0.1 e 172.17.0.1 p 172.17.0.1 a 172.17.0.1 r 172.17.0.1 a 172.17.0.1 t 172.17.0.1 e 172.17.0.1 d 172.17.0.1   172.17.0.1 b 172.17.0.1 y 172.17.0.1   172.17.0.1 a 172.17.0.1 t 172.17.0.1   172.17.0.1 l 172.17.0.1 e 172.17.0.1 a 172.17.0.1 s 172.17.0.1 t 172.17.0.1   172.17.0.1 o 172.17.0.1 n 172.17.0.1 e 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 s 172.17.0.1 p 172.17.0.1 a 172.17.0.1 c 172.17.0.1 e 172.17.0.1 . 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 A 172.17.0.1 d 172.17.0.1 d 172.17.0.1 i 172.17.0.1 t 172.17.0.1 i 172.17.0.1 o 172.17.0.1 n 172.17.0.1 a 172.17.0.1 l 172.17.0.1 l 172.17.0.1 y 172.17.0.1 , 172.17.0.1   172.17.0.1 c 172.17.0.1 o 172.17.0.1 m 172.17.0.1 m 172.17.0.1 e 172.17.0.1 n 172.17.0.1 t 172.17.0.1 s 172.17.0.1   172.17.0.1 ( 172.17.0.1 s 172.17.0.1 u 172.17.0.1 c 172.17.0.1 h 172.17.0.1   172.17.0.1 a 172.17.0.1 s 172.17.0.1   172.17.0.1 t 172.17.0.1 h 172.17.0.1 e 172.17.0.1 s 172.17.0.1 e 172.17.0.1 ) 172.17.0.1   172.17.0.1 m 172.17.0.1 a 172.17.0.1 y 172.17.0.1   172.17.0.1 b 172.17.0.1 e 172.17.0.1   172.17.0.1 i 172.17.0.1 n 172.17.0.1 s 172.17.0.1 e 172.17.0.1 r 172.17.0.1 t 172.17.0.1 e 172.17.0.1 d 172.17.0.1   172.17.0.1 o 172.17.0.1 n 172.17.0.1   172.17.0.1 i 172.17.0.1 n 172.17.0.1 d 172.17.0.1 i 172.17.0.1 v 172.17.0.1 i 172.17.0.1 d 172.17.0.1 u 172.17.0.1 a 172.17.0.1 l 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 l 172.17.0.1 i 172.17.0.1 n 172.17.0.1 e 172.17.0.1 s 172.17.0.1   172.17.0.1 o 172.17.0.1 r 172.17.0.1   172.17.0.1 f 172.17.0.1 o 172.17.0.1 l 172.17.0.1 l 172.17.0.1 o 172.17.0.1 w 172.17.0.1 i 172.17.0.1 n 172.17.0.1 g 172.17.0.1   172.17.0.1 t 172.17.0.1 h 172.17.0.1 e 172.17.0.1   172.17.0.1 m 172.17.0.1 a 172.17.0.1 c 172.17.0.1 h 172.17.0.1 i 172.17.0.1 n 172.17.0.1 e 172.17.0.1   172.17.0.1 n 172.17.0.1 a 172.17.0.1 m 172.17.0.1 e 172.17.0.1   172.17.0.1 d 172.17.0.1 e 172.17.0.1 n 172.17.0.1 o 172.17.0.1 t 172.17.0.1 e 172.17.0.1 d 172.17.0.1   172.17.0.1 b 172.17.0.1 y 172.17.0.1   172.17.0.1 a 172.17.0.1   172.17.0.1 ' 172.17.0.1 # 172.17.0.1 ' 172.17.0.1   172.17.0.1 s 172.17.0.1 y 172.17.0.1 m 172.17.0.1 b 172.17.0.1 o 172.17.0.1 l 172.17.0.1 . 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 F 172.17.0.1 o 172.17.0.1 r 172.17.0.1   172.17.0.1 e 172.17.0.1 x 172.17.0.1 a 172.17.0.1 m 172.17.0.1 p 172.17.0.1 l 172.17.0.1 e 172.17.0.1 : 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1 1 172.17.0.1 0 172.17.0.1 2 172.17.0.1 . 172.17.0.1 5 172.17.0.1 4 172.17.0.1 . 172.17.0.1 9 172.17.0.1 4 172.17.0.1 . 172.17.0.1 9 172.17.0.1 7 172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1 r 172.17.0.1 h 172.17.0.1 i 172.17.0.1 n 172.17.0.1 o 172.17.0.1 . 172.17.0.1 a 172.17.0.1 c 172.17.0.1 m 172.17.0.1 e 172.17.0.1 . 172.17.0.1 c 172.17.0.1 o 172.17.0.1 m 172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1 # 172.17.0.1   172.17.0.1 s 172.17.0.1 o 172.17.0.1 u 172.17.0.1 r 172.17.0.1 c 172.17.0.1 e 172.17.0.1   172.17.0.1 s 172.17.0.1 e 172.17.0.1 r 172.17.0.1 v 172.17.0.1 e 172.17.0.1 r 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1 3 172.17.0.1 8 172.17.0.1 . 172.17.0.1 2 172.17.0.1 5 172.17.0.1 . 172.17.0.1 6 172.17.0.1 3 172.17.0.1 . 172.17.0.1 1 172.17.0.1 0 172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1 x 172.17.0.1 . 172.17.0.1 a 172.17.0.1 c 172.17.0.1 m 172.17.0.1 e 172.17.0.1 . 172.17.0.1 c 172.17.0.1 o 172.17.0.1 m 172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1 # 172.17.0.1   172.17.0.1 x 172.17.0.1   172.17.0.1 c 172.17.0.1 l 172.17.0.1 i 172.17.0.1 e 172.17.0.1 n 172.17.0.1 t 172.17.0.1   172.17.0.1 h 172.17.0.1 o 172.17.0.1 s 172.17.0.1 t 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 l 172.17.0.1 o 172.17.0.1 c 172.17.0.1 a 172.17.0.1 l 172.17.0.1 h 172.17.0.1 o 172.17.0.1 s 172.17.0.1 t 172.17.0.1   172.17.0.1 n 172.17.0.1 a 172.17.0.1 m 172.17.0.1 e 172.17.0.1   172.17.0.1 r 172.17.0.1 e 172.17.0.1 s 172.17.0.1 o 172.17.0.1 l 172.17.0.1 u 172.17.0.1 t 172.17.0.1 i 172.17.0.1 o 172.17.0.1 n 172.17.0.1   172.17.0.1 i 172.17.0.1 s 172.17.0.1   172.17.0.1 h 172.17.0.1 a 172.17.0.1 n 172.17.0.1 d 172.17.0.1 l 172.17.0.1 e 172.17.0.1 d 172.17.0.1   172.17.0.1 w 172.17.0.1 i 172.17.0.1 t 172.17.0.1 h 172.17.0.1 i 172.17.0.1 n 172.17.0.1   172.17.0.1 D 172.17.0.1 N 172.17.0.1 S 172.17.0.1   172.17.0.1 i 172.17.0.1 t 172.17.0.1 s 172.17.0.1 e 172.17.0.1 l 172.17.0.1 f 172.17.0.1 . 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1          172.17.0.1 1 172.17.0.1 2 172.17.0.1 7 172.17.0.1 . 172.17.0.1 0 172.17.0.1 . 172.17.0.1 0 172.17.0.1 . 172.17.0.1 1 172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1 l 172.17.0.1 o 172.17.0.1 c 172.17.0.1 a 172.17.0.1 l 172.17.0.1 h 172.17.0.1 o 172.17.0.1 s 172.17.0.1 t 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1          172.17.0.1 : 172.17.0.1 : 172.17.0.1 1 172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1   172.17.0.1 l 172.17.0.1 o 172.17.0.1 c 172.17.0.1 a 172.17.0.1 l 172.17.0.1 h 172.17.0.1 o 172.17.0.1 s 172.17.0.1 t 172.17.0.1   172.17.0.1

>> 📋 Refreshed 21 entries

>> ✅ Updated config
Out-String : A parameter cannot be found that matches parameter name 'NoNewLine'.
At C:\images\wsl2\wslsync\modules\restart.ps1:9 char:56
+ ... ningDistro = (wsl --list --running -q | Out-String -NoNewLine).Trim() ...
+                                                        ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Out-String], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.OutStringCommand

Copyright (c) Microsoft Corporation. All rights reserved.

Usage: wsl.exe [Argument] [Options...] [CommandLine]

Arguments for running Linux binaries:

    If no command line is provided, wsl.exe launches the default shell.

    --exec, -e <CommandLine>
        Execute the specified command without using the default Linux shell.

    --
        Pass the remaining command line as is.

Options:
    --distribution, -d <Distro>
        Run the specified distribution.

    --user, -u <UserName>
        Run as the specified user.

Arguments for managing Windows Subsystem for Linux:

    --export <Distro> <FileName>
        Exports the distribution to a tar file.
        The filename can be - for standard output.

    --import <Distro> <InstallLocation> <FileName> [Options]
        Imports the specified tar file as a new distribution.
        The filename can be - for standard input.

        Options:
            --version <Version>
                Specifies the version to use for the new distribution.

    --list, -l [Options]
        Lists distributions.

        Options:
            --all
                List all distributions, including distributions that are currently
                being installed or uninstalled.

            --running
                List only distributions that are currently running.

            --quiet, -q
                Only show distribution names.

            --verbose, -v
                Show detailed information about all distributions.

    --set-default, -s <Distro>
        Sets the distribution as the default.

    --set-default-version <Version>
        Changes the default install version for new distributions.

    --set-version <Distro> <Version>
        Changes the version of the specified distribution.

    --shutdown
        Immediately terminates all running distributions and the WSL 2 lightweight utility virtual machine.

    --terminate, -t <Distro>
        Terminates the specified distribution.

    --unregister <Distro>
        Unregisters the distribution.

    --help
        Display usage information.
There is no distribution with the supplied name.

>> 🐧 Detected running distro: , restarted to sync virtual hosts
>> ✅ Done!

This from Windows Terminal:

scriptSettings = C:\images\wsl2\wslsync\config.json

💻 WSLSync v1.0.0 Beta 1
📋 Author: widersky (https://github.com/widersky/)
🐛 Issues? Ideas? Feel free to write here: https://github.com/widersky/wslsync/issues

✋ The script is at an early stage of development. You use it at your own risk!


======================================================================================


>> We're going to change old WSL IP's to new. Do you want to continue?
[Enter to continue / CTRL + C to abort]:

>> 🤔 Last known WSL IP:
>> 🤖 Current WSL IP:

Method invocation failed because [System.Object[]] does not contain a method named 'Trim'.
At C:\images\wsl2\wslsync\modules\r.ps1:24 char:5
+ if ($lastIP.Trim() -eq $newIP.Trim()) {
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 C 172.17.0.1 o 172.17.0.1 p 172.17.0.1 y 172.17.0.1 r 172.17.0.1 i 172.17.0.1 g 172.17.0.1 h 172.17.0.1 t 172.17.0.1   172.17.0.1 ( 172.17.0.1 c 172.17.0.1 ) 172.17.0.1   172.17.0.1 1 172.17.0.1 9 172.17.0.1 9 172.17.0.1 3 172.17.0.1 - 172.17.0.1 2 172.17.0.1 0 172.17.0.1 0 172.17.0.1 9 172.17.0.1   172.17.0.1 M 172.17.0.1 i 172.17.0.1 c 172.17.0.1 r 172.17.0.1 o 172.17.0.1 s 172.17.0.1 o 172.17.0.1 f 172.17.0.1 t 172.17.0.1   172.17.0.1 C 172.17.0.1 o 172.17.0.1 r 172.17.0.1 p 172.17.0.1 . 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1
>> 📋 Refreshed entry:  172.17.0.1 # 172.17.0.1   172.17.0.1 T 172.17.0.1 h 172.17.0.1 i 172.17.0.1 s 172.17.0.1   172.17.0.1 i 172.17.0.1 s 172.17.0.1   172.17.0.1 a 172.17.0.1   172.17.0.1 s 172.17.0.1 a 172.17.0.1 m 172.17.0.1 p 172.17.0.1 l 172.17.0.1 e 172.17.0.1   172.17.0.1 H 172.17.0.1 O 172.17.0.1 S 172.17.0.1 T 172.17.0.1 S 172.17.0.1   172.17.0.1 f 172.17.0.1 i 172.17.0.1 l 172.17.0.1 e 172.17.0.1   172.17.0.1 u 172.17.0.1 s 172.17.0.1 e 172.17.0.1 d 172.17.0.1   172.17.0.1 b 172.17.0.1 y 172.17.0.1   172.17.0.1 M 172.17.0.1 i 172.17.0.1 c 172.17.0.1 r 172.17.0.1 o 172.17.0.1 s 172.17.0.1 o 172.17.0.1 f 172.17.0.1 t 172.17.0.1   172.17.0.1 T 172.17.0.1 C 172.17.0.1 P 172.17.0.1 / 172.17.0.1 I 172.17.0.1 P 172.17.0.1   172.17.0.1 f 172.17.0.1 o 172.17.0.1 r 172.17.0.1   172.17.0.1 W 172.17.0.1 i 172.17.0.1 n 172.17.0.1 d 172.17.0.1 o 172.17.0.1 w 172.17.0.1 s 172.17.0.1 . 172.17.0.1
...

    --help
        Display usage information.
There is no distribution with the supplied name.

>> 🐧 Detected running distro: , restarted to sync virtual hosts
>> ✅ Done!

The hosts file was NOT updated.

The config.json file was updated the first time I ran it ... then the second time, that change was removed. The change was (I think) the lastKnownIP array had the correct WSL IP (172.21.204.97) but concaternated with 172.17.0.1 ?? ... on the second run, all of that was removed (and so it is for all subsequent runs) ... it now looks like this:

{
    "firstRun":  0,
    "hostsPath":  "C:/Windows/System32/drivers/etc/hosts",
    "lastKnownIP":  [

                    ],
    "htdocsRoot":  "",
    "localDomain":  ".test",
    "extras":  {
                   "usingXampp":  0
               }
}

HTHs

Fraser

@widersky
Copy link
Owner

@goffinf Thanks for the information, I'll focus on this problem while working on the next release.

@widersky widersky modified the milestones: v1.0.0, v0.9.2 Beta Jun 18, 2020
@widersky widersky added priority:high and removed question Further information is requested labels Jun 18, 2020
@goffinf
Copy link
Author

goffinf commented Jun 24, 2020

Hey @widersky (Adrian),

I have been playing around with a variety of scripts for getting the WSL distro IP address and updating the Windows hosts file.

A couple of observations which may be of use to you when you get to working on your next release (or not - but figured its worth sharing). I based my experiments on Michael Belgium's simple script, but they could apply to your more sophisticated solution also IMHO.

  1. Using hostname -I is unreliable. I found that this worked some of the time but not consistently. At present my distros (I have several) are returning multiple IPs (eth0, docker0 and br-xxxxx) which is clearly not whats needed:
goffinf@DESKTOP-XXXXXXX:~$ hostname -I
172.26.103.206 172.17.0.1 172.22.0.1

I have found this approach to be reliable (shown from with Powershell because the call syntax is critical .. specifically using -- instead of -e .... also note $selectedDistro - more on that below):

$wslIp = (wsl -d $selectedDistro -- ip route get 1 | sed -n 's/^.src ([0-9.]) .*$/\1/p')`

  1. I run multiple WSL distros so I wanted the update to the Windows hosts file to ONLY change those for a selected distro. To enable that I did 2 things.

a. I used a specific naming convention in the hosts file, where each entry carries the name of the distribution it belongs to. For example ... these belong to my distro called 'Ubuntu-20.04'

# wsl2.Ubuntu-20.04.local
172.26.103.206                                 wsl2.Ubuntu-20.04.local
172.26.103.206                                 sample.k3d.wsl2.Ubuntu-20.04.local
172.26.103.206                                 rancher.server.wsl2.Ubuntu-20.04.local
172.26.103.206                                 kubernetes.dashboard.Ubuntu-20.04.local
172.31.46.82                                   rancher-k3d.wsl2.Ubuntu-20.04.local

and these to another distro configured for systemd and k8s called 'Ubuntu-20.04-systemd-k8s'

# wsl2.Ubuntu-20.04-systemd-k8s.local
172.26.103.206                                 wsl2.Ubuntu-20.04-systemd-k8s.local
172.26.103.206                                 rancher.server.wsl2.Ubuntu-20.04-systemd-k8s.local
172.26.103.206                                 rancher.k3d.academy.wsl2.Ubuntu-20.04-systemd-k8s.local
172.26.103.206                                 ingress.test.wsl2.Ubuntu-20.04-systemd-k8s.local
172.26.103.206                                 kubernetes.dashboard.wsl2.Ubuntu-20.04-systemd-k8s.local
172.31.46.82                                   nginx.wsl2.Ubuntu-20.04-systemd-k8s.local
172.26.103.206                                 kubernetes.dashboard.ingress.wsl2.Ubuntu-20.04-systemd-k8s.local
172.26.103.206                                 portainer.wsl2.Ubuntu-20.04-systemd-k8s.local

b. In the Powershell script, I prompt the user for the name of the distribution they want to work with (using a Out-GridView populated from wsl --list), .. that sets the $selectedDistro variable mentioned above ... I use that variable to select the list of domains to update, then foreach around those and update just those entries in the hosts file using the Carbon module:

...
switch ( $selectedDistro ) {

    Ubuntu_20_04 {
        $domains = $domains_Ubuntu_20_04
    }
    Ubuntu_20_04_systemd_k8s {
        $domains = $domains_Ubuntu_20_04_systemd_k8s
    }
}

foreach($domain in $domains) {
    Write-Output "Updating the WSL host IP address for for domain $domain for distribution $selectedDistro to $wslIp"
    Set-HostsEntry -IPAddress $wslIp -HostName $domain
}

Anyway, not sure if any of this is of use to you, but hopefully it is.

Kind Regards

Fraser.

@goffinf
Copy link
Author

goffinf commented Jun 24, 2020

Hmmm, a bit more reading about network namespaces with WSL2 ... it appears that currently ALL WSL instances share the SAME network namespace because they also share the same virtual machine which has a single network interface. Therefore the IP address for all instances will also be the same !

It is possible to add another virtual ip to eth0 but AFAIK that wont be reachable from the Windows side.

It is possible to create an additional network namespaces within each WSL distro and have processes attach to that ... but that isn't available OOTB and I'm not sure its worth the effort ... back to the drawing board (sigh)

The tip around getting the WSL IP might still be useful though

@widersky
Copy link
Owner

widersky commented Jun 25, 2020

Thak you for your helpful knowledge @goffinf !

For now, the most important problem with WSL2 is that you cannot work with web applications on node servers: microsoft/WSL#4204 . There are a lot of similar issues on WSL github.

In my case, applications based on - for example - reactjs simply do not load. None of the tricks given on the github are working. I saw that this problem disappeared and appeared back several times after Windows updates.

@goffinf
Copy link
Author

goffinf commented Jun 25, 2020

You are welcome. I waited for quite a while before deciding to move from WSL1 to WSL2 (I didn’t really want to run an insiders build on my main laptop), but I too have found it to be quite a frustrating experience. I spin up a lot of Kubernetes clusters and was really hoping that multi-node and multi-cluster setup would be easier as well as configuring Ingress and LoadBalancer services, but the constantly changing IP and all WSL instances sharing the same IP have been a massive distraction rather than a step forwards.

I’ll keep plugging away though, I’m a massive DevSecOps advocate and local WSL environments have a part to play.

Thanks so much for adding to body of capability and knowledge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:high
Projects
None yet
Development

No branches or pull requests

2 participants