Facilitate a build from the trunk

Facilitate a build from the trunk

Postby Gerby » 02.10.2009, 22:18

Dear Beta junkies!

Since I'm a quite curious type of human being and sometimes cannot wait, until a new official release of WSUS Offline Update is out, I use the development releases from the trunk, downloaded as zip. However, these archives need a few preparational steps in order to use the contained files for downloading and updating:
  1. Unpack the trunk archive (source files).
  2. Create an empty directory for the build.
  3. Run the batch PrepareReleaseTree.cmd, which is contained in the trunk archive, with the empty directory as parameter.
  4. Erase the source files (clean up).
Quite some effort, at least if you do that frequently. So why not automate those steps? And that's what the following batch file BuildLatestTrunk.cmd does.

Code: Select all
@echo off

rem ------------------------------------------------------------
rem --- BuildLatestTrunk.cmd 1.2.0 (2018-08-14)              ---
rem ---                                                      ---
rem --- Facilitate a build from a WSUS Offline Update        ---
rem --- trunk. The latest trunk revision (trunk-*.zip)       ---
rem --- from the current directory is used.                  ---
rem ---                                                      ---
rem --- by Gerby                                             ---
rem ---                                                      ---
rem --- See WSUS Offline Update forums for more information: ---
rem --- http://forums.wsusoffline.net/viewtopic.php?t=43     ---
rem ------------------------------------------------------------

setlocal
title Build Latest Trunk - WSUS Offline Update


rem --- Check for UnZip utility --------------------------------
if not exist unzip.exe (
for %%U in (unzip.exe) do if "%%~$PATH:U"=="" goto NoUnzip
)

rem --- Search for latest trunk --------------------------------
rem --- Use latest marked trunk (prefix !) if it exists --------
set TrunkSearcher=trunk-*.zip
set MarkedTrunkSearcher=!%TrunkSearcher%
if exist %MarkedTrunkSearcher% (set TrunkSearcher=%MarkedTrunkSearcher% & set MarkerSet=1) else (set MarkerSet=0)
if not exist %TrunkSearcher% goto NoTrunk

set HighestRev=0
for %%R in (%TrunkSearcher%) do call :CompareRev %%R
set BuildTrunk=trunk-%RChar%%HighestRev%.zip
set BuildDir=build-r%HighestRev%
if %MarkerSet% == 1 ren !%BuildTrunk% %BuildTrunk%
if exist %BuildDir%\nul goto AlreadyExists


rem --- Procedure for creating the build -----------------------
echo Using trunk r%HighestRev%...
echo.

echo Cleaning up...
if exist trunk\nul rmdir /s /q trunk

echo Unpacking trunk...
unzip -q %BuildTrunk%
if errorlevel 1 goto :UnziProb

echo Doing the build process...
mkdir %BuildDir%
cd trunk
call PrepareReleaseTree.cmd ..\%BuildDir%
cd ..

echo Cleaning up afterwards...
ping -n 3 127.0.0.1 > nul
rmdir /s /q trunk
echo Finished!
goto End


rem --- Sub batch for searching latest revision ----------------
:CompareRev
set TempRev=%1
if %MarkerSet% == 1 (
  if %TempRev:~7,1% == r (
    set TempRChar=r
    set TempRev=%TempRev:~8,-4%
  ) else (
    set "TempRChar="
    set TempRev=%TempRev:~7,-4%
  )
) else (
  if %TempRev:~6,1% == r (
    set TempRChar=r
    set TempRev=%TempRev:~7,-4%
  ) else (
    set "TempRChar="
    set TempRev=%TempRev:~6,-4%
  )
)
if %TempRev% GTR %HighestRev% (
  set HighestRev=%TempRev%
  set RChar=%TempRChar%
)
goto :eof


rem --- Error messages with beeps ------------------------------
:NoUnzip
echo Error: The UnZip utility cannot be found on the system.
echo Aborting.
goto :End

:NoTrunk
echo There's no trunk package %TrunkSearcher% in the current directory.
echo Nothing to do.
goto :End

:AlreadyExists
echo Build r%HighestRev% already exists.
echo Nothing to do.
goto :End

:UnziProb
echo A problem occured while trying to unzip.
echo Please check the %BuildTrunk% file.
echo Aborting.
goto :End


:End
echo.
echo Press a key to quit...
pause > nul

