@echo off rem InstallLatestCygwinSnapshot.bat rem A combined bat/perl script to automatically install the latest snapshot. rem Requires Cygwin perl and wget on your path. rem Run the perl script part, which is at the end. perl -x -- %0 if ERRORLEVEL 1 goto :error1 rem Replace cygwin1.dll cd c:\unix\bin del cygwin1.dll ren deleteme.dll cygwin1.dll echo Done. pause exit :error1 echo Error. pause exit 1 rem -------------------- PERL STARTS HERE ----------------- #!/bin/perl # My sweet LORD perl is cool! use File::Temp qw/ tempfile tempdir /; # Get the snapshots page print "Getting list of snapshots...\n"; $page = `wget -O- http://cygwin.com/snapshots/ 2>/dev/null`; if ($?) { die "Couldn't get list of snapshots"; } # Parse the URLs out of it. (@base) = ($page =~ m|(http.*cygwin-inst.*bz2)|gm); # Sort them by date, newest to oldest. @base = sort {$b cmp $a} @base; # Get the newest one. $URL = @base[0]; ($BASENAME) = (@base[0] =~ m!([^/]*bz2$)!); print "Latest snapshot is ", $BASENAME, "\n"; # Download the file print "Downloading ", $URL, "...\n"; system("wget -cq -nd --directory-prefix=/. $URL") == 0 or die "Couldn't download file"; # Create a temp dir for extractiong cygwin1.dll $tempdir = tempdir( CLEANUP => 1); # Extract as much as we can (i.e. hopefully everything except cygwin1.dll) # Extract *only* the cygwin1.dll, to a different name in /bin, and we'll move # it to its final resting place back in cmd.exe. print "Extracting...\n"; system("cd / && tar -xjf $BASENAME --exclude=usr/bin/cygwin1.dll && cp $BASENAME $tempdir/$BASENAME && cd $tempdir && tar -xjf $BASENAME usr/bin/cygwin1.dll && cp usr/bin/cygwin1.dll /bin/deleteme.dll") == 0 or die "Extraction failed";