Centre for Mathematical Sciences, Lund University
    Print this page!
Help?!

Home

Scientific Calculations
Matlab
Scipy/Pylab
R
S-Plus

Word Processing
LaTeX
presentations
Convert file format A to B

Graphics
Gimp
ImageMagick

Programming
Preprocessors
Java
Lisp
Perl
Python
SQL

Computer Systems
Floppy disks
Printers
Unix
MH:230 & MH231
SuSE Linux + KDE
KDE Windows Manager
MS Windows

Webmastering
JSP
PHP
Password Access
Web Design

Language Help
English

MC specific
MCphoto



Printer-friendly
Print this page



Powered by Google

Unattended Cygwin Installation

Henrik Bengtsson, 2004-06-02

Introduction

Below are instructions how to install Cygwin unattended and quietly off-line (no Internet connection is required) by

 cygwinSetup [CYGWIN_ROOT] [LOCAL_REPOSITORY]

Example

Having a local repository in the current directory that contains the cygwin_mirror\ directory with the modified setup.ini file (for instructions see below) typing

 cygwinSetup

at the command prompt will silently install Cygwin in %SystemDrive%\cygwin\, e.g. C:\cygwin\.

Download

The unattended Cygwin setup script is cygwinSetup.bat. Its source is shown in Appendix A. The script was adopted from [1,2].

Setup local repository

You have to follow the "Requirements" instructions in the script (see Appendix A) in order to download and setup a local repository (named cygwin_mirror\) containing all packages you want to install. Also, make sure to modify the setup.ini according to the instructions. A minimal example that allows Cygwin setup to complete is cygwin_mirror.zip (it will not create anything executable though).

Firewalls

At the end of the unattended installation Cygwin setup calls uname and bash (and possibly some other programs). If you have a firewall, such as ZoneAlarm, that protects against outgoing Internet calls, these programs will trigger the firewall (although the will not access the internet). Thus, you might have to accept these programs manually. To avoid this, turn of your firewall while installing Cygwin.

Troubleshooting

If you already have a Cygwin installation, this will force Cygwin setup to install in the directory where Cygwin is already installed. This information is stored in the Windows Registry. For more information see script. To uninstall Cygwin completely do

 cygwinSetup "" --uninstall

Appendix A

Below is the script fooling Cygwin setup to install quietly. It is supposed to be self contained with help and everything. Note that most of the code is to assert that there are no errors etc. This will help you troubleshoot, but also to understand what is required.

@echo off
REM ###########################################################################
REM # Unattended Cygwin installation
REM #
REM # Usage: cygwinSetup [CYGWIN_ROOT] [LOCAL_REPOSITORY]
REM #
REM # Options:
REM # CYGWIN_ROOT:
REM #  Path where Cygwin will be installed. If "" or not specified,
REM #  %SystemDrive%\cygwin is used.
REM #
REM # LOCAL_REPOSITORY:
REM # Path to local repository. If "" or not specified, the current directory 
REM # is used. Paths containing parentesis, i.e. '(' or ')', do not work.
REM # If --uninstall, Cygwin will be uninstalled from the Windows 
REM # Registry and the CYGWIN_ROOT directory will be removed completely!
REM #
REM # Note: Make sure the above arguments do not contain whitespaces, otherwise
REM # Cygwin setup will be confused and behave strangely (looping etc).
REM #
REM # Requirements:
REM # You have to have a "%LOCAL_REPOSITORY%\cygwin_mirror\" directory 
REM # containing a cached mirror of a repository plus setup.exe, that is, 
REM # it should contain
REM #
REM #   %LOCAL_REPOSITORY%\cygwin_mirror\
REM #    +- setup.exe
REM #    +- setup.ini 
REM #    +- release 
REM #    +- release 
REM #        +- _update-info-dir\ 
REM #        +- ap2s\                  # example of packages
REM #        +- ...\                   #        - " - 
REM #        +- zsh\                   #        - " - 
REM #
REM # As described in [2,3], Cygwin 'setup -q' will only install packages in
REM # category "Base". The categories are defined in the above 'setup.ini' file.
REM # To fake setup to install other package, replace the category for such
REM # packages to become "Base" (no quotes). This will fool setup to install
REM # those too. If you have access to a 'sed' command [1] just do
REM #
REM #   copy setup.ini setup.ini.base
REM #   sed "s/category: .*/category: Base/g;" setup.ini.base > setup.ini
REM # 
REM # This should be all.
REM # 
REM # FYI, this script relies solely on standard MS-DOS commands.
REM #
REM # Troubleshooting:
REM # If you already have a Cygwin installation, this will force Cygwin setup
REM # to install in the directory where Cygwin is already installed. This 
REM # information is stored in the Windows Registry. Either uninstall Cygwin
REM # by creating an UninstallCygwin.reg file containing:
REM # 
REM #   REGEDIT4
REM #   [-HKEY_LOCAL_MACHINE\Software\Cygnus Solutions]
REM #   [-HKEY_CURRENT_USER\Software\Cygnus Solutions]
REM #   [-HKEY_USERS\.DEFAULT\Software\Cygnus Solutions]
REM #
REM # and double click on it.
REM #
REM # See also:
REM # For more details, see [1].
REM #
REM # Author: 
REM # Henrik Bengtsson adopted from Seth de l'Isle instructions [2,3].
REM #
REM # Acknowledgements: 
REM # Seth de l'Isle and Brian White.
REM #
REM # References:
REM # [1] Henrik Bengtsson, Unattended Cygwin Installation, June 2, 2004.
REM #     http://www.maths.lth.se/help/windows/cygwin/
REM # [2] Seth de l'Isle, cygwin without autoit, February 11, 2004.
REM #     http://www.mail-archive.com/unattended-info@lists.sourceforge.net/
REM #     msg01051.html  
REM # [3] Seth de l'Isle, cygwin unattended, February 12, 2004.
REM #     http://www.mail-archive.com/unattended-info@lists.sourceforge.net/
REM #     msg01060.html  
REM # [4] Sed for Windows, GnuWin32, June 2004.
REM #     http://gnuwin32.sourceforge.net/packages/sed.htm
REM ###########################################################################

