Results 1 to 5 of 5

Thread: Bash script for downloading and running the latest build.

  1. #1
    Junior Member
    Join Date
    Mar 2016
    Posts
    2

    Talking Bash script for downloading and running the latest build.

    This was originally written by Zombie Feynman (#1886944). I honestly can't remember where I got it from (and I can't find it here), but I've made a few changes to it myself and found it to be quiet useful.

    After coming back from a brief vacation, I found that the builds have moved to Jenkins (yay!) but that the script no longer worked (boo!).

    So I fixed it, and decided to share it with other folks who are of the Linux persuasion (although it should be fine under Cygwin or Mac OS, too, if you've got the necessary tools installed). And because it works on the new build system, I felt that a new thread was in order.

    You'll need curl and to have java in your PATH.

    Have fun!

    Code:
    #!/bin/bash
    
    # Originally written by Zombie Feynman (#1886944), a Curious Character.
    # Tweaked and updated for Jenkins build system by NeppyMan (#1232476).
    
    # Download the latest build ...
    LATEST=$(curl ci.kolmafia.us/job/Kolmafia/lastSuccessfulBuild/artifact/dist/ | grep -o 'KoLmafia-[0-9][0-9][0-9][0-9][0-9].jar' | head -1)
    
    # Check whether the current build is already present. If it is, don't bother downloading it again.
    # The filename for KoLmafia is 18 characters long, and that seems unlikely to change in the near future.
    # This is a bit of a hacky solution, though ...
    
    if [ -f ${LATEST:(-18)} ]
    then
        echo "Latest KoLmafia build already present." 
    else
        echo "Fetching latest KoLmafia build."
        curl -O http://ci.kolmafia.us/job/Kolmafia/lastSuccessfulBuild/artifact/dist/$LATEST
    
        # Dump all but the most recent (to avoid filling up the directory) ...
        ls -tr *jar | head -n -1 | xargs rm
    fi
    
    # Launch the newest build on-hand ...
    LAUNCH=$(ls *jar | head -1)
    java -jar $LAUNCH &>/dev/null &disown
    
    exit 0

  2. #2
    Senior Member Theraze's Avatar
    Join Date
    Mar 2010
    Posts
    8,636

    Default

    Might I suggest only removing mafia jars? Some of us like to keep ALV or alternate downloaders that are also in the jar format, and the blanket removal approach here might surprise people who run code without understanding it.

  3. #3
    Developer
    Join Date
    Aug 2009
    Posts
    2,599

    Default

    I did modify this script a bit, but again, I don't really have any need for automatic updaters, since I build from source.

    Code:
    #!/bin/bash
    
    # Originally written by Zombie Feynman (#1886944), a Curious Character.
    # Tweaked and updated for Jenkins build system by NeppyMan (#1232476).
    
    # Download the latest build ...
    LATEST=$(curl ci.kolmafia.us/job/Kolmafia/lastSuccessfulBuild/artifact/dist/ | grep -Eo 'KoLmafia-[0-9]+.jar' | head -1)
    
    # Check whether the current build is already present. If it is, don't bother downloading it again.
    
    if [ -f $LATEST ]
    then
        echo "Latest KoLmafia build already present." 
    else
        echo "Fetching latest KoLmafia build."
        curl -O http://ci.kolmafia.us/job/Kolmafia/lastSuccessfulBuild/artifact/dist/$LATEST
    
        # Dump all but the most recent (to avoid filling up the directory) ...
        ls -tr KoLmafia-*.jar | head -n -1 | xargs rm -f
    fi
    
    # Launch the newest build on-hand ...
    java -jar $LATEST &>/dev/null &disown
    
    exit 0

  4. #4
    Junior Member
    Join Date
    Mar 2016
    Posts
    2

    Default

    Might I suggest only removing mafia jars? Some of us like to keep ALV or alternate downloaders that are also in the jar format, and the blanket removal approach here might surprise people who run code without understanding it.
    Originally Posted by Theraze View Post
    Ooh, yeah, good point on that - and thanks to heeheehee for already taking care of it (and fixing the regex).

  5. #5
    Junior Member
    Join Date
    Mar 2016
    Posts
    1

    Default

    It's interesting, I actually just recently wrote another script to do exactly this. https://github.com/Elronnd/mafia-auto-updater. It's a lot more user friendly than this one in that it: produces pretty and colourful messages that tell the user what it's doing, tells the user the commit message and number of their build, is mostly POSIX-compliant (aside from needing java and curl) so it can be run on any shell, and most importantly, will detect if the previous download was interrupted, thus creating a partial and unrunnalbe jarfile

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •