Run most Recent Daily

bumcheekcity

Active member
So I use the daily builds because I am cool, and I'll always want to run the most recent. I just dump them in my kolmafia folder and forget about it.

Can anyone write a little batch file or something that looks for files in the format "Kolmafia-1234.jar" and then opens the one with the largest number, so that I can just execute "mafia.bat" or whatever, and it'll always open the most recent build I have in my Kolmafia folder.
 

Catch-22

Active member
This isn't as fancy, but it will probably do what you want. Provided you're using Windows...

Code:
Option Explicit
Dim objShell, objFSO, File, Build1, Build2
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Build1 = 0

objShell.CurrentDirectory = objFSO.GetParentFolderName(Wscript.ScriptFullName)

For Each File in objFSO.GetFolder(objShell.CurrentDirectory).Files
	If (InStr(File, "KoLmafia-") And InStrRev(File, ".jar")) Then
		Build2 = Right(File, Len(File) - InStrRev(File, "\"))
		Build2 = CInt(Replace(Replace(Build2, "KoLmafia-", ""), ".jar", ""))
		If Build1 < Build2 Then
			Build1 = Build2
		End If
	End If
Next

If Build1 > 0 Then
	objShell.Run "KoLmafia-" & Build1 & ".jar", 1, False
End If

Copy and paste that into notepad and save it as something like "KoLmafia.vbs".

Run it from your KoLmafia directory.
 

Fluxxdog

Active member
For those Linux users

If you run a Linux ennivonment, this script might help. This was written using BASH and should be easily tweakable.
Code:
#!/bin/bash

# This script will test for the latest KoLmafia JAR build compared to the latest SVN version.
# In case of discrepancies between SVN and the jatest JAR build, it'll check for the most recent JAR.
# "wget --spider" tests for the existance of web pages.

# Determine current SVN jar version (quietly)
currver=$(eval "svn info -r HEAD https://kolmafia.svn.sourceforge.net/svnroot/kolmafia | grep Revision: ")
kolmver=${currver:10}

# Check to see if you don't already have that version downloaded
until ( eval "wget --spider http://builds.kolmafia.us/KoLmafia-$kolmver.jar" ); # If current build doesn't match SVN
do
	let kolmver=$kolmver-1 # Decrement until we find the most recent build
done
if [ ! -e KoLmafia-$kolmver.jar ] # Check to see if we don't have the most recent JAR
then # if not, remove old copies and download then latest JAR
	echo "Current JAR version is $kolmver.  Youse ain't got dat!"
	rm KoLmafia-*.jar
	wget http://builds.kolmafia.us/KoLmafia-$kolmver.jar
else # Don't bother redownloading what you already have
	echo "Youse already got da latest KoLmafia!"
fi

# # Uncomment the line below to have KoLmafia run as soon as you check for the latest version
# java -jar KoLmafia-$kolmver.jar
# # Modify it as needed

exit 0
Big thanks to Catch-22 for the 'svn info' heads up! Worked like a charm.
Now checks against SVN and existence of JARs. Should reduce problems.
 
Last edited:

zarqon

Well-known member
@Fluxxdog: Excellent, since Rinn posted the little tool for Windows I've been hoping for a Linux equivalent. What do I save this script as? Just a txt file? Sorry, at the moment I'm still very GUI-dependent in Linux, and don't know much of the behind-the-GUI goings-on.
 

Fluxxdog

Active member
Well, you can save it as a shell script, then create a shortcut on your desktop to point to the script. I would recommend you use the "Run in Terminal" option. Just make sure you chmod the shell script to executable. 755 should do the trick.

If none of this makes sense, remember that Google is your friend. That's how I learned the vast majority of my Linux skills. So much is out there.
 

mredge73

Member
It is not working for me, it cannot seem to find the latest build info.

Code:
EdgeServer:~$ bash mafia.sh
mafia.sh: line 10: svn: command not found
rm: cannot remove `KoLmafia-*.jar': No such file or directory
--2009-11-29 20:01:45--  http://builds.kolmafia.us/KoLmafia-.jar
Resolving builds.kolmafia.us... 74.207.228.89
Connecting to builds.kolmafia.us|74.207.228.89|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2009-11-29 20:01:45 ERROR 404: Not Found.

how would I modify it to just download the latest regardless of what version is on the computer?
 

Catch-22

Active member
This is actually a problem with the method I have posted.

svn info will get the latest revision, NOT the latest build. There's a 1 hour window with which someone can commit changes to SVN which will throw the build number out of whack.

I only thought of this after I posted, but I didn't realise that Fluxxdog had switched over to using svn info.

The old way of using curl is probably the only reliable way at the moment.

Maybe you can ask fewyn to add something like a "latest.txt" file into the cron job so that you can determine the latest build by downloading http://builds.kolmafia.us/latest.txt instead of having to use curl to read the builds page...
 

mredge73

Member
I don't have the original, he overwrote it in the post above.

I am not a linux wiz, I don't know the first thing about building a bash script or anything about ant. I was looking for something just like Rinn's script (works great on my windows machine) but the one posted above for linux is broken.
 

Fluxxdog

Active member
Well, it works for the most part. If you happen to have the bad timing where the update and current build are out of sync, yeah, that can cause a hangup. Other than that, it's worked pretty well. I'm gonna do some hunting and see if I can fine tune it some. Basically, what I need is something to test whether a file exists through an http.

FOLLOWUP: New script is up. Dug in to wget a bit and discovered the --spider command for the first time. Works like a charm. Shouldn't have anymore problems.
 
Last edited:

mredge73

Member
The first part still does not work for me, it cannot determine the newest version available. It always sets kolmver=0

Making the countdown count down from 7900 seems to work for now:
Code:
#!/bin/bash

# This script will test for the latest KoLmafia JAR build compared to the latest SVN version.
# In case of discrepancies between SVN and the jatest JAR build, it'll check for the most recent JAR.
# "wget --spider" tests for the existance of web pages.

# Determine current SVN jar version (quietly)
currver=$(eval "svn info -r HEAD https://kolmafia.svn.sourceforge.net/svnroot/kolmafia | grep Revision: ")
kolmver=${currver:10}
kolmver= 7900

# Check to see if you don't already have that version downloaded
until ( eval "wget --spider http://builds.kolmafia.us/KoLmafia-$kolmver.jar" ); # If current build doesn't match SVN
do
    let kolmver=$kolmver-1 # Decrement until we find the most recent build
done
if [ ! -e KoLmafia-$kolmver.jar ] # Check to see if we don't have the most recent JAR
then # if not, remove old copies and download then latest JAR
    echo "Current JAR version is $kolmver.  Youse ain't got dat!"
    rm KoLmafia-*.jar
    wget http://builds.kolmafia.us/KoLmafia-$kolmver.jar
else # Don't bother redownloading what you already have
    echo "Youse already got da latest KoLmafia!"
fi

# # Uncomment the line below to have KoLmafia run as soon as you check for the latest version
# java -jar KoLmafia-$kolmver.jar
# # Modify it as needed


exit 0
 

Alhifar

Member
You need to have svn installed. On ubuntu (or any system using apt-get), simply type "apt-get install svn" into the terminal to install. For any other system, you'll have to look up the syntax for your package manager.
 
Top