Skip to content

Instantly share code, notes, and snippets.

@urbans0ft
Created November 24, 2024 22:41
Show Gist options
  • Select an option

  • Save urbans0ft/15fbc8f7aca6b0362aa8ddc990eb1dac to your computer and use it in GitHub Desktop.

Select an option

Save urbans0ft/15fbc8f7aca6b0362aa8ddc990eb1dac to your computer and use it in GitHub Desktop.
Always install latest cygwin version batch script.
@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