@echo off REM PROGRAM: Update_Cygwin.bat REM PURPOSE: Apply the latest Cygwin updates REM CREATOR: John Ruble (jrx@qad.com) REM CREATED: 2014-10-03 REM CHANGES: REM jrx 2014-10-03 Created REM jrx 2014-10-13 Handle sshd not installed. Handle errors. SETLOCAL SET myExitCode=0 REM ### This is the folder with either setup-x86.exe or setup-x86_64.exe REM ### Note some physical servers have this as something of than REM ### "Administrator", such as "79462-admin" SET installFolder=C:\Users\Administrator\Downloads IF NOT EXIST "%installFolder%" ( SET myExitCode=3 ECHO ERROR: Invalid root folder "%installFolder%" EVENTCREATE /T ERROR /L APPLICATION /SO Update_Cygwin /ID %myExitCode% /D "Invalid root folder: %installFolder%" GOTO :end ) CD /d %installFolder% IF NOT ERRORLEVEL 0 SET myExitCode=3 &GOTO :end REM ### First look for 32-bit version of Cygwin's setup REM ### If found skip over the check for the 64-bit version SET cyg_setup=setup-x86.exe IF EXIST %cyg_setup% GOTO stop_ssh REM ### Otherwise use the 64-bit version of setup REM ### Jump to the end if we found nothing SET cyg_setup=setup-x86_64.exe IF NOT EXIST %cyg_setup% SET myExitCode=2 &GOTO no_setup REM ### See if the SSHD service is installed and stop it :stop_ssh SC QUERY sshd >nul 2>&1 IF NOT ERRORLEVEL 1 ( NET STOP sshd IF ERRORLEVEL == 1 SET myExitCode=2 &GOTO :end ) REM ### Clear the error code (short method) CD>nul REM ### Run the setup. If it fails we still want to start SSH, REM ### if it is installed, so we will store an error code REM ### of 259 "No more data is available" and we stop changing REM ### our error code. ECHO Running %cyg_setup% %cyg_setup% --no-desktop --no-shortcuts --no-startmenu --quiet-mode -l %installFolder% -s http://mirrors.kernel.org/sourceware/cygwin/ >nul 2>&1 IF ERRORLEVEL == 1 SET myExitCode=259 &EVENTCREATE /T ERROR /L APPLICATION /SO Update_Cygwin /ID 259 /D "%cyg_setup% failed" &ECHO %cyg_setup% failed REM ### See if the SSHD service is installed and start it SC QUERY sshd >nul 2>&1 if NOT ERRORLEVEL 1 ( NET START sshd IF ERRORLEVEL == 1 GOTO :end ) REM ### Clear the error code and go to the end CD>nul GOTO end :no_setup ECHO ERROR: Neither setup-x86.exe nor setup-x86_64.exe exist here EVENTCREATE /T ERROR /L APPLICATION /SO Update_Cygwin /ID %myExitCode% /D "Neither setup-x86.exe nor setup-x86_64.exe exist here" GOTO end REM ### Exit with our code ############## :end EXIT /B %myExitCode% REM ### The following is never hit ENDLOCAL