From 9078ff73c78beb048082b61bbfbf4c8d25ba08d2 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 28 Apr 2018 13:08:12 +0000 Subject: [PATCH] Ensure required variables are defined before running scripts. --- Makefile | 19 ++++++++++++++++--- fetch-engine.sh | 16 ++++++++++++++++ launch-dedicated.cmd | 12 ++++++++++++ launch-dedicated.sh | 14 ++++++++++++++ launch-game.cmd | 13 +++++++++++++ launch-game.sh | 14 ++++++++++++++ make.ps1 | 21 +++++++++++++++++++++ packaging/linux/buildpackage.sh | 16 ++++++++++++++++ packaging/osx/buildpackage.sh | 16 ++++++++++++++++ packaging/windows/buildpackage.sh | 16 ++++++++++++++++ utility.cmd | 12 ++++++++++++ utility.sh | 14 ++++++++++++++ 12 files changed, 180 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c52c7ac..4ecdb4b 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,20 @@ HAS_LUAC = $(shell command -v luac 2> /dev/null) LUA_FILES = $(shell find mods/*/maps/* -iname '*.lua') PROJECT_DIRS = $(shell dirname $$(find . -iname "*.csproj" -not -path "$(ENGINE_DIRECTORY)/*")) -engine: +variables: + @if [ -z "$(MOD_ID)" ] || [ -z "$(ENGINE_DIRECTORY)" ];then \ + echo "Required mod.config variables are missing:"; \ + if [ -z "$(MOD_ID)" ]; then \ + echo " MOD_ID"; \ + fi; \ + if [ -z "$(ENGINE_DIRECTORY)" ]; then \ + echo " ENGINE_DIRECTORY"; \ + fi; \ + echo "Repair your mod.config (or user.config) and try again."; \ + exit 1; \ + fi + +engine: variables @./fetch-engine.sh || (printf "Unable to continue without engine files\n"; exit 1) @cd $(ENGINE_DIRECTORY) && make core @@ -60,13 +73,13 @@ endif @cd $(ENGINE_DIRECTORY) && make clean @printf "The engine has been cleaned.\n" -version: +version: variables @awk '{sub("Version:.*$$","Version: $(VERSION)"); print $0}' $(MANIFEST_PATH) > $(MANIFEST_PATH).tmp && \ awk '{sub("/[^/]*: User$$", "/$(VERSION): User"); print $0}' $(MANIFEST_PATH).tmp > $(MANIFEST_PATH) && \ rm $(MANIFEST_PATH).tmp @printf "Version changed to $(VERSION).\n" -check-scripts: +check-scripts: variables ifeq ("$(HAS_LUAC)","") @printf "'luac' not found.\n" && exit 1 endif diff --git a/fetch-engine.sh b/fetch-engine.sh index 0e53acd..c7ae4f3 100755 --- a/fetch-engine.sh +++ b/fetch-engine.sh @@ -5,6 +5,18 @@ command -v curl >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires curl."; exit 1; } command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } +require_variables() { + missing="" + for i in "$@"; do + eval check="\$$i" + [ -z "${check}" ] && missing="${missing} ${i}\n" + done + if [ ! -z "${missing}" ]; then + echo "Required mod.config variables are missing:\n${missing}Repair your mod.config (or user.config) and try again." + exit 1 + fi +} + TEMPLATE_LAUNCHER=$(python -c "import os; print(os.path.realpath('$0'))") TEMPLATE_ROOT=$(dirname "${TEMPLATE_LAUNCHER}") @@ -16,6 +28,8 @@ if [ -f "${TEMPLATE_ROOT}/user.config" ]; then . "${TEMPLATE_ROOT}/user.config" fi +require_variables "MOD_ID" "ENGINE_VERSION" "ENGINE_DIRECTORY" + CURRENT_ENGINE_VERSION=$(cat "${ENGINE_DIRECTORY}/VERSION" 2> /dev/null) if [ -f "${ENGINE_DIRECTORY}/VERSION" ] && [ "${CURRENT_ENGINE_VERSION}" = "${ENGINE_VERSION}" ]; then @@ -23,6 +37,8 @@ if [ -f "${ENGINE_DIRECTORY}/VERSION" ] && [ "${CURRENT_ENGINE_VERSION}" = "${EN fi if [ "${AUTOMATIC_ENGINE_MANAGEMENT}" = "True" ]; then + require_variables "AUTOMATIC_ENGINE_SOURCE" "AUTOMATIC_ENGINE_EXTRACT_DIRECTORY" "AUTOMATIC_ENGINE_TEMP_ARCHIVE_NAME" + echo "OpenRA engine version ${ENGINE_VERSION} is required." if [ -d "${ENGINE_DIRECTORY}" ]; then diff --git a/launch-dedicated.cmd b/launch-dedicated.cmd index 266be85..0b3ad28 100644 --- a/launch-dedicated.cmd +++ b/launch-dedicated.cmd @@ -10,12 +10,17 @@ set EnableSingleplayer=False set Password="" @echo off +setlocal EnableDelayedExpansion title %Name% FOR /F "tokens=1,2 delims==" %%A IN (mod.config) DO (set %%A=%%B) if exist user.config (FOR /F "tokens=1,2 delims==" %%A IN (user.config) DO (set %%A=%%B)) set MOD_SEARCH_PATHS=%~dp0mods,./mods +if "!MOD_ID!" == "" goto badconfig +if "!ENGINE_VERSION!" == "" goto badconfig +if "!ENGINE_DIRECTORY!" == "" goto badconfig + if not exist %ENGINE_DIRECTORY%\OpenRA.Game.exe goto noengine >nul find %ENGINE_VERSION% %ENGINE_DIRECTORY%\VERSION || goto noengine cd %ENGINE_DIRECTORY% @@ -28,4 +33,11 @@ goto loop echo Required engine files not found. echo Run `make all` in the mod directory to fetch and build the required files, then try again. pause +exit /b + +:badconfig +echo Required mod.config variables are missing. +echo Ensure that MOD_ID ENGINE_VERSION and ENGINE_DIRECTORY are +echo defined in your mod.config (or user.config) and try again. +pause exit /b \ No newline at end of file diff --git a/launch-dedicated.sh b/launch-dedicated.sh index 40887f0..3feac05 100755 --- a/launch-dedicated.sh +++ b/launch-dedicated.sh @@ -8,6 +8,18 @@ set -e command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } command -v mono >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires mono."; exit 1; } +require_variables() { + missing="" + for i in "$@"; do + eval check="\$$i" + [ -z "${check}" ] && missing="${missing} ${i}\n" + done + if [ ! -z "${missing}" ]; then + echo "Required mod.config variables are missing:\n${missing}Repair your mod.config (or user.config) and try again." + exit 1 + fi +} + TEMPLATE_LAUNCHER=$(python -c "import os; print(os.path.realpath('$0'))") TEMPLATE_ROOT=$(dirname "${TEMPLATE_LAUNCHER}") MOD_SEARCH_PATHS="${TEMPLATE_ROOT}/mods,./mods" @@ -20,6 +32,8 @@ if [ -f "${TEMPLATE_ROOT}/user.config" ]; then . "${TEMPLATE_ROOT}/user.config" fi +require_variables "MOD_ID" "ENGINE_VERSION" "ENGINE_DIRECTORY" + NAME="${Name:-"Dedicated Server"}" LAUNCH_MOD="${Mod:-"${MOD_ID}"}" LISTEN_PORT="${ListenPort:-"1234"}" diff --git a/launch-game.cmd b/launch-game.cmd index 0c5a765..2c98fda 100644 --- a/launch-game.cmd +++ b/launch-game.cmd @@ -1,10 +1,16 @@ @echo off +setlocal EnableDelayedExpansion title OpenRA + FOR /F "tokens=1,2 delims==" %%A IN (mod.config) DO (set %%A=%%B) if exist user.config (FOR /F "tokens=1,2 delims==" %%A IN (user.config) DO (set %%A=%%B)) set TEMPLATE_LAUNCHER=%0 set MOD_SEARCH_PATHS=%~dp0mods,./mods +if "!MOD_ID!" == "" goto badconfig +if "!ENGINE_VERSION!" == "" goto badconfig +if "!ENGINE_DIRECTORY!" == "" goto badconfig + set TEMPLATE_DIR=%CD% if not exist %ENGINE_DIRECTORY%\OpenRA.Game.exe goto noengine >nul find %ENGINE_VERSION% %ENGINE_DIRECTORY%\VERSION || goto noengine @@ -23,6 +29,13 @@ echo Run `make all` in the mod directory to fetch and build the required files, pause exit /b +:badconfig +echo Required mod.config variables are missing. +echo Ensure that MOD_ID ENGINE_VERSION and ENGINE_DIRECTORY are +echo defined in your mod.config (or user.config) and try again. +pause +exit /b + :crashdialog echo ---------------------------------------- echo OpenRA has encountered a fatal error. diff --git a/launch-game.sh b/launch-game.sh index 4fc181f..86381e1 100755 --- a/launch-game.sh +++ b/launch-game.sh @@ -4,6 +4,18 @@ set -e command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } command -v mono >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires mono."; exit 1; } +require_variables() { + missing="" + for i in "$@"; do + eval check="\$$i" + [ -z "${check}" ] && missing="${missing} ${i}\n" + done + if [ ! -z "${missing}" ]; then + echo "Required mod.config variables are missing:\n${missing}Repair your mod.config (or user.config) and try again." + exit 1 + fi +} + TEMPLATE_LAUNCHER=$(python -c "import os; print(os.path.realpath('$0'))") TEMPLATE_ROOT=$(dirname "${TEMPLATE_LAUNCHER}") MOD_SEARCH_PATHS="${TEMPLATE_ROOT}/mods,./mods" @@ -16,6 +28,8 @@ if [ -f "${TEMPLATE_ROOT}/user.config" ]; then . "${TEMPLATE_ROOT}/user.config" fi +require_variables "MOD_ID" "ENGINE_VERSION" "ENGINE_DIRECTORY" + cd "${TEMPLATE_ROOT}" if [ ! -f "${ENGINE_DIRECTORY}/OpenRA.Game.exe" ] || [ "$(cat "${ENGINE_DIRECTORY}/VERSION")" != "${ENGINE_VERSION}" ]; then echo "Required engine files not found." diff --git a/make.ps1 b/make.ps1 index a56b23c..e279c62 100644 --- a/make.ps1 +++ b/make.ps1 @@ -228,6 +228,27 @@ function ParseConfigFile($fileName) ReadConfigLine $line $name } } + + $missing = @() + foreach ($name in $names) + { + if (!([System.Environment]::GetEnvironmentVariable($name))) + { + $missing += $name + } + } + + if ($missing) + { + echo "Required mod.config variables are missing:" + foreach ($m in $missing) + { + echo " $m" + } + echo "Repair your mod.config (or user.config) and try again." + WaitForInput + exit + } } ############################################################### diff --git a/packaging/linux/buildpackage.sh b/packaging/linux/buildpackage.sh index c281225..57b4674 100755 --- a/packaging/linux/buildpackage.sh +++ b/packaging/linux/buildpackage.sh @@ -7,6 +7,18 @@ command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template require command -v tar >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires tar."; exit 1; } command -v curl >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires curl."; exit 1; } +require_variables() { + missing="" + for i in "$@"; do + eval check="\$$i" + [ -z "${check}" ] && missing="${missing} ${i}\n" + done + if [ ! -z "${missing}" ]; then + echo "Required mod.config variables are missing:\n${missing}Repair your mod.config (or user.config) and try again." + exit 1 + fi +} + if [ $# -eq "0" ]; then echo "Usage: `basename $0` version [outputdir]" exit 1 @@ -23,6 +35,10 @@ if [ -f "${TEMPLATE_ROOT}/user.config" ]; then . "${TEMPLATE_ROOT}/user.config" fi +require_variables "MOD_ID" "ENGINE_DIRECTORY" "PACKAGING_DISPLAY_NAME" "PACKAGING_INSTALLER_NAME" \ + "PACKAGING_APPIMAGE_DEPENDENCIES_TAG" "PACKAGING_APPIMAGE_DEPENDENCIES_SOURCE" "PACKAGING_APPIMAGE_DEPENDENCIES_TEMP_ARCHIVE_NAME" \ + "PACKAGING_FAQ_URL" + TAG="$1" if [ $# -eq "1" ]; then OUTPUTDIR=$(python -c "import os; print(os.path.realpath('.'))") diff --git a/packaging/osx/buildpackage.sh b/packaging/osx/buildpackage.sh index cea9a6f..7c8a623 100755 --- a/packaging/osx/buildpackage.sh +++ b/packaging/osx/buildpackage.sh @@ -6,6 +6,18 @@ command -v make >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } command -v curl >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires curl."; exit 1; } +require_variables() { + missing="" + for i in "$@"; do + eval check="\$$i" + [ -z "${check}" ] && missing="${missing} ${i}\n" + done + if [ ! -z "${missing}" ]; then + echo "Required mod.config variables are missing:\n${missing}Repair your mod.config (or user.config) and try again." + exit 1 + fi +} + if [ $# -eq "0" ]; then echo "Usage: `basename $0` version [outputdir]" exit 1 @@ -22,6 +34,10 @@ if [ -f "${TEMPLATE_ROOT}/user.config" ]; then . "${TEMPLATE_ROOT}/user.config" fi +require_variables "MOD_ID" "ENGINE_DIRECTORY" "PACKAGING_DISPLAY_NAME" "PACKAGING_INSTALLER_NAME" \ + "PACKAGING_OSX_LAUNCHER_TAG" "PACKAGING_OSX_LAUNCHER_SOURCE" "PACKAGING_OSX_LAUNCHER_TEMP_ARCHIVE_NAME" \ + "PACKAGING_FAQ_URL" + TAG="$1" if [ $# -eq "1" ]; then OUTPUTDIR=$(python -c "import os; print(os.path.realpath('.'))") diff --git a/packaging/windows/buildpackage.sh b/packaging/windows/buildpackage.sh index 92deb68..9ff3489 100755 --- a/packaging/windows/buildpackage.sh +++ b/packaging/windows/buildpackage.sh @@ -4,6 +4,18 @@ set -e command -v curl >/dev/null 2>&1 || { echo >&2 "Windows packaging requires curl."; exit 1; } command -v makensis >/dev/null 2>&1 || { echo >&2 "Windows packaging requires makensis."; exit 1; } +require_variables() { + missing="" + for i in "$@"; do + eval check="\$$i" + [ -z "${check}" ] && missing="${missing} ${i}\n" + done + if [ ! -z "${missing}" ]; then + echo "Required mod.config variables are missing:\n${missing}Repair your mod.config (or user.config) and try again." + exit 1 + fi +} + if [ $# -eq "0" ]; then echo "Usage: `basename $0` version [outputdir]" exit 1 @@ -20,6 +32,10 @@ if [ -f "${TEMPLATE_ROOT}/user.config" ]; then . "${TEMPLATE_ROOT}/user.config" fi +require_variables "MOD_ID" "ENGINE_DIRECTORY" "PACKAGING_DISPLAY_NAME" "PACKAGING_INSTALLER_NAME" \ + "PACKAGING_WINDOWS_LAUNCHER_NAME" "PACKAGING_WINDOWS_REGISTRY_KEY" "PACKAGING_WINDOWS_INSTALL_DIR_NAME" \ + "PACKAGING_FAQ_URL" "PACKAGING_WEBSITE_URL" "PACKAGING_AUTHORS" + TAG="$1" if [ $# -eq "1" ]; then OUTPUTDIR=$(python -c "import os; print(os.path.realpath('.'))") diff --git a/utility.cmd b/utility.cmd index 6c51b06..0a9eee3 100644 --- a/utility.cmd +++ b/utility.cmd @@ -1,9 +1,14 @@ @echo off +setlocal EnableDelayedExpansion FOR /F "tokens=1,2 delims==" %%A IN (mod.config) DO (set %%A=%%B) if exist user.config (FOR /F "tokens=1,2 delims==" %%A IN (user.config) DO (set %%A=%%B)) set MOD_SEARCH_PATHS=%~dp0mods,./mods +if "!MOD_ID!" == "" goto badconfig +if "!ENGINE_VERSION!" == "" goto badconfig +if "!ENGINE_DIRECTORY!" == "" goto badconfig + title OpenRA.Utility.exe %MOD_ID% set TEMPLATE_DIR=%CD% @@ -32,4 +37,11 @@ goto loop echo Required engine files not found. echo Run `make all` in the mod directory to fetch and build the required files, then try again. pause +exit /b + +:badconfig +echo Required mod.config variables are missing. +echo Ensure that MOD_ID ENGINE_VERSION and ENGINE_DIRECTORY are +echo defined in your mod.config (or user.config) and try again. +pause exit /b \ No newline at end of file diff --git a/utility.sh b/utility.sh index c22a5db..b649e7b 100755 --- a/utility.sh +++ b/utility.sh @@ -8,6 +8,18 @@ command -v make >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires command -v python >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires python."; exit 1; } command -v mono >/dev/null 2>&1 || { echo >&2 "The OpenRA mod template requires mono."; exit 1; } +require_variables() { + missing="" + for i in "$@"; do + eval check="\$$i" + [ -z "${check}" ] && missing="${missing} ${i}\n" + done + if [ ! -z "${missing}" ]; then + echo "Required mod.config variables are missing:\n${missing}Repair your mod.config (or user.config) and try again." + exit 1 + fi +} + TEMPLATE_LAUNCHER=$(python -c "import os; print(os.path.realpath('$0'))") TEMPLATE_ROOT=$(dirname "${TEMPLATE_LAUNCHER}") MOD_SEARCH_PATHS="${TEMPLATE_ROOT}/mods,./mods" @@ -20,6 +32,8 @@ if [ -f "${TEMPLATE_ROOT}/user.config" ]; then . "${TEMPLATE_ROOT}/user.config" fi +require_variables "MOD_ID" "ENGINE_VERSION" "ENGINE_DIRECTORY" + LAUNCH_MOD="${Mod:-"${MOD_ID}"}" cd "${TEMPLATE_ROOT}"