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

First install removes all folders from user path #954

Closed
RichardLinde opened this issue Oct 18, 2022 · 17 comments · Fixed by #975
Closed

First install removes all folders from user path #954

RichardLinde opened this issue Oct 18, 2022 · 17 comments · Fixed by #975
Assignees
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@RichardLinde
Copy link

Expected behavior

When first installing the ide I want to use it to add other programs/tools to my already existing programs.
For example, I already had VSCode installed and wanted to use the ide for the first time to install Rancher Desktop.

Actual behavior

When running the start.bat for the first time while %USERPROFILE%\scripts is not added to the user path the installation will instead of adding it to the path replace the path with it. Removing all folders from the path.
In my example the command code was removed and had to be added again.

Steps to reproduce

  1. check content of user path variable (Add a path if there are none)
  2. clean system from devon ide
    2.1 Uninstall devon ide devon uninstall ide
    2.2 Remove %USERPROFILE%\scripts from user path
  3. Install devon ide again by running start.bat
  4. Check if the user Path only contains %USERPROFILE%\scripts

Related/Dependent Issues

Comments/Hints:

Already talked about the issue with @cinnamon-coder-hub

Affected version:

Version: 2022.08.003
OS: Windows 10.0.19044 Build 19044

@RichardLinde RichardLinde added the bug Something isn't working label Oct 18, 2022
@hohwille
Copy link
Member

This is a duplicate of #409.
As you can see on the milestone the issue is already fixed and released.
Simply do an update (download latest version or run devon ide update scripts).
With the new version of devonfw-ide it should be fixed.
Otherwise please give details and reopen.

@hohwille hohwille added this to the release:2022.08.002 milestone Oct 25, 2022
@hohwille hohwille added the duplicate This issue or pull request already exists label Oct 25, 2022
@RichardLinde
Copy link
Author

image

I updated everything and tested again. The setup.bat still removed all folders from the user Path.

  • removed the old devonfw-ide-scripts folder
  • removed the folder %USERPROFILE%\scripts
  • removed the folder %USERPROFILE%\scripts from path
  • downloaded the latest version 2022.08.003
  • unpacked the folder to C:_dev\tutorials\devonfw-ide-scripts-2022.08.003
  • ran the setup.bat by clicking it in the explorer directly
  • log out / log in
  • Path variable only contains %USERPROFILE%\scripts

OUTPUT LOGS

Setting up your devonfw-ide in C:\_dev\tutorials\devonfw-ide-scripts-2022.08.003
Copying devon CLI script to your home directory...
        1 file(s) copied.
Adding C:\Users\rlinde\scripts to your users system PATH