Prerequisites
  • Copy the batch file BuildLatestTrunk.cmd to the same directory, where you save all the trunk archives (and where the build directories shall be created).
  • The UnZip utility by Info-ZIP (unzip.exe) must either reside in the same directory as the batch file or must be reachable via the PATH environment variable.
    Info-ZIP homepage: http://infozip.sourceforge.net/
    Binary download: ftp://ftp.info-zip.org/pub/infozip/win32/
    Note: Starting with r41, unzip.exe is contained in the trunk. So you can extract/copy the binary from there.
How to use
Just start the batch file BuildLatestTrunk.cmd without any parameters.

It takes the latest revision from the trunk archives residing in the current directory (trunk-r*.zip), unpacks it, and runs the build routine PrepareReleaseTree.cmd contained in the trunk archive. Voilà: You've got the ready to use files in a build directory corresponding to the trunk archive (e.g. build-r123).

Bonus feature :!: : If you want to create a build from a specific trunk revision (for those of you collecting the trunk archives), rename the corresponding archive by putting an exclamation mark in front (e.g. !trunk-r123.zip) and run the batch file. It automatically detects the prefix and uses that trunk revision.

Hope it makes life a little bit more comfortable. Here it does. 8-)

Greetings
Gerby
Last edited by Gerby on 12.01.2012, 21:04, edited 3 times in total.
Mach mit - der Übersichtlichkeit wegen! Füge Log-Auszüge als [Code] ein.
Make it clear! Insert log excerpts as [Code].
Gerby
 
Posts: 504
Joined: 11.09.2009, 15:57
Location: DE > SH > SE

Re: Facilitate a build from the trunk

Postby WSUSUpdateAdmin » 07.10.2009, 20:57

Hi Gerby,

thanks a lot for your effort!

Regards
Torsten Wittrock
WSUSUpdateAdmin
Administrator
 
Posts: 2245
Joined: 07.07.2009, 14:38

Re: Facilitate a build from the trunk

Postby Denniss » 09.03.2011, 14:41

Nice util, used it for the first time today.
But I had a problem: despite having unzip.exe placed in the same directory the script did not detect it and exits. Maybe it was Win7 or spaces in the directory name - no idea. After commenting out the search for unzip.exe the script did work.
Denniss
 
Posts: 869
Joined: 01.08.2009, 10:51

Re: Facilitate a build from the trunk

Postby Gerby » 10.03.2011, 11:30

Thanks for the hint, Denniss! :)

Never checked that one since here the unzip utility always resides in a directory contained in PATH.

I've updated the batch file code in the initial post. It contains also some minor/cosmetic changes.

Greetz
Gerby
Mach mit - der Übersichtlichkeit wegen! Füge Log-Auszüge als [Code] ein.
Make it clear! Insert log excerpts as [Code].
Gerby
 
Posts: 504
Joined: 11.09.2009, 15:57
Location: DE > SH > SE

Re: Facilitate a build from the trunk

Postby -Iwan- » 11.03.2011, 07:31

Guten morgen,

warum greifst du nicht einfach auf die unzip.exe zurück, die im bin-Ordner liegt?
-Iwan-
 
Posts: 364
Joined: 02.11.2009, 17:49
Location: NRW, Germany

Re: Facilitate a build from the trunk

Postby Gerby » 11.03.2011, 08:37

Guten Morgen Iwan - Good morning Iwan!

(I stay with English here, so that all readers can continue participating in this thread.)

My first thought to your hint was: "Sure, why haven't I've seen that before?". However, if the batch should use the unzip.exe directly from the downloaded trunk (ZIP file), this leads to the typical chicken-and-egg question. The batch must unzip the trunk to access the unzip utility.

Other ideas I've already went through: Although Windows has a zip functionality included since XP, this cannot be accessed by the command line. Also a download directly from the trac website would require a download tool not available natively.

Conclusion: We don't want to make life with trunks to easy, do we? ;-)
Mach mit - der Übersichtlichkeit wegen! Füge Log-Auszüge als [Code] ein.
Make it clear! Insert log excerpts as [Code].
Gerby
 
Posts: 504
Joined: 11.09.2009, 15:57
Location: DE > SH > SE

Re: Facilitate a build from the trunk

Postby rednaxela » 11.01.2012, 05:53

Good morning!

