Created
May 16, 2025 21:45
-
-
Save urbans0ft/21ccd17139ca4ddc7e5f425fb803242f to your computer and use it in GitHub Desktop.
Install and auto-update cygwin from command line.
This file contains hidden or 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
| @echo off | |
| cls | |
| :: CONSTANTS | |
| :: Path cygwin should get installed to. | |
| set cygwin_dir=C:\Cygwin | |
| set cygwin_url=https://cygwin.com/setup-x86_64.exe | |
| :: The script calls itself after copying to the installation directory with the parameter | |
| :: --origin set to the originating file. So it can delete the obsolete copy it originated from. | |
| if not [%1] == [] ( | |
| if ["%1"] == ["--origin"] ( | |
| if exist "%~2" ( | |
| echo $ del "%~2" | |
| del "%~2" | |
| ) else ( | |
| echo Origin file '%~2' not found! | |
| goto :eof | |
| ) | |
| ) else ( | |
| echo Wrong command line args! | |
| goto :eof | |
| ) | |
| ) | |
| echo cygwin_url = %cygwin_url% | |
| echo cygwin_dir = %cygwin_dir% | |
| for %%i in ("%cygwin_url%") do ( set setup_file=%%~nxi ) | |
| echo setup_file = %setup_file% | |
| set setup_path=%cygwin_dir%\%setup_file% | |
| echo setup_path = %setup_path% | |
| :: create setup dir if necessary | |
| if not exist %cygwin_dir% mkdir %cygwin_dir% | |
| :: copy itself and execute again. ATTENTION: %~dp0 contains trailing '\' | |
| if not [%cygwin_dir%\] == [%~dp0] ( | |
| echo $ copy "%~f0" "%cygwin_dir%" /y | |
| copy "%~f0" "%cygwin_dir%" /y | |
| echo $ "%cygwin_dir%\%~nx0" --origin "%~f0" | |
| "%cygwin_dir%\%~nx0" --origin "%~f0" | |
| goto :eof | |
| ) | |
| echo $ pushd %cygwin_dir% | |
| pushd %cygwin_dir% | |
| echo $ curl "%cygwin_url%" -o"%setup_file%" | |
| curl "%cygwin_url%" -o"%setup_file%" | |
| echo $ %setup_path% -a x86_64 -D -f -l "%cygwin_dir%" -d -n -O -s http://cygwin.mirror.constant.com/ -R "%cygwin_dir%" -g -v -W | |
| %setup_path% -a x86_64 -f -l "%cygwin_dir%" -d -n -O -s http://cygwin.mirror.constant.com/ -R "%cygwin_dir%" -g -v -W | |
| echo $ popd | |
| popd | |
| :: REFERENCES | |
| :: https://ss64.com/nt/syntax-args.html | |
| :: https://cygwin.com/faq/faq.html#faq.setup.cli |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment