Last active
July 20, 2021 13:55
-
-
Save kou1okada/7802343 to your computer and use it in GitHub Desktop.
Cygwin automatic installer
This file contains 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 | |
REM Cygwin automatic installer | |
REM Copyright (c) 2013-2015 Koichi OKADA. All rights reserved. | |
REM This script is distributed under the MIT license. | |
REM http://www.opensource.org/licenses/mit-license.php | |
SETLOCAL | |
CD %~dp0 | |
SET CYGWIN_MIRROR=http://ftp.jaist.ac.jp/pub/cygwin/ | |
SET ROOT= | |
SET NO_MINTTYHERE= | |
SET PATH_BAK=%PATH% | |
SET PACKAGES=wget,ca-certificates,gnupg,libiconv,git,chere,patch | |
SET PACKAGES32= | |
SET PACKAGES64= | |
:TARGET_SETUP | |
IF NOT "%PROCESSOR_ARCHITECTURE%" == "AMD64" GOTO TARGET_SETUP_X86 | |
SET TARGET=x86_64 | |
GOTO :TARGET_SETUP_END | |
:TARGET_SETUP_X86 | |
IF NOT "%PROCESSOR_ARCHITECTURE%" == "x86" GOTO TARGET_SETUP_FAILED | |
SET TARGET=x86 | |
GOTO :TARGET_SETUP_END | |
:TARGET_SETUP_FAILED | |
ECHO Error: Unknoun PROCESSOR_ARCHITECTURE: %PROCESSOR_ARCHITECTURE% | |
GOTO :END | |
:TARGET_SETUP_END | |
:OPT_PARSE | |
IF "%1" == "" GOTO :MAIN | |
IF "%1" == "-h" GOTO :OPT_HELP | |
IF "%1" == "--help" GOTO :OPT_HELP | |
IF "%1" == "--proxy" GOTO :OPT_PROXY | |
IF "%1" == "--root" GOTO :OPT_ROOT | |
IF "%1" == "--target" GOTO :OPT_TARGET | |
IF "%1" == "--mirror" GOTO :OPT_MIRROR | |
IF "%1" == "--install" GOTO :OPT_INSTALL | |
IF "%1" == "--install32" GOTO :OPT_INSTALL32 | |
IF "%1" == "--install64" GOTO :OPT_INSTALL64 | |
IF "%1" == "--no-minttyhere" GOTO :OPT_NO_MINTTYHERE | |
ECHO Error: Unknown option: %1 | |
GOTO :END | |
GOTO :OPT_PARSE | |
:OPT_HELP | |
SHIFT | |
ECHO Usage: cygwin_autoinstall.bat [options] | |
ECHO Options: | |
ECHO -h,--help help | |
ECHO --proxy PROXY set PROXY server | |
ECHO --root ROOT set root installation directory | |
ECHO --target TARGET set target archtecture (x86 or x86_64) | |
ECHO --mirror MIRROR set mirror (default: %CYGWIN_MIRROR%) | |
ECHO --install pkgs,... add extra packages for 32/64bit environment | |
ECHO --install32 pkgs,... add extra packages for 32bit environment | |
ECHO --install64 pkgs,... add extra packages for 64bit environment | |
ECHO --no-minttyhere do not install minttyhere | |
GOTO :END | |
:OPT_PROXY | |
SHIFT | |
SET http_proxy=%1 | |
SET https_proxy=%1 | |
SET ftp_proxy=%1 | |
SHIFT | |
GOTO :OPT_PARSE | |
:OPT_ROOT | |
SHIFT | |
SET ROOT=%~1 | |
SHIFT | |
GOTO :OPT_PARSE | |
:OPT_TARGET | |
SHIFT | |
SET TARGET=%1 | |
SHIFT | |
GOTO :OPT_PARSE | |
:OPT_MIRROR | |
SHIFT | |
SET CYGWIN_MIRROR=%1 | |
SHIFT | |
GOTO :OPT_PARSE | |
:OPT_INSTALL | |
SHIFT | |
SET PACKAGES=%PACKAGES%,%~1 | |
SHIFT | |
GOTO :OPT_PARSE | |
:OPT_INSTALL32 | |
SHIFT | |
SET PACKAGES32=%PACKAGES32%,%1 | |
SHIFT | |
GOTO :OPT_PARSE | |
:OPT_INSTALL64 | |
SHIFT | |
SET PACKAGES64=%PACKAGES64%,%1 | |
SHIFT | |
GOTO :OPT_PARSE | |
:OPT_NO_MINTTYHERE | |
SHIFT | |
SET NO_MINTTYHERE=YES | |
GOTO :OPT_PARSE | |
:MAIN | |
:MAIN_PREPARE | |
IF "%TARGET%" == "x86" ( | |
IF "%ROOT%" == "" SET ROOT=C:\cygwin | |
SET MINTTYHERE_INF=Cygwin32MinttyHere.inf | |
SET PACKAGES=%PACKAGES%%PACKAGES32% | |
GOTO :MAIN_PREPARE_END | |
) | |
IF "%TARGET%" == "x86_64" ( | |
IF "%ROOT%" == "" SET ROOT=C:\cygwin64 | |
SET MINTTYHERE_INF=Cygwin64MinttyHere.inf | |
SET PACKAGES=%PACKAGES%%PACKAGES64% | |
GOTO :MAIN_PREPARE_END | |
) | |
ECHO Error: Unknown target: %TARGET% | |
GOTO :END | |
:MAIN_PREPARE_END | |
IF "%ROOT%" == "" ( | |
ECHO Error: Failed to set root installation directory. | |
GOTO :END | |
) | |
:MAIN_SET_ROOT_END | |
:INSTALL | |
PATH=%ROOT%\bin;%PATH_BAK% | |
MKDIR "%ROOT%\etc\setup" | |
icacls "%ROOT%" /grant "%USERDOMAIN%\%USERNAME%:F" "*S-1-3-1:RX" "Everyone:RX" "CREATOR OWNER:(OI)(CI)(IO)F" "CREATOR GROUP:(OI)(CI)(IO)RX" "Everyone:(OI)(CI)(IO)RX" /remove "NT AUTHORITY\Authenticated Users" "NT AUTHORITY\SYSTEM" "BUILTIN\Administrators" "BUILTIN\Users" "NULL SID" /inheritance:r | |
ECHO net-method> "%ROOT%\etc\setup\setup.rc" | |
ECHO IE>> "%ROOT%\etc\setup\setup.rc" | |
powershell -Command "Import-Module BitsTransfer; Start-BitsTransfer https://cygwin.com/setup-%TARGET%.exe" | |
START /wait setup-%TARGET%.exe -q -B -s %CYGWIN_MIRROR% -P "%PACKAGES%" -R "%ROOT%" | |
bash --login -c exit | |
bash -c "git clone https://github.com/kou1okada/apt-cyg.git /usr/local/apt-cyg" | |
bash -c "ln -sf /usr/local/apt-cyg/apt-cyg /usr/local/bin/" | |
bash -c "/usr/local/bin/apt-cyg upgrade-self" | |
bash -c "/usr/local/bin/apt-cyg --use-setuprc update" | |
wget -N https://gist.githubusercontent.com/kou1okada/45ac4f49a45af076faa00ecc3c96d40c/raw/xhere.patch | |
patch -b -p0 -d/ < xhere.patch | |
:INSTALL_MINTTYHERE | |
IF NOT "%NO_MINTTYHERE%" == "" GOTO :INSTALL_MINTTYHERE_END | |
wget -N https://gist.github.com/kou1okada/7801720/raw/%MINTTYHERE_INF% | |
cygstart.exe -a install %MINTTYHERE_INF% | |
:INSTALL_MINTTYHERE_END | |
GOTO :END | |
:END | |
PATH=%PATH_BAK% | |
GOTO :EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment