purplesyringa / win-sudo

Add `sudo` command to Git Bash
MIT License
183 stars 55 forks source link

Bugfix install.sh path to bashrc with spaces #43

Closed michaelchanwork closed 4 years ago

michaelchanwork commented 4 years ago

Currently, if username has a space, script will fail; path to bashrc/bash_profile gets broken up

$ curl -s https://raw.githubusercontent.com/imachug/win-sudo/master/install.sh | sh
Downloading win-sudo...
mkdir: created directory '/c/Users/Michael Chan/bin'
mkdir: created directory '/c/Users/Michael Chan/bin/win-sudo'
Processing /c/Users/Michael Chan/.bashrc
sh: line 28: [: /c/Users/Michael: binary operator expected
Processing /c/Users/Michael Chan/.bash_profile
sh: line 28: [: /c/Users/Michael: binary operator expected
Win-sudo successfully installed!

Have tested fix, ensures spaces in path are handled, resulting in

mkdir: created directory '/c/Users/Michael Chan/bin'
mkdir: created directory '/c/Users/Michael Chan/bin/win-sudo'
Processing /c/Users/Michael Chan/.bashrc
Appending sudo initialization to  /c/Users/Michael Chan/.bashrc
Win-sudo successfully installed!

And sudo works!

michaelchanwork commented 4 years ago

DO NOT MERGE, from testing looks like another bug, will update

michaelchanwork commented 4 years ago

Some bugs in sudo itself, also regarding spaces

sudo netsh advfirewall firewall add rule name="lolchat" dir=out remoteip=172.65.244.155 protocol=TCP action=block
realpath: Chan/bin/win-sudo/s/sudobackend: No such file or directory
UAC elevation was canceled

After taking out dev/null redirection from powershell line and adding a debugging line(won't output anything if there is no error) {noformat} \; (\$Error[0]).InvocationInfo.Line {noformat}

Start-Process : A positional parameter cannot be found that accepts argument 'Files/Git/'.
At line:1 char:1
+ Start-Process "C:\Program Files\Git\usr\bin\bash" "/c/Users/Michael C ...                                                                             + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand

Start-Process "C:\Program Files\Git\usr\bin\bash" "/c/Users/Michael Chan/bin/win-sudo/s/sudobackend", "/tmp/.sudo.5526" -Verb RunAs -WorkingDirectory C:/Program Files/Git/ -WindowStyle Hidden; ($Error[0]).InvocationInfo.Line

From there, it hangs(hard to tell with all the changes to fds and pipes), but from what I can tell, isn't related to the changes I made nor spaces in paths. Feel free to make edits/merge.

I'll open an issue regarding the hanging after the powershell command, if you have suggestions let me know.

purplesyringa commented 4 years ago

Thank you.