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

Adding feature to check if shell is bash or windows cli. #119

Closed
wants to merge 2 commits into from

Conversation

ThomasAunvik
Copy link

@ThomasAunvik ThomasAunvik commented Sep 17, 2020

Closes #111
Closes appleboy/scp-action#39

Possibly Closes: appleboy/scp-action#3

Related Comment: #50 (comment)

Once this check passes, it will use commands specific command to it's operating shell. For example, at the command rm -rf %s would not work on either terminals, cause -rf is not a valid argument, the command exists for powershell, but not on the normal windows command line. So you would have to change that to DEL command isntead, which is supported by both powershell and windows command line.

Another fix is added is mkdir, though mkdir exists for the commandline, it returns an error when the folder already exists, and the -p argument is not valid for mkdir, and instead creates an actual folder called -p. This is why we use if not exist %s mkdir %s, cause it checks if that folder exists before creating it. This works on the windows command line, but not on powershell, but if we can, we could also add a check for powershell and use a powershell command instead.

Once this check passes, it will use commands specific command to it\'s operating shell. For example, at the command `rm -rf %s` would not work on either terminals, cause -rf is not a valid argument, the command exists for powershell, but not on the normal windows command line. So you would have to change that to `DEL` command isntead, which is supported by both powershell and windows command line.\n\nAnother fix is added is mkdir, though mkdir exists for the commandline, it returns an error when the folder already exists, and the -p argument is not valid for mkdir, and instead creates an actual folder called `-p`. This is why we use `if not exist %s mkdir %s`, cause it checks if that folder exists before creating it. This works on the windows command line, but not on powershell, but if we can, we could also add a check for powershell and use a powershell command instead.
@ThomasAunvik
Copy link
Author

Another workaround to these issues, are to change the default shell of OpenSSH to be a bash shell. By installing git, and use the git bash terminal as the default shell.

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Users\user\AppData\Local\Programs\Git\bin\bash.exe" -PropertyType String -Force

https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_server_configuration

@appleboy appleboy force-pushed the master branch 3 times, most recently from 5658167 to 5672c12 Compare January 1, 2023 07:16
@appleboy appleboy closed this in #166 Apr 9, 2023
appleboy added a commit that referenced this pull request Apr 9, 2023
- Change the `rmcmd` and `mkdircmd` functions to accept an OS parameter
- Remove `command_windows.go` file
- Modify `removeDestFile` and `Exec` functions to use the OS parameter
- Add OS detection logic to `removeAllDestFile` and `Exec` functions
- Modify `TestRemoveDestFile` function to use the OS parameter

fix #119
@appleboy
Copy link
Owner

appleboy commented Apr 9, 2023

@ThomasAunvik Thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants