Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:

- name: Run checks
run: |
bash -n mcserver-kit new-minecraft-server.sh setup.sh install.sh uninstall.sh tests/run-tests.sh
bash -n mcserver-kit new-minecraft-server.sh setup.sh reset.sh install.sh uninstall.sh tests/run-tests.sh
python3 -m py_compile scripts/detect-world-version.py scripts/validate-locales.py
python3 scripts/validate-locales.py
shellcheck -x mcserver-kit new-minecraft-server.sh setup.sh install.sh uninstall.sh tests/run-tests.sh
shellcheck -x mcserver-kit new-minecraft-server.sh setup.sh reset.sh install.sh uninstall.sh tests/run-tests.sh
bash tests/run-tests.sh

- name: Build release archive
Expand All @@ -35,6 +35,7 @@ jobs:
new-minecraft-server.sh \
mcserver-kit \
setup.sh \
reset.sh \
install.sh \
uninstall.sh \
config.example.yml \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/shell-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: sudo apt-get update && sudo apt-get install --yes shellcheck zip unzip

- name: Check Bash syntax
run: bash -n mcserver-kit new-minecraft-server.sh setup.sh install.sh uninstall.sh tests/run-tests.sh
run: bash -n mcserver-kit new-minecraft-server.sh setup.sh reset.sh install.sh uninstall.sh tests/run-tests.sh

- name: Check Python syntax
run: python3 -m py_compile scripts/detect-world-version.py scripts/validate-locales.py
Expand All @@ -33,7 +33,7 @@ jobs:
run: python3 scripts/validate-locales.py

- name: Run ShellCheck
run: shellcheck -x mcserver-kit new-minecraft-server.sh setup.sh install.sh uninstall.sh tests/run-tests.sh
run: shellcheck -x mcserver-kit new-minecraft-server.sh setup.sh reset.sh install.sh uninstall.sh tests/run-tests.sh

- name: Run specification tests
run: bash tests/run-tests.sh
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ main() {
install -m 755 "${source_dir}/new-minecraft-server.sh" "${INSTALL_DIR}/new-minecraft-server.sh"
install -m 755 "${source_dir}/mcserver-kit" "${INSTALL_DIR}/mcserver-kit"
install -m 755 "${source_dir}/setup.sh" "${INSTALL_DIR}/setup.sh"
install -m 755 "${source_dir}/reset.sh" "${INSTALL_DIR}/reset.sh"
install -m 755 "${source_dir}/uninstall.sh" "${INSTALL_DIR}/uninstall.sh"
install -m 644 "${source_dir}/config.example.yml" "${INSTALL_DIR}/config.example.yml"
install -m 644 "${source_dir}/compose-example.yaml" "${INSTALL_DIR}/compose-example.yaml"
Expand Down
9 changes: 8 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"cli.commands": "Commands:",
"cli.create": "Create a new server interactively (default command)",
"cli.setup": "Configure Owner, EULA, MCID templates, Playit, and defaults",
"cli.reset": "Delete settings and MCID templates but keep servers and the program",
"cli.uninstall": "Remove the program but keep settings and MCID templates",
"cli.uninstall_purge": "Remove the program, settings, and MCID templates",
"cli.help": "Show this help",
Expand Down Expand Up @@ -31,5 +32,11 @@
"input.yes_no": "Please enter y or n.\n",
"input.mcid": "MCID",
"input.mcid_rules": "MCID must be 3–16 letters, numbers, or underscores.\n",
"input.one_per_line": "Enter one per line and press Enter on an empty line to finish.\n"
"input.one_per_line": "Enter one per line and press Enter on an empty line to finish.\n",
"reset.usage": "Usage: mcserver-kit reset [--yes]\n",
"reset.unsafe": "Refusing to reset an unsafe path.\n",
"reset.summary": "The following settings will be deleted:\n %s\n %s\nCreated servers, worlds, and the installed program will not be deleted.\n",
"reset.confirm": "Continue? [y/N]: ",
"reset.cancelled": "Reset cancelled.\n",
"reset.done": "Settings and MCID templates were deleted. Run mcserver-kit setup to configure them again.\n"
}
9 changes: 8 additions & 1 deletion locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"cli.commands": "コマンド:",
"cli.create": "対話形式で新しいサーバーを作成します(省略時の動作)",
"cli.setup": "Owner、EULA、MCIDテンプレート、Playit等を設定します",
"cli.reset": "設定とMCIDテンプレートだけを削除し、本体とサーバーは保持します",
"cli.uninstall": "本体を削除し、設定とMCIDテンプレートは保持します",
"cli.uninstall_purge": "本体、設定、MCIDテンプレートをすべて削除します",
"cli.help": "このヘルプを表示します",
Expand Down Expand Up @@ -31,5 +32,11 @@
"input.yes_no": "yまたはnを入力してください。\n",
"input.mcid": "MCID",
"input.mcid_rules": "MCIDは英数字と_の3~16文字です。\n",
"input.one_per_line": "1行に1つ入力し、空Enterで終了します。\n"
"input.one_per_line": "1行に1つ入力し、空Enterで終了します。\n",
"reset.usage": "使い方: mcserver-kit reset [--yes]\n",
"reset.unsafe": "危険なパスが指定されているためリセットを拒否しました。\n",
"reset.summary": "次の設定を削除します:\n %s\n %s\n作成済みサーバー、ワールド、インストール済み本体は削除しません。\n",
"reset.confirm": "続行しますか? [y/N]: ",
"reset.cancelled": "リセットをキャンセルしました。\n",
"reset.done": "設定とMCIDテンプレートを削除しました。mcserver-kit setupで再設定できます。\n"
}
6 changes: 6 additions & 0 deletions mcserver-kit
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ show_help() {
cat <<HELP
mcserver-kit [create]
mcserver-kit setup
mcserver-kit reset [--yes]
mcserver-kit uninstall [--purge]
mcserver-kit --lang <code> [command]
mcserver-kit --help
Expand All @@ -36,6 +37,7 @@ HELP
printf '\n'
printf ' %-20s %s\n' create "$(tr cli.create)"
printf ' %-20s %s\n' setup "$(tr cli.setup)"
printf ' %-20s %s\n' reset "$(tr cli.reset)"
printf ' %-20s %s\n' uninstall "$(tr cli.uninstall)"
printf ' %-20s %s\n' 'uninstall --purge' "$(tr cli.uninstall_purge)"
printf ' %-20s %s\n' help "$(tr cli.help)"
Expand All @@ -58,6 +60,10 @@ case "$command_name" in
shift
exec "${SCRIPT_DIR}/setup.sh" "$@"
;;
reset)
shift
exec "${SCRIPT_DIR}/reset.sh" "$@"
;;
uninstall)
shift
exec "${SCRIPT_DIR}/uninstall.sh" "$@"
Expand Down
58 changes: 58 additions & 0 deletions reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
# `tr` is the repository translation helper, and load_messages takes no CLI args.
# shellcheck disable=SC2020,SC2119
set -Eeuo pipefail

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_FILE="${MCSERVER_KIT_CONFIG:-${HOME}/.config/mcserver-compose-kit/config.yml}"
TEMPLATE_DIR="${MCSERVER_KIT_MCID_TEMPLATE_DIR:-${HOME}/.config/mcserver-compose-kit/mcid-templates}"

