@ECHO OFF
SETLOCAL
IF "%[_ELEVATED]" == "1" GOTO :RUN
ECHO Restarting elevated.
START "" /MIN /ELEVATED "%~0" %*
EXIT /B
:RUN
"ssh-pageant.sh" -k
gpgconf --kill gpg-agent dirmngr scdaemon
UNSET STOP_SVC
UNSET START_SVC
DO svc IN /P cygrunsrv --list
IFF "%[svc]" == "cygserver" THEN
SET "START_SVC=%[svc] %[START_SVC]"
SET "STOP_SVC=%[svc]"
ITERATE
ENDIFF
SET "START_SVC=%[START_SVC] %[svc]"
net stop "%[svc]"
ENDDO
IF NOT "%[STOP_SVC]" == "" net stop "%[STOP_SVC]"
:SAFETY
REM Crude test for other Cygwin processes running.
IFF "%~1" != "--force" THEN
IF %@EXECSTR[ ( ( ps -al | grep -vE "\<%@INSTR[5,,%@EXECSTR[tty]]\>" ) | TEE CON: ) | wc -l ] GT 1 (
ECHO There's likely other processes running from Cygwin environment.
ECHO Please stop them or use --force to suppress this test.
GOTO :RESTART
)
ELSE
SHIFT
ENDIFF
REM Cygwin upgrade helper script.
REM Usage:
REM
REM install-cygwin.btm [--force] [-ns]
REM
REM If you intend to use it for new installs, you will need minimal bootstrap
REM including POSIX shell interpreter and wget utility.
REM
REM You will have to edit the script to provide mirror URL of your choice
REM or set CYGWIN_MIRROR environment variable to the mirror URL.
REM
REM The script assumes existing installation of the same architecture as
REM the host operating system.
REM If you want to install 32-bit Cygwin on 64-bit host, override
REM $ARCH with value other than "x86_64".
REM F.e.
REM
REM SET ARCH=x86 && install-cygwin.btm
IF "%[CYGWIN_MIRROR]" != "" SET "MIRROR=%[CYGWIN_MIRROR]"
IF "%[MIRROR]" != "" GOTO :ARCH
REM Mirror URL - don't include trailing slash!
SET "MIRROR=https://mirrors.kernel.org/sourceware/cygwin"
:ARCH
REM System architecture.
IF "%[ARCH]" != "" GOTO :LOCALE
SET "ARCH=%@EXECSTR[ uname -m ]"
:LOCALE
REM Localization is fine... as long as you don't show it to other people.
SET LANG=C.UTF-8
IF "%[ARCH]" != "x86_64" SET ARCH=x86
wget -N "https://cygwin.com/setup-%[ARCH].exe"
REM Skip running setup on "NoSetup" switch
IF "%~1" == "-ns" GOTO :RESTART
".\setup-%[ARCH].exe" -O -s "%@RTRIM[/,%[MIRROR]]/" %[KEYS] %$
:RESTART
DO svc IN /Q %[START_SVC]
net start "%[svc]"
ENDDO
"ssh-pageant.sh"
ENDLOCAL