#!/bin/bash # Wrapper script for starting The Ur-Quan Masters HTTPBASE="http://user.interface.org.nz/~lorne/uqm" kill_uqm() { [ -d "/mnt/scratch/uqm" ] && rm -ir "/mnt/scratch/uqm" } run_uqm() { get_files echo "Running.." echo "$BINPATH/uqm" --contentdir="$CONTENTPATH" "$@" "$BINPATH/uqm" --contentdir="$CONTENTPATH" "$@" } get_files() { CONTENT="$CONTENTPATH/packages/uqm-0.5.0-content.uqm" BINARY="$BINPATH/uqm" } fetch_files() { get_files if [ ! -f "$CONTENT" ]; then CONTENTPATH="/mnt/scratch/uqm/share/uqm/content" get_files mkdir -p "$CONTENTPATH/packages" wget "$HTTPBASE/uqm-0.5.0-content.uqm" -O "$CONTENT" wget "$HTTPBASE/version" -O "$CONTENTPATH/version" fi if [ ! -f "$BINARY" ]; then echo $BINPATH BINPATH="/mnt/scratch/uqm/lib/uqm" get_files mkdir -p "$BINPATH" wget "$HTTPBASE/uqm" -O "$BINARY" chmod +x "$BINARY" fi } check_files() { echo Checking files [ -f "$CONTENT" ] || echo "Content is missing ($CONTENT)" [ -f "$BINARY" ] || echo "Binary is missing ($BINARY)" [ ! -f "$BINARY" ] || [ ! -f "$CONTENT" ] && return -1 expected_sum=$(mktemp uqm-sum.XXXXXX) m4 -DCONTENT="$CONTENT" -DBINARY="$BINARY" > "$expected_sum" < "$generated_sum" diff "$expected_sum" "$generated_sum" 2>&1 > /dev/null files_ok=$? if [ $files_ok -eq 0 ]; then echo "Files ok" result=0 else echo "Files corrupt" result=-1 echo "-- expected --" cat "$expected_sum" echo "-- actual --" cat "$generated_sum" fi rm "$expected_sum" "$generated_sum" return $result } find_uqm() { until [[ -z "$1" || ("$BINPATH" && "$CONTENTPATH") ]]; do if [[ -z "$BINPATH" && -x "$1/lib/uqm/uqm" ]]; then BINPATH="$1/lib/uqm" fi if [[ -z "$CONTENTPATH" && -d "$1/share/uqm/content" ]]; then CONTENTPATH="$1/share/uqm/content" fi shift done get_files } find_uqm "$HOME/.uqm" "/mnt/scratch/uqm" case "$1" in fetch) fetch_files;; check) check_files;; run) check_files && run_uqm;; remove) kill_uqm;; voodoo) fetch_files && check_files && run_uqm && kill_uqm;; *) echo "$0 [ fetch | check | remove | run | voodoo ]";; esac