cc.sh/run.sh code review

This commit is contained in:
JustArchi 2017-10-18 15:03:52 +02:00
parent 00d8804607
commit 944421e47e
2 changed files with 39 additions and 51 deletions

40
cc.sh
View file

@ -1,38 +1,41 @@
#!/bin/bash
set -eu
PROJECT="ArchiSteamFarm"
SOLUTION="ArchiSteamFarm.sln"
CONFIGURATION="Release"
OUT="out/source"
SOLUTION="${PROJECT}.sln"
CONFIGURATION="Release"
PROJECTS=("ArchiSteamFarm")
CLEAN=0
TEST=1
PRINT_USAGE() {
echo "Usage: $0 [--clean] [debug/release]"
exit 1
}
cd "$(dirname "$(readlink -f "$0")")"
for ARG in "$@"; do
case "$ARG" in
release|Release) CONFIGURATION="Release" ;;
debug|Debug) CONFIGURATION="Debug" ;;
--clean) CLEAN=1 ;;
*) PRINT_USAGE
--no-test) TEST=0 ;;
*) echo "Usage: $0 [--clean] [--no-test] [debug/release]"; exit 1
esac
done
if ! hash dotnet &>/dev/null; then
if [[ "$TEST" -eq 1 ]]; then
PROJECTS+=("ArchiSteamFarm.Tests")
fi
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
if ! hash dotnet 2>/dev/null; then
echo "ERROR: dotnet CLI tools are not installed!"
exit 1
fi
dotnet --info
cd "$(dirname "$(readlink -f "$0")")"
if [[ -d ".git" ]] && hash git &>/dev/null; then
if [[ -d ".git" ]] && hash git 2>/dev/null; then
git pull || true
fi
@ -42,14 +45,19 @@ if [[ ! -f "$SOLUTION" ]]; then
fi
if [[ "$CLEAN" -eq 1 ]]; then
dotnet clean -c "$CONFIGURATION" -o "$OUT"
rm -rf "ArchiSteamFarm/${OUT}" "ArchiSteamFarm.Tests/${OUT}"
dotnet clean "${PROJECTS[@]}" -c "$CONFIGURATION" -o "$OUT"
for PROJECT in "${PROJECTS[@]}"; do
rm -rf "${PROJECT:?}/${OUT}"
done
fi
dotnet restore
dotnet build "${PROJECTS[@]}" -c "$CONFIGURATION" -o "$OUT" --no-restore /nologo
dotnet build -c "$CONFIGURATION" -o "$OUT" --no-restore /nologo
dotnet test ArchiSteamFarm.Tests -c "$CONFIGURATION" -o "$OUT" --no-build --no-restore
if [[ "$TEST" -eq 1 ]]; then
dotnet test ArchiSteamFarm.Tests -c "$CONFIGURATION" -o "$OUT" --no-build --no-restore
fi
echo
echo "Compilation finished successfully! :)"

50
run.sh
View file

@ -4,49 +4,29 @@ set -eu
PROJECT="ArchiSteamFarm"
OUT="out/source"
BINARY="${PROJECT}/${OUT}/${PROJECT}.dll"
cd "$(dirname "$(readlink -f "$0")")"
ASF_ARGS=("")
UNTIL_CLEAN_EXIT=0
if [[ -z "${ASF_ARGS-}" ]]; then
ASF_ARGS=""
fi
PRINT_USAGE() {
echo "Usage: $0 [--until-clean-exit] [--cryptkey=] [--path=] [--server]"
exit 1
}
ASF_ARGS+=" $*"
for ARG in "$@"; do
case "$ARG" in
--cryptkey=*) ASF_ARGS+=("$ARG") ;;
--path=*) ASF_ARGS+=("$ARG") ;;
--server) ASF_ARGS+=("$ARG") ;;
--until-clean-exit) UNTIL_CLEAN_EXIT=1 ;;
*) PRINT_USAGE
esac
done
# Kill underlying ASF process on shell process exit
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
if ! hash dotnet &>/dev/null; then
if ! hash dotnet 2>/dev/null; then
echo "ERROR: dotnet CLI tools are not installed!"
exit 1
fi
dotnet --info
cd "$(dirname "$(readlink -f "$0")")"
if [[ ! -f "$BINARY" ]]; then
echo "ERROR: $BINARY could not be found!"
exit 1
if grep -Eq '"Headless":\s+?true' "${PROJECT}/${OUT}/config/ASF.json"; then
# We're running ASF in headless mode so we don't need STDIN
dotnet exec "${PROJECT}/${OUT}/${PROJECT}.dll" $ASF_ARGS & # Start ASF in the background, trap will work properly due to non-blocking call
wait $! # This will forward dotnet error code, set -e will abort the script if it's non-zero
else
# We're running ASF in non-headless mode, so we need STDIN to be operative
dotnet exec "${PROJECT}/${OUT}/${PROJECT}.dll" $ASF_ARGS # Start ASF in the foreground, trap won't work until process exit
fi
if [[ "$UNTIL_CLEAN_EXIT" -eq 0 ]]; then
dotnet exec "$BINARY" "${ASF_ARGS[@]}"
exit $? # In this case $? can only be 0 because otherwise set -e terminates the script
fi
while [[ -f "$BINARY" ]]; do
if dotnet exec "$BINARY" "${ASF_ARGS[@]}"; then
break
fi
sleep 1
done