Tinyboss

Untitled

Nov 19th, 2024
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. set -o pipefail
  2. run() {
  3. test_bin() {
  4. command -v "$1" > /dev/null
  5. }
  6. get_realpath() {
  7. echo "$(cd "$(dirname "$1")"; pwd -P)/$(basename "$1")"
  8. }
  9. : "${HOST:="https://factoriobox.1au.us"}"
  10. : "${BENCH_TICKS:=1000}"
  11. : "${BENCH_RUNS:=5}"
  12. if [ -z "$FACTORIO_BIN" ]; then
  13. FACTORIO_BIN=bin/x64/factorio
  14. if ! test_bin "$FACTORIO_BIN"; then
  15. FACTORIO_BIN=./factorio;
  16. if ! test_bin "$FACTORIO_BIN"; then
  17. FACTORIO_BIN=factorio;
  18. if ! test_bin "$FACTORIO_BIN"; then
  19. FACTORIO_BIN="$HOME/.local/share/Steam/steamapps/common/Factorio/bin/x64/factorio";
  20. fi
  21. fi
  22. fi
  23. fi
  24. if ! test_bin "$FACTORIO_BIN"; then
  25. echo "Could not locate the Factorio binary. Validate it is in your path, installed via Steam, or CD to it."
  26. return 1
  27. fi
  28. if ! FACTORIO_VERSION=$("$FACTORIO_BIN" --version | head -n 1); then
  29. echo "Factorio exited with non-zero exit code"
  30. return 1
  31. fi
  32. echo "Found $FACTORIO_VERSION at $(get_realpath "$FACTORIO_BIN")"
  33. FACTORIO_VERSION_SHORT=$(echo "$FACTORIO_VERSION" | awk '{print $2}')
  34. : "${URL:="$HOST/map-version/$FACTORIO_VERSION_SHORT"}"
  35. if [ -z "$MAP" ]; then
  36. MAP=$(mktemp)
  37. echo "Downloading map..."
  38. curl --progress-bar -o "$MAP" "$URL"
  39. fi
  40. MAP_HASH=$(sha256sum "$MAP" | awk '{print $1}')
  41. echo "Running benchmark..."
  42. exec 5>&1
  43. if ! FACTORIO_LOG=$(gstdbuf -oL "$FACTORIO_BIN" --mod-directory /dev/null --benchmark "$MAP" --benchmark-ticks $BENCH_TICKS --benchmark-runs $BENCH_RUNS --benchmark-verbose all --benchmark-sanitize | tee >(grep Performed >&5)) ||
  44. ! UPS=$(awk -v ticks="$BENCH_TICKS" 'BEGIN{min = -1} $1=="Performed"{if (min == -1 || $5 < min) min = $5} END{print 1000 * ticks / min}' <<< $FACTORIO_LOG); then
  45. echo Benchmark failed
  46. echo "$FACTORIO_LOG"
  47. return 1
  48. fi
  49. echo "Map benchmarked at $UPS UPS"
  50. echo "Share your benchmark at: $HOST/result/"$(curl --progress-bar --data-binary @- <<< "v2 linux
  51. $MAP_HASH
  52. $FACTORIO_VERSION
  53. $BENCH_TICKS
  54. $BENCH_RUNS
  55. $(grep -Po 'Performed \d+ updates in \d+\.\d+ ms' <<< $FACTORIO_LOG)
  56. $(grep "^[^ ]" <<< $FACTORIO_LOG)
  57. $CPU
  58. $MEMORY
  59. $(LC_ALL=C lscpu)" -X POST -s -S "$HOST/result")
  60. }
  61. run
Add Comment
Please, Sign In to add comment