Skip to content

Instantly share code, notes, and snippets.

Last active Mar 5, 2022
What would you like to do?
Minimal bash implementation of a uploader. Requirements: inotify-tools, curl, awk
# Usage: ./
# 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.
# 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_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
# Only process SC2Replay files
[[ $FILENAME != *.SC2Replay ]] && continue
# Get absolute file path
# Upload replay via API call
curl \
-H "Authorization: ${SC2RS_AUTHKEY}" \
-F "upload_method=${CURL_VERSION}" \
-F "replay_file=@${REPLAY_FILE}" \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment