Skip to content

Instantly share code, notes, and snippets.

@snapcase snapcase/reflex_update
Last active Oct 23, 2015

Embed
What would you like to do?
update reflex server
#!/bin/bash
#
# update (a single) reflex server
# snapcase 2015
#
REFLEX_DIR="$HOME/reflex"
APPID=329740
die() { error "$*"; exit 1; }
error() { printf "error: $*\n" >&2; }
info() { printf ":: $*\n"; }
local_version() {
find $REFLEX_DIR -iname '*.acf' | \
xargs sed -n 's|.*"buildid"\t\t"\([^"]*\)"|\1|p'
}
remote_version() {
local version
version="$(steamcmd +login anonymous +app_info_print $APPID +force_install_dir ./4 +app_update 4 +app_info_print $APPID +quit | \
sed -n \
'1,/^\t\{2\}"branches"$/d
/^\t\{2\}"branches"$/,/^\t\{2\}}$/{
/"public"$/,/}/ s|.*buildid"\t\{2\}"\([0-9]\+\)".*|\1|p
}')"
printf "%d\n" $version
[[ $version =~ ^[0-9]+$ ]]
}
get_display() {
DISPLAY="$(pgrep -U $USER -lf Xvfb | sed -n 's|^[0-9]\+\sXvfb\s\(:[0-9]\+\).*|\1|p')"
[[ $DISPLAY ]]
}
# update and restart
update() {
steamcmd \
+@sSteamCmdForcePlatformType windows \
+login anonymous \
+force_install_dir $REFLEX_DIR \
+app_update $APPID validate \
+quit >/dev/null
# wait for everyone to leave the server
# we don't want to kill it mid game
until [ $(players) -eq 0 ]; do
sleep 25
done
pkill -U $USER reflexded.exe
}
# check window title for players
players() {
xwininfo -display $DISPLAY -root -children | \
sed -n 's|.*\([0-9]\+\)/[0-9]\+ players.*\"reflexded.exe".*|\1|p'
}
# main
# make sure an instance of this
# script is not already running
for pid in $(pidof -x "$0"); do
if [ $pid != $$ ]; then
die "already running"
fi
done
# determine versions
local_version=$(local_version)
remote_version=$(remote_version) || die "potential steam error"
if [[ $local_version != $remote_version ]]; then
get_display || die "display not found"
update
info "updated"
else
info "nothing to do"
fi
#!/bin/sh
WINEDEBUG=-all
HOSTNAME="My Reflex Server"
cd $HOME/reflex$1
while true; do
xvfb-run \
--auth-file=$HOME/.Xauthority \
--server-num=0 \
--server-args='-screen 0 640x480x16' \
wine reflexded.exe +sv_hostname $HOSTNAME +sv_public 0
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.