#! /bin/bash # # General launcher script for dgamelaunch actions. The idea is to symlink # this (one) script into $HOME/bin and use it to run the others. SELF="$0" SCRIPT_NAME=$(basename $0) usage() { echo -e "Usage: $SCRIPT_NAME $@" } cat-error() { cat >&2 } report-usage() { printf "Usage: $SCRIPT_NAME " >&2 cat-error exit 1 } canonical-name() { local name=$1 if [[ -d "$name" ]]; then printf "%s\n" "$(cd $name && echo $PWD)" else local dir=$(cd $(dirname $name) && echo $PWD) printf "%s\n" "$dir/$(basename $name)" fi } test-set-dgl-home() { if [[ -n "$DGL_CONF_HOME" ]]; then return 0 fi local dir=$1 if [[ -d "$dir" && -d "$dir/bin" && -f "$dir/dgamelaunch.conf" \ && -d "$dir/chroot" ]]; then export DGL_CONF_HOME="$(canonical-name $dir)" export DGL_CONF_LOGS="$dir/logs" mkdir -p "$DGL_CONF_LOGS" fi } find-dgl-home() { test-set-dgl-home "$HOME/conf-dgamelaunch" test-set-dgl-home "$(dirname $SELF)/.." local link_target="$(readlink $0)" if [[ -n "$link_target" ]]; then test-set-dgl-home "$(dirname $(readlink $SELF))/.." fi if [[ -z "$DGL_CONF_HOME" ]]; then echo -e "Cannot find dgamelaunch config base directory" return 1 fi } resolve-action() { local action="$1" local script="$DGL_CONF_HOME/bin/$action.sh" if [[ ! -f "$script" ]]; then cat-error <" echo -e "Where is one of:" list-all-actions >&2 exit 1 fi ACTION_SCRIPT="$(resolve-action $ACTION)" [[ -z "$ACTION_SCRIPT" ]] && exit 1 cd "$DGL_CONF_HOME" source ./sh-utils SCRIPT_NAME="$SCRIPT_NAME $ACTION" source "$ACTION_SCRIPT"