Bash based auto-updater/launch script for Linux

xaix1999

New member
Hello Mafia,

I had been looking for a bash script to do this task and I have yet to find one that is up-to date and or uses GitHub to not slam the mafia servers.
Maybe I'm blind or didn't look enough but I made this. The script is a little crude but if anyone has any suggestions, please let me know.
Updated the script to rm old version numbers. Updated again to remove cut in place for awk+grep. Sort "should" help with it never breaking due to the version number being six digits.

Bash:
#! /bin/bash
Ver=$(curl -s https://api.github.com/repos/kolmafia/kolmafia/releases/latest | grep --color=never tag_name | grep --color=never -o '[0-9]\+')
#
## echo $Ver
re='^[0-9]+$'
if ! [[ $Ver =~ $re ]] ; then
echo "error: Version is not a number" >&2; exit 1
fi
#
ArA='KoLmafia*'
for i in $ArA
    do
    if ! [[ $i =~ "KoLmafia-"$Ver".jar" ]] ; then
    rm $i
    fi
done
#
if ! [[ -f "KoLmafia-"$Ver".jar" ]] ; then
wget -q https://github.com/kolmafia/kolmafia/releases/download/r$Ver/KoLmafia-$Ver.jar
fi
#
java -jar KoLmafia-$Ver.jar &>/dev/null &disown
 
Last edited:

Rinn

Developer
Bash:
#!/bin/bash
pushd ${TMPDIR-/tmp}
echo Downloading new versions of kolmafia...
MAFIA_RELEASE=$(curl --fail --silent --globoff 'https://api.github.com/repos/kolmafia/kolmafia/releases/latest' | jq --raw-output '.assets[] | select(.browser_download_url | contains(".jar")).browser_download_url')
if [[ -z "$MAFIA_RELEASE" ]]; then
    echo "Could not determine latest mafia release from GitHub!"
    exit 1
fi
wget -N "$MAFIA_RELEASE"
latest=$(ls -dt KoLmafia-*.jar | head -1)
oldest=$(ls -td KoLmafia-*.jar | awk 'NR>5')
if [ -n "$oldest" ]; then
    echo Removing old KoLmafia jar files...
    rm ${oldest}
fi
popd
echo Copying kolmafia.jar from ${latest}...
if [ -f "kolmafia.jar" ]; then rm kolmafia.jar; fi
cp ${TMPDIR-/tmp}/${latest} kolmafia.jar
exit 0

requires curl wget and jq
 
Top