echo Installing Cygwin unattended...
REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REM Parse arguments
REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REM Path where Cygwin will be installed
set CYGWIN_ROOT=%1%
IF "%CYGWIN_ROOT%" == """" (
  set CYGWIN_ROOT=
)
IF "%CYGWIN_ROOT%" == "" (
  REM If not defined, assume %SystemDrive%\cygwin
  set CYGWIN_ROOT=%SystemDrive%\cygwin
)

REM Path where local Cygwin repository is located
set LOCAL_REPOSITORY=%2%
IF "%LOCAL_REPOSITORY%" == """" (
  set LOCAL_REPOSITORY=
)

IF "%LOCAL_REPOSITORY%" == "" (
  REM If not defined, assume current directory
  REM NOTE: Twice on purpose! if %cd% contains ')' it won't work otherwise. 
  set LOCAL_REPOSITORY=%cd%
  set LOCAL_REPOSITORY=%cd%
)

REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REM Check for uninstallation of Cygwin
REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IF "%LOCAL_REPOSITORY%" == "--uninstall" (
  IF NOT EXIST "%CYGWIN_ROOT%" (
    echo ERROR: Can not uninstall Cygwin since the CYGWIN_ROOT argument is not
    echo pointing to an existing directory: '%CYGWIN_ROOT%'.
    exit /B 1
  )

  IF NOT EXIST "%CYGWIN_ROOT%\bin\cygwin1.dll" (
    echo ERROR: Can not uninstall Cygwin since the CYGWIN_ROOT argument is most
    echo likely pointing to a non Cygwin directory: '%CYGWIN_ROOT%'.
    exit /B 1
  )

  reg QUERY "HKEY_LOCAL_MACHINE\Software\Cygnus Solutions" > "%TEMP%/null"
  IF ERRORLEVEL 1 ( 
    echo ERROR: Can not uninstall Cygwin since it is not installed.
    exit /B 1
  )

  echo WARNING: Are you sure you want to uninstall Cygwin? This will
  echo remove all Cygwin entries in the Windows Registry and delete the
  echo '%CYGWIN_ROOT%' "(==CYGWIN_ROOT)" directory completely.
  set /P answer="There is no return back. Continue? [y/N]: "
  IF "%answer%" == "y" (
    reg delete "HKEY_LOCAL_MACHINE\Software\Cygnus Solutions"  /f
    reg delete "HKEY_CURRENT_USER\Software\Cygnus Solutions"   /f
    reg delete "HKEY_USERS\.DEFAULT\Software\Cygnus Solutions" /f
    echo Comment: Missing registry keys above are ok.

    rd /Q /S "%CYGWIN_ROOT%"
    echo Removed the '%CYGWIN_ROOT%' directory.
    echo.

    echo Cygwin uninstalled!

    exit /B 0
  ) ELSE (
    echo Cygwin uninstall cancelled.
    exit /B 1
  )
)

REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REM Debug information
REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo CYGWIN_ROOT='%CYGWIN_ROOT%'
echo LOCAL_REPOSITORY='%LOCAL_REPOSITORY%'

REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REM Assert that there exists a valid %LOCAL_REPOSITORY% directory.
REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IF NOT EXIST "%LOCAL_REPOSITORY%" (
  echo ERROR: Local repository does not exists: %LOCAL_REPOSITORY%
  exit /B 1
)

IF NOT EXIST "%LOCAL_REPOSITORY%\cygwin_mirror" (
  echo ERROR: Invalid local repository. Missing directory: %LOCAL_REPOSITORY%\cygwin_mirror\
  exit /B 1
)

