Friday, March 08, 2013

Gotcha of the Day: Creating a semi-automated cygwin install script

I love cygwin. Wouldn't last 24 hours without it. And the installer is very reliable and easy to use. The only headache I usually run into is when I setup a new laptop. I find that I'm constantly re-running cygwin to make sure I've got all the packages I need installed.

This time I had plan, though. I noted which packages I was going to need and using setup.exe carefully went through and selected each one. It took some time, but I figured I'd only have to do this once. Of course, once the download process began I lost my Internet connection and was going to have to repeat the process, including the annoying package selection step.

I figured there had to be a better way. And thanks to ServerFault, I now know there is. The basic strategy is to create a script that invokes setup.exe using command line arguments.

Below is the script I arrived at. At the top is a list of packages I want installed. It's safe to re-run this as often as I want, so adding new packages is easy: just add it to the list and re-run.

#!/bin/bash

PACKAGES='
openssh
zip
unzip
subversion
git
screen
gcc
make
automake
autoconf
vim
vim-common
rxvt
ncftp
cvs
rcs
aspell
aspell-en
md5deep
ImageMagick
'

C=/cygdrive/c
export PATH=$PATH:$C/cygwin/bin
mirror=http://cygwin.mirrors.pair.com
pkgs=`echo $PACKAGES | tr ' ' ','`

./setup.exe -A -q -n -N -d -R 'C:\cygwin' \
          -s $mirror \
          -l 'c:\temp\packages' -P $pkgs

The process for setting up a new laptop then becomes:

  1. Install cygwin using the default settings
  2. As administrator run the above script. I did this by opening up a cmd window using Administrator privliges and then running:
     c:\cygwin\bin\bash cygwinstall.sh
    

It's not a fully automated process, but it's close enough.

2 comments:

  1. That is really nice, thanks.

    ReplyDelete
  2. You're very welcome, Grant.

    Hope this is a time saver for all.

    ReplyDelete