Thursday, June 24, 2010

Cygwin Scripted Installation

Because I never quite know when I will need to use Cygwin and it isn't part of any "standard build" for my Windows servers, I wanted an easy way to quickly install it on a server. I wrote a batch file that will download the setup file and install the base system. Thanks goes out to http://theos.in/windows-server/windows-command-line-download-tool/ for the information on using bitsadmin for command-line downloading in Windows.

There are some prerequisites for this to work properly:
  1. Must have an Internet connection
  2. Must be an administrator on the computer
  3. Must have the Windows Support Tools installed (bitsadmin)
The batch file below will download the Cygwin setup file and install Cygwin with the base packages (assuming all of the prerequisites have been met). The command line switches in the script are set to not verify the setup.ini.sig nor does Cygwin setup any shortcuts. The local directory for the installation files is set to C:\temp, but could be changed.

If you have any problems with the script, please post in the Comments and I will try to help out.

@ECHO OFF
SET PATH=%PATH%;C:\Program Files\Support Tools

bitsadmin /create CygwinDownload
bitsadmin /addfile CygwinDownload http://cygwin.com/setup.exe c:\temp\setup.exe
bitsadmin /resume CygwinDownload
goto :checkstatus

:checkstatus
FOR /F "tokens=*" %%i in ('bitsadmin /GetFilesTransferred CygwinDownload') do SET status=%%i
if not "%status%"=="1" goto :checkagain else goto :downloadcomplete

:checkagain
FOR /F "tokens=*" %%i in ('bitsadmin /GetFilesTransferred CygwinDownload') do SET status=%%i
if not "%status%"=="1" goto :checkstatus else goto :downloadcomplete

:downloadcomplete
bitsadmin /complete CygwinDownload
echo "Download Complete"

:errorhandler
bitsadmin /reset

C:\temp\setup.exe -q -l c:\temp -n -X -s http://mirror.mcs.anl.gov/pub/cygwin -P base-cygwin vim

echo "Installation Complete"

No comments: