@echo off :: ConCygSys: Cygwin and ConEmu portable installer: https://github.com/zhubanRuban/cygwin-portable :: Copyright zhubanRuban: https://github.com/zhubanRuban :: Licensed under the Apache License 2.0: http://www.apache.org/licenses/LICENSE-2.0 :: Independent fork of cygwin-portable-installer: https://github.com/vegardit/cygwin-portable-installer set CONCYGSYS_VERSION=190915 ::======================= begin SCRIPT SETTINGS ======================= ::+++++++++++++ Cygwin settings :: Custom home folder: https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-mapping-nsswitch-home :: Applicable for new installations only. For existing ones home folder can be modified in /etc/nsswitch.conf :: Examples: :: /home/cygwinhome :: /cygdrive/c/Users/YOURUSERNAME/cygwinhome :: /%%H/cygwinhome (% sign should be escaped) :: Leave empty to use default one - /home/concygsys set CYGWIN_HOME= :: Specify default launcher for Cygwin: conemu mintty cmd :: If specified launcher is not available, defaults to next available one in the following order: conemu mintty cmd set LAUNCHER_CYGWIN= :: Comma-separated list of the packages to be installed automatically: https://cygwin.com/packages/package_list.html :: You will be able to install other packages later with apt-cyg if INSTALL_APT_CYG is set to yes below set CYGWIN_PACKAGES=bind-utils,inetutils,openssh,vim,whois :: You can choose the closest mirror: https://cygwin.com/mirrors.html set CYGWIN_MIRROR= :: Set proxy, if required, in the following format: proxyip:port :: Applicable to installation process only set PROXY_HOST= :: Override OS architecture, if required: "32" bit or "64" bit system. Leave empty for autodetect set CYGWIN_ARCH= ::+++++++++++++ Addons :: Install apt-cyg command line package manager for Cygwin: https://github.com/transcode-open/apt-cyg :: Why not using https://github.com/kou1okada/apt-cyg : https://github.com/kou1okada/apt-cyg#requirements https://github.com/kou1okada/apt-cyg/issues/24 set INSTALL_APT_CYG=yes :: Configure ssh-agent: https://github.com/zhubanRuban/cygwin-extras#ssh-agent-tweak set INSTALL_SSH_AGENT_TWEAK=yes :: Space-separated list of additional scripts URL to execute after Cygwin installation :: They will be downloaded with wget and passed to bash. Commands available by default to custom scripts: cygwin base + wget + apt-cyg :: The example can be found here: https://github.com/zhubanRuban/cygwin-extras/raw/master/ssh-pageant_install.sh set INSTALL_ADDONS= :: Alternatively you can create a folder called 'addons' near installer and place your sh scripts there :: They will be executed during installation and during next update ::+++++++++++++ ConEmu settings :: Install ConEmu quake-style terminal https://conemu.github.io/ set INSTALL_CONEMU=yes :: How Cygwin or WSL will be launched in ConEmu multitab terminal, available options: :: Mintty : will be launched via mintty :: Connector : will be launched via ConEmu connector https://conemu.github.io/en/CygwinMsysConnector.html :: Cmd : will be launched via standard Windown console set CONEMUTASK_DEFAULT= ::+++++++++++++ Settings for WSL :: Install WSLbridge allowing to access WSL via Mintty https://github.com/rprichard/wslbridge (WSLtty emulation https://github.com/mintty/wsltty) set INSTALL_WSLBRIDGE=no :: Specify default launcher for WSL: conemu mintty cmd :: If specified launcher is not available, defaults to next available one in the following order: conemu mintty cmd set LAUNCHER_WSLBRIDGE= ::======================= end SCRIPT SETTINGS ======================= echo. set CONCYGSYS_LINK=https://github.com/zhubanRuban/cygwin-portable set CONCYGSYS_INFO=ConCygSys v.%CONCYGSYS_VERSION% %CONCYGSYS_LINK% echo %CONCYGSYS_INFO% echo. set INSTALL_ROOT=%~dp0 set CYGWIN_DIR=cygwin set CYGWIN_ROOT=%~dp0%CYGWIN_DIR% set CONCYGSYS_SETTINGS=update.cmd set "PATH=%CYGWIN_ROOT%\bin;%CYGWIN_ROOT%\usr\local\bin;%PATH%" set BASH=bash --noprofile --norc -c ::========================================================== :retryupdate setlocal EnableDelayedExpansion if exist %CYGWIN_DIR% ( echo Existing Cygwin folder detected, switching to update mode... set UPDATEMODE=yes %SystemRoot%\System32\wbem\WMIC.exe process get ExecutablePath | findstr "%INSTALL_ROOT%" >NUL 2>&1 :: multiple :: in if loop cause"system cannot find disk" warning, using rem further rem why not using "%ERRORLEVEL%"=="0": https://social.technet.microsoft.com/Forums/en-US/e72cb532-3da0-4c7f-a61e-9ffbf8050b55/batch-errorlevel-always-reports-back-level-0?forum=ITCG if not ErrorLevel 1 ( echo. echo ^^!^^!^^! Active Cygwin processes detected ^^!^^!^^! echo ========================================== %SystemRoot%\System32\wbem\WMIC.exe process where "ExecutablePath like '%%%INSTALL_ROOT:\=\\%%%'" get ExecutablePath, ProcessId echo. echo They will be terminated during update, please make sure you saved everything before proceeding pause for /f "usebackq" %%p in (`%SystemRoot%\System32\wbem\WMIC.exe process where "ExecutablePath like '%%%INSTALL_ROOT:\=\\%%%'" get ProcessId`) do taskkill /f /pid %%p >NUL 2>&1 goto :retryupdate ) else ( if exist "%CONCYGSYS_SETTINGS%" ( call "%CONCYGSYS_SETTINGS%" cygwinsettings call "%CONCYGSYS_SETTINGS%" installoptions :: making sure settings from previous versions are transferred properly if not "!PROXY_PORT!" == "" (if not "!PROXY_HOST!" == "" (set PROXY_HOST=!PROXY_HOST!:!PROXY_PORT!)) ) echo. set /p UPDATECYGWINONLY= [1] then [Enter] : update Cygwin only [Enter] : update everything echo. echo ^^!^^!^^! Before you proceed with update... ^^!^^!^^! echo ========================================= echo. echo You may need to backup your cygwin home directory just in case echo. echo To customize update process: echo - close this window echo - modify :installoptions section of %CONCYGSYS_SETTINGS% file echo - re-run update echo. echo If you are good with existing setup, just hit [Enter] to start update echo ======================================================================= echo. pause ) ) else ( mkdir %CYGWIN_DIR% >NUL 2>&1 ) setlocal DisableDelayedExpansion ::========================================================== set DOWNLOADER=ConCygSys-downloader.vbs echo. if "%PROXY_HOST%" == "" (set DOWNLOADER_PROXY=.) else ( set DOWNLOADER_PROXY= req.SetProxy 2, "%PROXY_HOST%", "" set http_proxy=http://%PROXY_HOST% set https_proxy=https://%PROXY_HOST% set ftp_proxy=ftp://%PROXY_HOST% ) echo Creating script that can download files, not using PowerShell which may be blocked by group policies... ( echo url = Wscript.Arguments(0^) echo target = Wscript.Arguments(1^) echo WScript.Echo "Downloading '" ^& url ^& "' to '" ^& target ^& "'..." echo Set req = CreateObject("WinHttp.WinHttpRequest.5.1"^) echo%DOWNLOADER_PROXY% echo req.Open "GET", url, False echo req.Send echo If req.Status ^<^> 200 Then echo WScript.Echo "FAILED to download: HTTP Status " ^& req.Status echo WScript.Quit 1 echo End If echo Set buff = CreateObject("ADODB.Stream"^) echo buff.Open echo buff.Type = 1 echo buff.Write req.ResponseBody echo buff.Position = 0 echo buff.SaveToFile target echo buff.Close echo. ) > %DOWNLOADER% || goto :fail ::========================================================== echo. if "%CYGWIN_ARCH%" == "" ( echo CYGWIN_ARCH setting is empty, autodetecting... if "%PROCESSOR_ARCHITECTURE%" == "x86" ( if defined PROCESSOR_ARCHITEW6432 (set CYGWIN_ARCH=64) else (set CYGWIN_ARCH=32) ) else (set CYGWIN_ARCH=64) ) echo Choosing correct version of Cygwin installer... if "%CYGWIN_ARCH%" == "64" (set CYGWIN_SETUP=setup-x86_64.exe) else (set CYGWIN_SETUP=setup-x86.exe) echo Chosen installer: %CYGWIN_SETUP% set CYGWIN_SETUP_PATH=%CYGWIN_DIR%\%CYGWIN_SETUP% cscript //Nologo %DOWNLOADER% https://cygwin.org/%CYGWIN_SETUP% %CYGWIN_SETUP_PATH% || goto :fail :: https://cygwin.com/faq/faq.html#faq.setup.cli if "%CYGWIN_MIRROR%" == "" (set CYGWIN_MIRROR=http://mirror.checkdomain.de/cygwin/) if "%PROXY_HOST%" == "" (set CYGWIN_PROXY=) else (set CYGWIN_PROXY=--proxy "%PROXY_HOST%") :: adding required packages for special software if "%INSTALL_CONEMU%" == "yes" (set CYGWIN_PACKAGES=bsdtar,wget,%CYGWIN_PACKAGES%) if "%INSTALL_WSLBRIDGE%" == "yes" (set CYGWIN_PACKAGES=bsdtar,wget,%CYGWIN_PACKAGES%) if "%INSTALL_APT_CYG%" == "yes" (set CYGWIN_PACKAGES=wget,%CYGWIN_PACKAGES%) if "%INSTALL_SSH_AGENT_TWEAK%" == "yes" (set CYGWIN_PACKAGES=openssh,wget,%CYGWIN_PACKAGES%) if not "%INSTALL_ADDONS%" == "" (set CYGWIN_PACKAGES=wget,%CYGWIN_PACKAGES%& set INSTALL_APT_CYG=yes) :: https://www.cygwin.com/faq/faq.html#faq.setup.cli echo. echo Running Cygwin setup... %CYGWIN_SETUP_PATH% ^ --allow-unsupported-windows ^ --delete-orphans ^ --local-package-dir "%TEMP%\cygwin-local-package-dir" ^ --no-admin ^ --no-desktop ^ --no-replaceonreboot ^ --no-shortcuts ^ --no-startmenu ^ --packages dos2unix,%CYGWIN_PACKAGES% ^ --quiet-mode ^ --root %CYGWIN_DIR% ^ --site %CYGWIN_MIRROR% %CYGWIN_PROXY% ^ --upgrade-also || goto :fail del /f /q %CYGWIN_SETUP_PATH% >NUL 2>&1 & rmdir /s /q "%TEMP%\cygwin-local-package-dir" >NUL 2>&1 :: warning for standard Cygwin launcher echo %CONCYGSYS_INFO% > %CYGWIN_DIR%\DO-NOT-LAUNCH-CYGWIN-FROM-HERE :: permanent noacl to prevent issues set FSTAB=%CYGWIN_ROOT:\=/% set FSTAB=%FSTAB: =\040% ( echo # %CONCYGSYS_INFO% echo %FSTAB%/bin /usr/bin none noacl,posix=0,user 0 0 echo %FSTAB%/lib /usr/lib none noacl,posix=0,user 0 0 echo %FSTAB% / none override,noacl 0 0 echo none /tmp usertemp noacl,posix=0,user 0 0 echo none /cygdrive cygdrive noacl,user 0 0 echo # %CONCYGSYS_INFO% ) > %CYGWIN_DIR%\etc\fstab & dos2unix -q %CYGWIN_DIR%\etc\fstab :: adjusting home folder if not set if "%CYGWIN_HOME%" == "" (set CYGWIN_HOME=/home/concygsys) sed -i 's/^^#.*db_home:.*/db_home: %CYGWIN_HOME:/=\/%/' /etc/nsswitch.conf :: inputrc fix for ctrl+left and ctrl+right to work as expected: https://github.com/zhubanRuban/cygwin-extras#custom-inputrc copy /y %CYGWIN_DIR%\etc\defaults\etc\skel\.inputrc %CYGWIN_DIR%\etc\skel\.inputrc >NUL 2>&1 ( echo. echo # %CONCYGSYS_INFO% echo "\e[1;5C": forward-word # ctrl + right echo "\e[1;5D": backward-word # ctrl + left echo # %CONCYGSYS_INFO% ) >> %CYGWIN_DIR%\etc\skel\.inputrc & dos2unix -q %CYGWIN_DIR%\etc\skel\.inputrc if not "%UPDATECYGWINONLY%" == "" goto :aftercygwinupdate ::========================================================== if "%INSTALL_APT_CYG%" == "yes" ( echo. & echo Installing apt-cyg... wget -nv --show-progress -O /usr/local/bin/apt-cyg https://github.com/transcode-open/apt-cyg/raw/master/apt-cyg chmod +x /usr/local/bin/apt-cyg ) if "%INSTALL_SSH_AGENT_TWEAK%" == "yes" ( echo. & echo Configuring ssh-agent... wget -nv --show-progress -O /etc/profile.d/ssh-agent-tweak.sh https://github.com/zhubanRuban/cygwin-extras/raw/master/ssh-agent-tweak grep -q AddKeysToAgent %CYGWIN_DIR%\etc\ssh_config >NUL 2>&1 || echo AddKeysToAgent yes >> %CYGWIN_DIR%\etc\ssh_config & dos2unix -q %CYGWIN_DIR%\etc\ssh_config :: removing previous possible ssh-agent implementations rm -f /opt/ssh-agent-tweak & sed -i '/\/opt\/ssh-agent-tweak/d' ~/.bashrc >NUL 2>&1 ) set ADDONS_DIR=addons if not "%INSTALL_ADDONS%" == "" (echo. & echo Downloading addons... for %%a in (%INSTALL_ADDONS%) do (wget -nv --show-progress -NP %ADDONS_DIR% %%a) ) if exist "%ADDONS_DIR%" ( for %%a in (%ADDONS_DIR%\*) do (echo. & echo Installing addon: %%a ... & bash --noprofile --norc %%a) ) ::========================================================== :: Mintty options for ConEmu task: https://cdn.rawgit.com/mintty/mintty/master/docs/mintty.1.html#CONFIGURATION :: for better experience in running Mintty via ConEmu set MINTTY_OPTIONS= ^ -o FontHeight=10 ^ -o BoldAsFont=yes ^ -o AllowBlinking=yes ^ -o CopyOnSelect=yes ^ -o RightClickAction=paste ^ -o ScrollbackLines=5000 ^ -o Transparency=off ^ -o ConfirmExit=no set CONEMU_DIR=conemu set CONEMU_ARCHIVE=%CONEMU_DIR%.7z set CONEMU_CONFIG=%CONEMU_DIR%\ConEmu.xml if "%INSTALL_CONEMU%" == "yes" (echo. if not exist %CONEMU_DIR% ( echo Installing ConEmu... %BASH% "wget -nv --show-progress -O %CONEMU_ARCHIVE% https://github.com$(wget -qO- https://github.com/Maximus5/ConEmu/releases/latest|grep /.*/releases/download/.*/.*7z -o)" || goto :fail mkdir %CONEMU_DIR% >NUL 2>&1 echo Extracting... & bsdtar -xf %CONEMU_ARCHIVE% -C %CONEMU_DIR% || goto :fail echo %CONCYGSYS_INFO% > %CONEMU_DIR%\DO-NOT-LAUNCH-CONEMU-FROM-HERE rm -f %CONEMU_ARCHIVE% ) rem Commented until ConEmu allows importing tasks via command line without replacing the whole config rem if not exist "%CONEMU_CONFIG%" ( echo Replacing ConEmu config... ( echo ^ echo ^