128 lines
3.2 KiB
Bash
Executable file
128 lines
3.2 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
#
|
|
# Copyright (c) 2019-2021, mord0d and their slaves
|
|
# All rights reserved.
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without modification,
|
|
# are permitted provided that the following conditions are met:
|
|
#
|
|
# 1. Redistributions of source code must retain the above copyright notice, this
|
|
# list of conditions and the following disclaimer.
|
|
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
# this list of conditions and the following disclaimer in the documentation
|
|
# and/or other materials provided with the distribution.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
#
|
|
|
|
VERSION="0.6"
|
|
PROGNAME="gamelib"
|
|
|
|
arch="$(uname -m)"
|
|
uid="$(id -u)"
|
|
gid="$(id -g)"
|
|
|
|
: ${TMPDIR:=/tmp}
|
|
: ${GAMELIB_DEBUG:=0}
|
|
|
|
LOCKFILE="${TMPDIR}/.${PROGNAME}-${uid}.lock"
|
|
TEMPDIR="${TMPDIR}/.${PROGNAME}-${uid}"
|
|
|
|
# gl_log {{{
|
|
gl_log() {
|
|
local lvl="${1}"
|
|
shift
|
|
if [ "${lvl}" = "FTL" ] || [ "${GAMELIB_DEBUG}" -ne 0 ] || [ -z "${LOGFILE}" -o ! -w "${LOGFILE}" ]; then
|
|
echo "[${lvl}] ${*}" >&2
|
|
fi
|
|
echo "[${lvl}:${$}] $(date -j '+%Y-%m-%d %H:%M:%S') ${*}" >> "${LOGFILE:=/dev/null}"
|
|
}
|
|
# }}}
|
|
|
|
gl_run() {
|
|
}
|
|
gl_edit() {
|
|
}
|
|
gl_upgrade() {
|
|
}
|
|
gl_rollback() {
|
|
}
|
|
gl_usage() {
|
|
}
|
|
|
|
# gl_version {{{
|
|
gl_version() {
|
|
echo "${PROGNAME} ${VERSION}"
|
|
}
|
|
# }}}
|
|
|
|
# gl_license {{{
|
|
gl_license() {
|
|
sed -n 's/^# //; s/^#$//; 4,25p' "${0}"
|
|
}
|
|
# }}}
|
|
|
|
gl_list() {
|
|
}
|
|
|
|
game=''
|
|
subcommands=''
|
|
upgrade=0
|
|
rollback=0
|
|
edit=0
|
|
|
|
while :; do
|
|
case "${1}" in
|
|
('') break ;;
|
|
(-h|--help) gl_usage; exit 0 ;;
|
|
(-V|--version) gl_version; exit 0 ;;
|
|
(-L|--license) gl_license; exit 0 ;;
|
|
(-l|--list) gl_list; exit 0 ;;
|
|
(-v|--verbose) GAMELIB_DEBUG=1; shift ;;
|
|
(-u|--upgrade) upgrade=1; rollback=0; shift ;;
|
|
(-b|--rollback) rollback=1; upgrade=0; shift ;;
|
|
(-r|--run) shift; subcommands="${subcommands} ${1}"; shift ;;
|
|
(-e|--edit) edit=1; shift ;;
|
|
(-w|--workdir) shift; GAMELIB_GAMES_DIR="${1}"; shift ;;
|
|
(-*) gl_log ERR "Unknown option \"${1}\"!"; exit 1 ;;
|
|
(*) game="${1}"; shift ;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "${GAMELIB_GAMES_DIR}" ]; then
|
|
gl_log FTL "\"\$GAMELIB_GAMES_DIR\" is not defined!"
|
|
exit 1
|
|
fi
|
|
if [ ! -d "${GAMELIB_GAMES_DIR}" ]; then
|
|
gl_log FTL "\"\$GAMELIB_GAMES_DIR\" is not a directory"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "${game}" ]; then
|
|
gl_log FTL "No game specified!"
|
|
gl_list
|
|
exit 1
|
|
fi
|
|
|
|
if [ ${edit} -eq 1 ]; then
|
|
gl_edit "${game}"
|
|
exit ${?}
|
|
fi
|
|
|
|
if [ ${upgrade} -eq 1 ]; then
|
|
gl_upgrade "${game}"
|
|
elif [ ${rollback} -eq 1 ]; then
|
|
gl_rollback "${game}"
|
|
else
|
|
gl_run "${game}" "${subcommands}"
|
|
fi
|