SUCCESS: Specified value was saved.
←[93m"ATTENTION:"←[0m
"Your user PATH environment variable has not been previously set."
"You may need to log-off and log-in again so your PATH changes are properly applied."
"Otherwise you may get errors that devon command has not been found."
Press any key to continue . . .
←[92mThe devon CLI script has been installed to your windows system.←[0m
←[92mNow in any new command shell, you can call devon to setup your IDE enviromennt variables.←[0m
←[92mYou can also provide arguments to devon for advanced usage, e.g. try calling 'devon help'←[0m
Creating main workspace directory
devonfw-ide environment variables have been set for /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003 in workspace main
Copying devon CLI script to your home directory...
Installing devon alias to your .bashrc
Installing devon alias to your .zshrc
The devon CLI script has been installed to your system.
Now in any new shell, you can call devon to setup your IDE environment variables.
You can also provide arguments to devon for advanced usage (try calling 'devon help')
Installing devon autocompletion
Missing your settings at /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/settings and no SETTINGS_URL is defined.
Further details can be found here:
https://github.com/devonfw/ide/blob/master/documentation/settings.asciidoc
Please contact the technical lead of your project to get the SETTINGS_URL for your project.
In case you just want to test devonfw-ide you may simply hit return to install default settings.

Settings URL [https://github.com/devonfw/ide-settings.git]:
Success: run command git
Copying template /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/settings/devon/conf/devon.properties to /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/conf/devon.properties.
Copying template /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/settings/devon/conf/npm/.npmrc to /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/conf/npm/.npmrc.

*** Setting up mvn ***
Starting installation of java in version 11.0.13_8 to /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/software/java

     ..........  ///
    ..........  /////                  dd                                                      fffff
   ..........  ////////               ddd                                                     ffffff
  ..........  //////////              ddd                                                     ff
 ..........    //////////        dddddddd   eeeeeee  vvv         vvv   oooo      nnnnnn     fffffff ww               ww
..........      //////////     dddddddddd  eeeeeeeeee vvv       vvv oooooooooo  nnnnnnnnnn  fffffff  ww      w      ww
..........       //////////   dddd    ddd eeee    eee  vvv     vvv oooo    oooo nnn     nnn   ff      ww    www    ww
..........      //////////    ddd     ddd eeeeeeeeeee   vvv   vvv  ooo      ooo nnn      nnn  ff       ww  wwwww  ww
 ..........    //////////     ddd     ddd eeeeeeeeeee    vvvvvvv   ooo      ooo nnn      nnn  ff        ww wwwww ww
  ..........  //////////       ddd    ddd eeee            vvvvv     ooo    ooo  nnn      nnn  ff         wwww wwww
   ........  //////////         dddddddd   eeeeeeeeee      vvv       oooooooo   nnn      nnn  ff          ww   ww
     .....  //////////            ddddd      eeeeee         v          oooo     nnn      nnn  ff           w   w
      ...  //////////

Welcome to devonfw-ide!
This product and its 3rd party components is open-source software and can be used free (also commercially).
However, before using it you need to read the license agreement with all involved licenses agreements.
With confirming you take notice and agree that there is no warranty for using this product and its 3rd party components.
You are solely responsible for all risk implied by using this software.
You will be able to find it in one of the following locations:
https://github.com/devonfw/ide/blob/master/documentation/LICENSE.asciidoc
Also it is included in /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/devon-ide-doc.pdf

Do you accept these terms of use and all license agreements?
(yes/no): yes

Success: run command git
Trying to download java-11.0.13_8-windows.zip from
Artifact already exists at /c/Users/rlinde/Downloads/devonfw-ide/java-11.0.13_8-windows.zip
To force update please delete the file and run again.
Success: run command unzip
Successfully extracted/moved archive java-11.0.13_8-windows.zip to updates/extracted
Success: run command mv
Successfully installed java
The software java has been added. You need to rerun 'devon' command without arguments or restart your terminal to update your PATH so the newly installed software will be found.
Starting installation of maven in version 3.8.4 to /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/software/maven
Trying to download maven-3.8.4.tar.gz from https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz
Artifact already exists at /c/Users/rlinde/Downloads/devonfw-ide/maven-3.8.4.tar.gz
To force update please delete the file and run again.
Success: run command tar
Successfully extracted/moved archive maven-3.8.4.tar.gz to updates/extracted
Success: run command mv
Successfully installed maven
The software maven has been added. You need to rerun 'devon' command without arguments or restart your terminal to update your PATH so the newly installed software will be found.
Successfully created /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/conf/.m2/settings-security.xml
Starting to create /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/conf/.m2/settings.xml
Successfully created /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/conf/.m2/settings.xml
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: C:\_dev\tutorials\devonfw-ide-scripts-2022.08.003\software\maven
Java version: 11.0.13, vendor: Eclipse Adoptium, runtime: C:\_dev\tutorials\devonfw-ide-scripts-2022.08.003\software\java
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Success: verify installation of maven ('/c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/software/maven/bin/mvn')

*** Setting up npm ***
Starting installation of nodejs in version v14.17.6 to /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/software/node
Trying to download nodejs-v14.17.6-windows.zip from https://nodejs.org/dist/v14.17.6/node-v14.17.6-win-x64.zip
Artifact already exists at /c/Users/rlinde/Downloads/devonfw-ide/nodejs-v14.17.6-windows.zip
To force update please delete the file and run again.
Success: run command unzip
Successfully extracted/moved archive nodejs-v14.17.6-windows.zip to updates/extracted
Success: run command mv
Successfully installed nodejs
The software node has been added. You need to rerun 'devon' command without arguments or restart your terminal to update your PATH so the newly installed software will be found.
/c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/scripts/command/npm: line 26: /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/software/node/bin/npm: No such file or directory
Version  of npm is already installed at /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/software/node/bin/npm
Importing from /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/settings/projects/cobigen.properties...
Project is not active by default.
Skipping project - use force (-f) to setup all projects...
Importing from /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/settings/projects/devon4j.properties...
Project is not active by default.
Skipping project - use force (-f) to setup all projects...
Importing from /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/settings/projects/mts.properties...
Project is not active by default.
Skipping project - use force (-f) to setup all projects...

*** Creating start-scripts for IDE eclipse ***
Repeating command eclipse create-script in workspace /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/workspaces/main
Created script /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/eclipse-main.bat
Created script /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/eclipse-main.bat

*** Creating start-scripts for IDE vscode ***
Repeating command vscode create-script in workspace /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/workspaces/main
Created script /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/vscode-main.bat
Created script /c/_dev/tutorials/devonfw-ide-scripts-2022.08.003/vscode-main.bat

Completed
The operation completed successfully.
The operation completed successfully.
The operation completed successfully.
The operation completed successfully.
The operation completed successfully.
Setup of devonfw-ide completed
Press any key to continue . . .

@hohwille
Copy link
Member

hohwille commented Oct 25, 2022

@RichardLinde thanks for your feedback and helping to improve devonfw-ide.
So if I understood correctly, in your case the bug #409 did not occur but scripts folder was re-added to your PATH.
However, a bug happens on your machine that replaces the existing PATH with %USERPROFILE%\scripts instead of extending it.

From your logs there is nothing to see helping us to see what is wrong.

The bug must come from the windows CMD magic to read and write the PATH in devon.bat starting from here:

echo Adding %USERPROFILE%\scripts to your users system PATH

These 3 lines try to determine the current PATH and IMHO here is where the bug comes from:

  for /F "tokens=2* delims= " %%f IN ('reg query HKCU\Environment /v PATH ^| findstr /i path') do set USER_PATH=%%g
  if "%USER_PATH:~-1,1%" == ";" (
    set "USER_PATH=%USER_PATH:~0,-1%"
  )

As a result you end up inside this IF overwriting your PATH:

if "%USER_PATH%" == "" (

Could you simply revert your PATH manually once more and then create a test.bat file with this:

@echo off
for /F "tokens=2* delims= " %%f IN ('reg query HKCU\Environment /v PATH ^| findstr /i path') do set USER_PATH=%%g
if "%USER_PATH:~-1,1%" == ";" (
  set "USER_PATH=%USER_PATH:~0,-1%"
)
echo PATH=%USER_PATH%
PAUSE

Simply double-click on the test.bat and see what is printed out.

On my machine this is working and giving me the proper PATH content.
Can you provide what happened on your machine?
In case you get PATH= with nothing else (except Press any key to continue . . .) can you remove the 3 lines with the if BLOCK that tries to remove a trailing semicolon and rerun the script?

@hohwille hohwille added the waiting-for-feedback we have asked a question and the issue is pending until an answer is provided label Oct 25, 2022
@hohwille
Copy link
Member

I digged deep in our issues and this seems to be a duplicate of #393 that was closed because we could not reproduce it and got no feedback. Great if we now have the chance to understand and fix this issue with your help @RichardLinde

@RichardLinde
Copy link
Author

Okay sound good.
I'm using the following example folders

C:\Users\rlinde\AppData\Local\Programs\Microsoft VS Code
C:\Users\rlinde\Documents\config\myScripts\bookmark

running the test.bat file worked and gave the following output

PATH=C:\Users\rlinde\AppData\Local\Programs\Microsoft VS Code;C:\Users\rlinde\Documents\config\myScripts\bookmark
Press any key to continue . . .

This is my complete Path System + User

C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.14.2281.0_x64__8wekyb3d8bbwe;C:\Python310\Scripts\;C:\Python310\;C:\Program Files\Eclipse Foundation\jdk-11.0.12.7-hotspot\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\Go\bin;C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Users\rlinde\AppData\Local\Programs\Microsoft VS Code;C:\Users\rlinde\Documents\config\myScripts\bookmark;

My testing

I added a bit to the test.bat simulating the if statement to test if the folder is already set.

@echo off
if 1==1 (

	for /F "tokens=2* delims= " %%f IN ('reg query HKCU\Environment /v PATH ^| findstr /i path') do set USER_PATH=%%g
	if "%USER_PATH:~-1,1%" == ";" (
  		set "USER_PATH=%USER_PATH:~0,-1%"
	)
	
	echo PATH=%USER_PATH%

)
pause

Result

PATH=
Press any key to continue . . .

The path is gone inside the if block.

@RichardLinde
Copy link
Author

I ran the setup.bat file on my home pc and caused the same problem. The test files also return the same results.

@hohwille hohwille removed the waiting-for-feedback we have asked a question and the issue is pending until an answer is provided label Nov 8, 2022
@hohwille
Copy link
Member

hohwille commented Nov 8, 2022

In case you get PATH= with nothing else (except Press any key to continue . . .) can you remove the 3 lines with the if BLOCK that tries to remove a trailing semicolon and rerun the script?

Did you already try this? So is for /F "tokens=2* delims= " %%f IN ('reg query HKCU\Environment /v PATH ^| findstr /i path') do set USER_PATH=%%g already giving you an empty PATH? In that case the linked stackoverflow solution works on most computers but not on yours and I have no clue why so we would need a true windows expert to solve this.

Or is the set "USER_PATH=%USER_PATH:~0,-1%" causing the bug and clearing the PATH? In that case I still do not understand the problem yet, but this would be rather easy to fix with some testing.

@hohwille
Copy link
Member

hohwille commented Nov 8, 2022

Reading again both of your answers.
Are you saying that test.bat worked and echos the correct PATH but the exact same code surrounded with if 1==1 ( and ) does not work and echo an empty PATH??? This makes even less sense after all...

@hohwille
Copy link
Member

hohwille commented Nov 8, 2022

So something is really inconsistent here. I tested the removal of the last semicolon and it works:

C:\Users\hohwille>set USER_PATH=C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.14.2281.0_x64__8wekyb3d8bbwe;C:\Python310\Scripts\;C:\Python310\;C:\Program Files\Eclipse Foundation\jdk-11.0.12.7-hotspot\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\Go\bin;C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Users\rlinde\AppData\Local\Programs\Microsoft VS Code;C:\Users\rlinde\Documents\config\myScripts\bookmark;

C:\Users\hohwille>echo %USER_PATH:~-1,1%
;

C:\Users\hohwille>echo %USER_PATH:~0,-1%
C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.14.2281.0_x64__8wekyb3d8bbwe;C:\Python310\Scripts\;C:\Python310\;C:\Program Files\Eclipse Foundation\jdk-11.0.12.7-hotspot\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\Go\bin;C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Users\rlinde\AppData\Local\Programs\Microsoft VS Code;C:\Users\rlinde\Documents\config\myScripts\bookmark

Therefore the if would match and remove the trailing semicolon.

C:\Users\hohwille>set USER_PATH=C:\Users\rlinde\AppData\Local\Programs\Microsoft VS Code;C:\Users\rlinde\Documents\config\myScripts\bookmark

C:\Users\hohwille>echo %USER_PATH:~-1,1%
k

Here there is no trailing semicolon and therefore the if would not match and not remove the last character.
This is what should happen on your machine.

So to summarize once again:
The test.bat script worked so for /F "tokens=2* delims= " %%f IN ('reg query HKCU\Environment /v PATH ^| findstr /i path') do set USER_PATH=%%g actually is working on your machine but if you put this into an if 1==1 ( it stops working. This is really insane...

@hohwille
Copy link
Member

hohwille commented Nov 8, 2022

@markusschuh Sorry to bother you but this magic command to read the USER_PATH from windows registry was initially written by you. Do you get any clue out of this crazy situation and see what I might be missing?

@alfeilex
Copy link
Member

alfeilex commented Nov 8, 2022

In my research, I found that this may be where the problem is: https://stackoverflow.com/questions/10558316/example-of-delayed-expansion-in-batch-file

So, if this causes the problem, we could either move the echo PATH=%USER_PATH% outside the if block or we use setlocal ENABLEDELAYEDEXPANSION and expand the variables with ! instead of % e.g. echo PATH=!USER_PATH!

I tried this solution and it worked for me.

@RichardLinde
Copy link
Author

I tested again. Everything works, as long as there is no if block around the code.

Working without if block

Result: PATH=C:\Users\rlinde\AppData\Local\Programs\Microsoft VS Code;C:\Users\rlinde\Documents\config\myScripts\bookmark;

@echo off
for /F "tokens=2* delims= " %%f IN ('reg query HKCU\Environment /v PATH ^| findstr /i path') do set USER_PATH=%%g
if "%USER_PATH:~-1,1%" == ";" (
  set "USER_PATH=%USER_PATH:~0,-1%"
)
echo PATH=%USER_PATH%
PAUSE

Not working with if block

Result: PATH=

@echo off
if 1==1 (

    for /F "tokens=2* delims= " %%f IN ('reg query HKCU\Environment /v PATH ^| findstr /i path') do set USER_PATH=%%g
    if "%USER_PATH:~-1,1%" == ";" (
        set "USER_PATH=%USER_PATH:~0,-1%"
    )
    echo PATH=%USER_PATH%
)
PAUSE

Working using !

Result: PATH=C:\Users\rlinde\AppData\Local\Programs\Microsoft VS Code;C:\Users\rlinde\Documents\config\myScripts\bookmark;

@echo off

setlocal ENABLEDELAYEDEXPANSION

if 1==1 (

    for /F "tokens=2* delims= " %%f IN ('reg query HKCU\Environment /v PATH ^| findstr /i path') do set USER_PATH=%%g
    if "%USER_PATH:~-1,1%" == ";" (
        set "USER_PATH=%USER_PATH:~0,-1%"
    )
    echo PATH=!USER_PATH!
)
PAUSE

@hohwille
Copy link
Member

@RichardLinde thanks for your support, testing and feedback. And thanks @alfeilex for nailing down the problem.
We now have all the information to fix this problem. This is really great. 👍

@alfeilex
Copy link
Member

@RichardLinde Would you be so kind as to test our fix on your system? Here is the branch with the included fix.

https://github.com/alfeilex/ide/tree/fix-devon.bat

So all you have to do is replace the devon.bat in the script folder with the corrected devon.bat from this branch and try to reproduce the error.

If you have any questions, please feel free to contact me. Thank you very much.

@RichardLinde
Copy link
Author

With the update, the installation is working as expected, appending to the path variable instead of overwriting.

@hohwille
Copy link
Member

@RichardLinde thanks again for your great support in reporting the bug and testing so we could finally trace it down.
The release 2022.11.002 has been released today containing the fix of this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants