Skip to content

Instantly share code, notes, and snippets.

@dermorz
Last active Mar 5, 2022
Embed
What would you like to do?
Minimal bash implementation of a sc2replaystats.com uploader. Requirements: inotify-tools, curl, awk
#!/bin/bash
#
# Usage: ./sc2replaystats.sh
#
# Keep one instance of this script running when playing Starcraft II.
# For example run it with systemd in user-space so it's just always running when logged in.
# Better output on errors
set -euxo pipefail
# I have a symlink from $HOME/replays to "$HOME/StarCraft II/Accounts/{ID}/{TOON_ID}/Replays/Multiplayer".
# You can also just put the direct path here.
REPLAYS="$HOME/replays"
# Create curl version string to use as upload method in API call.
CURL_VERSION=$(curl --version | head -n 1 | awk '{ print $1 "-" $2 }')
# sc2replaystats API config
SC2RS_API=https://api.sc2replaystats.com
SC2RS_AUTHKEY="your api authentication key here"
# Watch the replay folder for newly created files (ignores renames)
inotifywait --monitor --event close_write --format "%f" "${REPLAYS}" \
| while read FILENAME
do
# Only process SC2Replay files
[[ $FILENAME != *.SC2Replay ]] && continue
# Get absolute file path
REPLAY_FILE=$(realpath "${REPLAYS}/${FILENAME}")
# Upload replay via API call
curl \
-H "Authorization: ${SC2RS_AUTHKEY}" \
-F "upload_method=${CURL_VERSION}" \
-F "replay_file=@${REPLAY_FILE}" \
"${SC2RS_API}/replay"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment