-
-
Save Loopshape/fe8feea8a69e29b3ab1b155e74e35bad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
goto :start | |
:x | |
@set "redir=" | |
@set "args=%*" | |
@set "a=%1" | |
@if "%a:~0,5%" == "/out:" ( | |
@set "redir=> %a:~5%" | |
@shift | |
@rem The shift command does not affect %*. | |
@call set args=%%args:%a% =%% | |
) | |
@rem @echo + %args% >&2 | |
%args% %redir% | |
@exit /b | |
:start | |
set force=false | |
if [%1]==[/f] ( | |
set force=true | |
shift | |
) | |
if not [%1]==[] (set CYGBINSLASH=%1) | |
set croot=%CYGBINSLASH:~0,-5% | |
if [%croot%]==[] ( | |
echo Need a parameter of a CYGBINSLASH variable consisting of the bin directory of a Cygwin installation followed by a slash. | |
exit /b 1 | |
) | |
set caparch=x86_64 | |
if [%PROCESSOR_ARCHITECTURE%]==[x86] ( | |
if not defined PROCESSOR_ARCHITEW6432 ( | |
set caparch="x86" | |
) | |
) | |
echo caparch is %caparch% | |
set cygarch=%caparch% | |
for /F "tokens=* USEBACKQ" %%f in (`%CYGBINSLASH%uname -m`) do (set cygarch=%%f) | |
echo cygarch is %cygarch% | |
set curlok=true | |
if not exist %croot%\etc\pki\ca-trust\extracted\pem\tls-ca-bundle.pem (set curlok=false) | |
@rem Avoid stopping the script by a dialog box "Entry Point Not Found" or | |
@rem "System Error" ("...dll is missing from your computer") | |
reg add HKLM\SYSTEM\CurrentControlSet\Control\Windows /v ErrorMode /t REG_DWORD /f /d 2 | |
%CYGBINSLASH%curl -V || (set curlok=false) | |
if [%curlok%.%force%]==[true.false] goto :end_of_update | |
@rem The if then branch does shows its commands in a batch, making it difficult | |
@rem to track the progress. Use "goto" instead of having to escape round | |
@rem brackets and instead of having to "call :x [/out:outfile] ...". | |
powershell "$r = New-Object System.Net.WebClient; $r.DownloadFile('https://cygwin.com/setup-%cygarch%.exe', 'setup-%cygarch%.exe')" | |
net stop sshd | |
net stop cygrunsrv | |
wmic process where (executablepath like '%cygbinslash:\=\\%%%') get ProcessId,CommandLine /value > cygpids.txt | |
type cygpids.txt | |
for /f "tokens=2 delims==" %%g in ('type cygpids.txt ^| findstr /l "ProcessId="') do ( | |
@rem The for loop shows its commands in a batch just as if/then, but every | |
@rem iteration takes fewer commands. Iterations show step by step. | |
wmic process where ^(ProcessId=%%g^) call Terminate | |
) | |
icacls %CYGBINSLASH%sh.exe | |
icacls %CYGBINSLASH% | |
icacls %croot% | |
takeown /F %croot% /R /D Y > nul | |
icacls %croot% /reset /T /C /L /Q | |
icacls %croot% /remove:g everyone none /t /c /l /q | |
icacls %croot% /grant:r users:(OI)(CI)(F) /c /l /q | |
icacls %croot% /inheritance:e /t /c /l /q | |
%croot%\bin\getfacl /bin/setfacl | |
%croot%\bin\getfacl /bin/find | |
@rem %croot%\bin\setfacl -bk /bin/find | |
@rem | |
@rem The following setfacl command would disable permission inheritance of the | |
@rem local group Users grant, preventing invocation of Apache HTTPD CGI scripts | |
@rem via a local user account. The getfacl output would lack the additional | |
@rem "user", "group", "other" and "default" entries. | |
@rem %croot%\bin\find -P / -xdev -exec /bin/setfacl -bk "{}" + | |
@rem move /y %CYGBINSLASH%sh.exe %CYGBINSLASH%sh-bad.exe | |
@rem del /f /q %CYGBINSLASH%sh.exe | |
copy /b /y %CYGBINSLASH%bash.exe %CYGBINSLASH%sh.exe | |
@echo Running Cygwin's setup-%cygarch%.exe in %CD%... | |
setup-%cygarch%.exe --verbose --upgrade-also --no-desktop --no-shortcuts --no-startmenu --quiet-mode --no-admin ^ | |
--root "%croot%" --local-package-dir "%croot%\install" ^ | |
--site "http://mirrors.kernel.org/sourceware/cygwin/" ^ | |
--packages base-cygwin,base-files,cygwin,coreutils,cygutils,dash,gzip,unzip,zip,bzip2,bash,diffutils,file,findutils,grep,gawk,hostname,run,sed,tar,tzcode,tzdata,util-linux,vim,which,curl,ca-certificates | |
@echo Done with setup-%cygarch%.exe. | |
set curlok=true | |
%CYGBINSLASH%curl -V || (set curlok=false) | |
:end_of_update | |
if not [%curlok%]==[true] ( | |
echo Curl install failed | |
exit /b 1 | |
) | |
exit /b 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment