From 89bc806c825a71a2f32deb0a0d67cfc6f826986b Mon Sep 17 00:00:00 2001 From: kimzuni Date: Sat, 6 Apr 2024 14:42:56 +0900 Subject: [PATCH] README, etc --- .github/workflows/security.yml | 1 + docs/en/README.md | 17 ++++++++++ docs/kr/README.md | 17 ++++++++++ scripts/helper_functions.sh | 58 ++++++++++++++++++++++++++++++---- 4 files changed, 87 insertions(+), 6 deletions(-) diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index bfaf5b4..d7ca614 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -8,6 +8,7 @@ on: # yamllint disable-line rule:truthy push: branches: - main + - dev jobs: container-scanning: diff --git a/docs/en/README.md b/docs/en/README.md index c5d74e6..704aef7 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -181,6 +181,23 @@ docker run -d \ kimzuni/longvinter-docker-server:latest ``` +### Update the Container + +If you are running the server first, please stop: + +```bash +docker stop longvinter-server +docker rm longvinter-server +``` + +Next, remove the installed image: + +```bash +docker rmi $(docker images | grep -E ^"(ghcr.io\/)?kimzuni/longvinter-docker-server" | awk '{print $3}') +``` + +Finally, run the [Docker Compose](#docker-compose) or [Docker Run](#docker-run) with the `latest` tag. + ### Running without root This is only for advanced users. diff --git a/docs/kr/README.md b/docs/kr/README.md index 61baa59..1e4a6e6 100644 --- a/docs/kr/README.md +++ b/docs/kr/README.md @@ -178,6 +178,23 @@ docker run -d \ kimzuni/longvinter-docker-server:latest ``` +### 컨테이너 업데이트 방법 + +먼저 서버를 실행 중이라면 아래 명령어로 서버를 중지해 주세요. + +```bash +docker stop longvinter-server +docker rm longvinter-server +``` + +그리고 아래 명령어를 실행햐여 설치된 이미지를 제거합니다. + +```bash +docker rmi $(docker images | grep -E ^"(ghcr.io\/)?kimzuni/longvinter-docker-server" | awk '{print $3}') +``` + +마지막으로 `latest` 태그를 이용하여 [Docker Compose](#docker-compose) 또는 [Docker Run](#docker-run)을 실행하면 최신 버전의 컨테이너를 사용할 수 있습니다. + ### root 없이 실행하기 고급 유저를 위한 기능입니다. diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 0496a3e..104996b 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -142,10 +142,11 @@ container_version_check() { if [ "${current_version}" != "${latest_version}" ]; then LogWarn "New version available: ${latest_version}" - LogWarn "Learn how to update the container: https://github.com/kimzuni/longvinter-docker-server#update-the-container" + LogWarn "Learn how to update the container:" + LogWarn " - English : https://github.com/kimzuni/longvinter-docker-server/tree/main/docs/en/#update-the-container" + LogWarn " - 한국어 : https://github.com/kimzuni/longvinter-docker-server/tree/main/docs/kr/#컨테이너-업데이트-방법" else LogSuccess "The container is up to date!" - fi } @@ -161,15 +162,60 @@ get_latest_version() { # Use it when you have to wait for it to be saved automatically because it does not support RCON. wait_save() { - local path log + local path old_path new_path + local num old_num adminpanel + + old_path=$(last_savefile) + old_num=$(wc -l 2> /dev/null < "$old_path") while path=$(inotifywait -q -e modify -r "$SERVER_LOG_DIR" | sed "s/ MODIFY //g"); do - log=$(tail -1 "$path") - if [[ "$log" =~ ^\[[a-zA-Z]+\ [0-9\ ,:]+\ [AP]M\]\ Game\ saved!$ ]]; then + if [[ "${path##*/}" =~ ^AdminPanelServer-.*\.log$ ]] + then adminpanel=true + else adminpanel=false + fi + + if [ -n "$old_path" ] && num=$(check_save "$old_path" "$old_num"); then + break + elif [ "$adminpanel" = false ]; then + path="$old_path" + elif [ "$old_path" != "$path" ] && num=$(check_save "$path" 0); then break fi + + new_path=$(last_savefile) + if [ "$path" != "$new_path" ] && num=$(check_save "$new_path" 0); then + break + fi + + old_path="$new_path" + old_num="${num:-$old_num}" done } +# Outputs the latest log file among log files where saves are recorded +last_savefile() { + # shellcheck disable=SC2012 + ls -t "$SERVER_LOG_DIR"/AdminPanelServer-*.log 2> /dev/null | head -1 +} + +# Check if there is any saved history in the log file +# And Output the last line number of that file +# Returns 0 if saved +# Returns 1 if unsaved +check_save() { + local path num old_num + path="$1" + old_num="$2" + num=$(wc -l < "$path") + + echo "$num" + + logs=$(tail -$((num - old_num)) "$path") + if echo "$logs" | grep -i ^"\[[a-z]\+ [0-9 ,:]\+ [AP]M\] Game saved!"$ > /dev/null 2>&1; then + return 0 + fi + return 1 +} + Server_Info() { local HTTP URL="$CFG_COMMUNITY_WEBSITE" if ! [[ "$URL" =~ ^https?:// ]] && [ -n "$URL" ]; then @@ -191,4 +237,4 @@ Server_Info() { echo "Max Tent: $CFG_MAX_TENTS" echo "Coop Play: $CFG_COOP_PLAY" echo "Coop Spawn: $CFG_COOP_SPAWN" -} \ No newline at end of file +}