I frequently use the batch above and it works quite good, thanks to Gerby :)

But, from time to time, the following happens:

1. the trunk was unzipped :)
2. the directory for the build was created :)
3. the build was created :)

Then, trying to clean up with "rmdir /q /s", an error message appears: directory cannot be deleted because it is not empty" :shock:
and leaves the empty dir "trunk" (only with the empty dir "bin" in it).

Maybe there is a handle to a file not closed fast enough :?: Or the cpu ist too fast or the hdd too slow :lol:

For me i have solved this issue by inserting a "pause" in line 55 of the batch. What´s about a delay instead?

Greetz
Alexander
Sorry for my english.
Die Mehrheit der Mitglieder dieses Forums hat sich dafür ausgesprochen höflich und respektvoll miteinander umzugehen. Neue Mitglieder werden gebeten diese Entscheidung zu respektieren und sich ebenfalls so zu verhalten ;)
Bin ab und zu mal hier...
rednaxela
 
Posts: 164
Joined: 15.09.2010, 09:22
Location: Niedersachsen

Re: Facilitate a build from the trunk

Postby Gerby » 11.01.2012, 12:11

Hi Alexander!

It seems that the AutoIt compiler (Aut2Exe.exe) interferes with the rmdir command. This is the program that is run from the trunk\bin directory before the trunk tree is deleted.

However, to make a pragmatic workaround based on your idea, just insert the following line (instead of the pause command you are using right now):
Code: Select all
ping -n 3 127.0.0.1 > nul

Because Windows doesn't provide a wait command, you can build this by (mis)using the ping command that creates a pause of n-1 seconds (in this case 2 seconds). I hope that will do it. If not, try to play with the number of seconds.

There certainly would be a solution to check for Aut2Exe.exe task or something like that. But this would bload the batch.

When you've gained some experience with this patch, I would be happy about a feedback. Then I will insert the line in the code listed in the first post. The related code block then looks like this:
Code: Select all
echo Cleaning up afterwards...
rem Allow some time to release handles
ping -n 3 127.0.0.1 > nul
rmdir /s /q trunk
echo Finished!
goto End


Greetz
Gerby

P.S.: Du entschuldigst Dich dafür, dass Du gutes Englisch schreibst? ;-)
Mach mit - der Übersichtlichkeit wegen! Füge Log-Auszüge als [Code] ein.
Make it clear! Insert log excerpts as [Code].
Gerby
 
Posts: 504
Joined: 11.09.2009, 15:57
Location: DE > SH > SE

Re: Facilitate a build from the trunk

Postby boco » 11.01.2012, 14:51

Code: Select all
ping -n 3 127.0.0.1 > nul


The following is more exact:
Code: Select all
ping -n 3 -w 1000 127.0.0.1 > nul


The -w parameter tells ping to wait 1s before continuing. So you'll get n seconds delay.
Microsoft update catalog: http://catalog.update.microsoft.com/v7/site/
Windows Install media download: https://support.microsoft.com/en-us/help/15088/windows-create-installation-media
boco
 
Posts: 2391
Joined: 24.11.2009, 17:00
Location: Germany

Re: Facilitate a build from the trunk

Postby rednaxela » 11.01.2012, 16:57

Hi Gerby and boco!

Thanks for your advices and hints :)

The solution from boco is more exact, no question, but i think the other (from Gerby) is good enough ;)

I have tried this and it seems to work very good. Until now i have integrated it as follows, i think it´s more clear then. Related code block (line 56 to 62):
Code: Select all
echo Two seconds delay before cleaning ;-)
ping -n 3 127.0.0.1 > nul
echo End of delay
echo Cleaning up afterwards...
rmdir trunk /s /q
echo Finished!
goto End

There are few ways to do. If you want to integrate it in your batch do it in the way YOU think, it´s your batch ;)

Greetz
Alexander
Die Mehrheit der Mitglieder dieses Forums hat sich dafür ausgesprochen höflich und respektvoll miteinander umzugehen. Neue Mitglieder werden gebeten diese Entscheidung zu respektieren und sich ebenfalls so zu verhalten ;)
Bin ab und zu mal hier...
rednaxela
 
Posts: 164
Joined: 15.09.2010, 09:22
Location: Niedersachsen

Next

Return to Verschiedenes / Miscellaneous

Who is online

Users browsing this forum: No registered users and 13 guests