IF NOT EXIST "%LOCAL_REPOSITORY%\cygwin_mirror\release" (
  echo ERROR: Invalid local repository. Missing directory: %LOCAL_REPOSITORY%\cygwin_mirror\release\
  exit /B 1
)

IF NOT EXIST "%LOCAL_REPOSITORY%\cygwin_mirror\setup.ini" (
  echo ERROR: Invalid local repository. Missing file: %LOCAL_REPOSITORY%\cygwin_mirror\setup.ini
  exit /B 1
)

REM Find Cygwin's setup.exe
set CYGWIN_SETUP=%LOCAL_REPOSITORY%\cygwin_mirror\setup.exe
IF NOT EXIST "%LOCAL_REPOSITORY%\cygwin_mirror\setup.exe" (
  set CYGWIN_SETUP=%LOCAL_REPOSITORY%\setup.exe
  IF NOT EXIST "%LOCAL_REPOSITORY%\setup.exe" (
    echo ERROR: Could not find Cygwin's setup.exe in the cygwin_mirror\ directory of the local repository: %LOCAL_REPOSITORY%\cygwin_mirror\
    exit /B 1
  )
)

echo CYGWIN_SETUP=%CYGWIN_SETUP%

REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REM Check if Cygwin is already installed
REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
reg QUERY "HKEY_LOCAL_MACHINE\Software\Cygnus Solutions" > "%TEMP%/null"
IF ERRORLEVEL 1 (
  REM Dummy line
) ELSE (
  REM Note that the quotation marks are required below, otherwise 'if' is parsed.
  echo "WARNING Cygwin seems to already be installed. When the 'native' values"
  echo "below do not start with '%CYGWIN_ROOT%' (==CYGWIN_ROOT), the installation"
  echo "will fail. To uninstall Cygwin: cygwinSetup UNINSTALL CYGWIN"
  reg QUERY "HKEY_LOCAL_MACHINE\Software\Cygnus Solutions\Cygwin\mounts v2" /s
  echo.
  pause
)

REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REM Create a fake installation skeleton for Cygwin setup
REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo Cygwin will be installed in '%CYGWIN_ROOT%'

IF NOT EXIST "%CYGWIN_ROOT%" (
  mkdir "%CYGWIN_ROOT%"
)

IF NOT EXIST "%CYGWIN_ROOT%\etc\setup" (
  mkdir "%CYGWIN_ROOT%\etc\setup"
) ELSE (
  del /Q "%CYGWIN_ROOT%\etc\setup\last-*"
)

REM Note that last-* must *not* containing whitespace, e.g. " " etc. 
REM This is why there below is no space in front of ">".
echo Install> "%CYGWIN_ROOT%\etc\setup\last-action"
echo %LOCAL_REPOSITORY%> "%CYGWIN_ROOT%\etc\setup\last-cache"
echo cygwin_mirror> "%CYGWIN_ROOT%\etc\setup\last-mirror"


REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REM Finally, run Cygwin setup quietly
REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo .
echo Starting Cygwin unattended installation. The install will first check the
echo MDI for *all* packages (not only those that are marked "Base"). During
echo this phase, if you move the Cygwin Setup Window it seems to freeze, but
echo do not worry, it will indeed continue and later during the installation
echo phase it will not freeze anymore. At the end post installations are done.
echo.

echo Running %CYGWIN_SETUP% -q -R "%CYGWIN_ROOT%"
"%CYGWIN_SETUP%" -q -R "%CYGWIN_ROOT%"

REM Unfortunately, setup does not return with an exit flag, making it 
REM impossible to test if the user clicked Cancel or not.

REM ###########################################################################
REM # HISTORY:
REM # 2005-03-24
REM # o Now the script searches for Cygwin's setup.exe and give an informative
REM #   error if not found.
REM # o If a Cygwin is already installed, the script will give a warning and
REM #   wait for the user to press any, giving the option to quit.
REM # 2005-03-03
REM # o FYI: Confirmed to work with latest version of Cygwin setup.exe.
REM # o BUG FIX: Running the script would give an (parse) error saying
REM #   "directory was unexpected at this time.". Missing quotes in echo.
REM # 2004-06-03
REM # o It may be useful to add /bin/ and /usr/X11R6/bin/ to the Windows 
REM #   system PATH. TODO: Find out how to add the PATH (reg ?!?)
REM # 2004-06-02
REM # o Added check for already existing Cygwin and uninstall options.
REM # o Created from Seth de l'Isle instructions [2,3]. Thanks!
REM ###########################################################################

References

[1] Seth de l'Isle, cygwin without autoit, February 11, 2004.
http://www.mail-archive.com/unattended-info@lists.sourceforge.net/msg01051.html
[2] Seth de l'Isle, cygwin unattended, February 12, 2004.
http://www.mail-archive.com/unattended-info@lists.sourceforge.net/msg01060.html
[3] http://tech.erdelynet.com/cygwin-uninstall.html