#!/bin/sh # Installs quest sash (README.md): run on the server from this directory, then restart the game cores. # Adds pc.open_sash to quest_functions (needs the sash game binary; an older core would fail the call, not the boot), # compiles only sash.quest in an isolated staging directory and copies its objects into the live quest tree. set -eu SERVER=${SERVER:-/usr/metin2/server} LOCALE=${LOCALE:-newcibn} QUEST="$SERVER/share/locale/$LOCALE/quest" HERE=$(cd "$(dirname "$0")" && pwd) BACKUP=/root/backup-sash/$(date +%Y%m%d-%H%M%S) export LC_ALL=C mkdir -p "$BACKUP/stage" cp -p "$QUEST/quest_functions" "$QUEST/locale_list" "$BACKUP/" [ -f "$QUEST/sash.quest" ] && cp -p "$QUEST/sash.quest" "$BACKUP/" echo "backup: $BACKUP" # A GBK trail byte 0x5C would be a backslash to qc. iconv -f UTF-8 -t GBK "$HERE/sash.quest" > "$BACKUP/sash.gbk" if grep -q '\\' "$BACKUP/sash.gbk"; then echo "sash.quest: backslash byte in GBK" >&2; exit 1; fi cp "$QUEST/quest_functions" "$BACKUP/stage/" grep -qx 'pc.open_sash' "$BACKUP/stage/quest_functions" || echo 'pc.open_sash' >> "$BACKUP/stage/quest_functions" cp "$BACKUP/sash.gbk" "$BACKUP/stage/sash.quest" (cd "$BACKUP/stage" && "$QUEST/qc" sash.quest) > "$BACKUP/qc.log" 2>&1 || { cat "$BACKUP/qc.log" >&2; exit 1; } test -s "$BACKUP/stage/object/state/sash" [ "$(cd "$BACKUP/stage/object/20016/chat" && ls | grep -c '^sash\.')" -eq 9 ] || { echo "unexpected qc output" >&2; exit 1; } cat "$BACKUP/stage/quest_functions" > "$QUEST/quest_functions" cat "$BACKUP/sash.gbk" > "$QUEST/sash.quest" grep -qx 'sash.quest' "$QUEST/locale_list" || echo 'sash.quest' >> "$QUEST/locale_list" (cd "$BACKUP/stage/object" && find . -type f) | while read -r f; do mkdir -p "$QUEST/object/$(dirname "$f")" cp "$BACKUP/stage/object/$f" "$QUEST/object/$f" done echo "done; restart the game cores"