# shellcheck source=scripts/i18n.sh
source "${SCRIPT_DIR}/scripts/i18n.sh"
load_messages

resolve_parent() {
local path="$1"
local parent
parent="$(dirname -- "$path")"
if [[ -d "$parent" ]]; then
(cd -- "$parent" && pwd)
else
printf '%s' "$parent"
fi
}

confirm=false
case "${1-}" in
'') ;;
--yes | -y) confirm=true ;;
*)
tr reset.usage >&2
exit 2
;;
esac

config_parent="$(resolve_parent "$CONFIG_FILE")"
template_parent="$(resolve_parent "$TEMPLATE_DIR")"
for protected_path in '' / "$HOME"; do
if [[ "$config_parent" == "$protected_path" || "$template_parent" == "$protected_path" ]]; then
tr reset.unsafe >&2
exit 1
fi
done

tr reset.summary "$CONFIG_FILE" "$TEMPLATE_DIR"
if [[ "$confirm" != 'true' ]]; then
read -r -p "$(tr reset.confirm)" answer
case "${answer,,}" in
y | yes) ;;
*)
tr reset.cancelled
exit 0
;;
esac
fi

rm -f -- "$CONFIG_FILE"
rm -rf -- "$TEMPLATE_DIR"
tr reset.done
22 changes: 22 additions & 0 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,27 @@ test_setup_command() {
assert_equal 'absent' "$(! grep -q 'playit-secret-for-test' "$setup_log" && printf absent)" 'setup does not print the Playit secret'
}

test_reset_command() {
local temp_dir="$1"
local config_dir="${temp_dir}/reset/config"
local config_file="${config_dir}/config.yml"
local template_dir="${config_dir}/mcid-templates"
local server_dir="${temp_dir}/reset/servers/keep-me"

mkdir -p "$template_dir" "$server_dir"
: >"$config_file"
: >"${template_dir}/default.txt"
: >"${server_dir}/level.dat"

MCSERVER_KIT_CONFIG="$config_file" \
MCSERVER_KIT_MCID_TEMPLATE_DIR="$template_dir" \
bash "${REPO_ROOT}/mcserver-kit" --lang en reset --yes >/dev/null

assert_equal 'absent' "$([[ ! -f "$config_file" ]] && printf absent)" 'reset removes config.yml'
assert_equal 'absent' "$([[ ! -d "$template_dir" ]] && printf absent)" 'reset removes MCID templates'
assert_equal 'present' "$([[ -f "${server_dir}/level.dat" ]] && printf present)" 'reset preserves created servers and worlds'
}

main() {
TEST_TEMP_DIR="$(mktemp -d)"
trap cleanup EXIT
Expand All @@ -302,6 +323,7 @@ main() {
test_creation_flow "$TEST_TEMP_DIR"
test_local_installation "$TEST_TEMP_DIR"
test_setup_command "$TEST_TEMP_DIR"
test_reset_command "$TEST_TEMP_DIR"

printf 'PASS: %d specification tests, %d skipped\n' "$tests_run" "$tests_skipped"
}
Expand Down
Loading