diff --git a/scripts/install_db.sh b/scripts/install_db.sh index bc9cb2d..e5e5b9a 100755 --- a/scripts/install_db.sh +++ b/scripts/install_db.sh @@ -69,14 +69,20 @@ trap cleanup EXIT usage() { cat < + $0 [PORT] Przykłady: + $0 10.11 $0 10.11 33033 $0 11.4 3020 $0 11.8 3021 Dozwolone gałęzie MariaDB: 10.11, 11.4, 11.8. + +Jeżeli PORT zostanie pominięty, przyjmowana jest wartość domyślna 3306. W takim +przypadku skrypt najpierw przenosi natywną instancję MariaDB zarządzaną przez +CustomBuild na inny port (patrz scripts/setup/native_mariadb_port_takeover.sh), +aby zwolnić port 3306 dla alt-mariadb. EOF } @@ -98,19 +104,15 @@ apply_cli_args() { fi if [[ $# -gt 2 ]]; then - usage_error "Podano zbyt wiele argumentów. Oczekiwano: MARIADB_VERSION PORT." + usage_error "Podano zbyt wiele argumentów. Oczekiwano: MARIADB_VERSION [PORT]." fi - if [[ $# -lt 2 ]]; then - usage_error "Podaj wersję MariaDB i port TCP, np. 11.4 3020." - fi - - if [[ $# -ge 1 && -n "${1:-}" ]]; then - MARIADB_VERSION="$1" - fi + MARIADB_VERSION="$1" if [[ $# -ge 2 && -n "${2:-}" ]]; then PORT="$2" + else + PORT="3306" fi MARIADB_DIR="/usr/local/mariadb-$MARIADB_VERSION" diff --git a/tests/install_db_cli_test.sh b/tests/install_db_cli_test.sh index 44a3608..39f6288 100755 --- a/tests/install_db_cli_test.sh +++ b/tests/install_db_cli_test.sh @@ -41,10 +41,20 @@ set -e [ "$NO_ARGS_STATUS" -eq 2 ] || fail "install_db.sh without arguments should exit with status 2, got $NO_ARGS_STATUS" printf '%s\n' "$NO_ARGS_OUTPUT" | grep -Fq 'Użycie:' \ || fail "install_db.sh without arguments does not print usage" -printf '%s\n' "$NO_ARGS_OUTPUT" | grep -Fq ' ' \ - || fail "install_db.sh usage does not show required version and port" +printf '%s\n' "$NO_ARGS_OUTPUT" | grep -Fq ' [PORT]' \ + || fail "install_db.sh usage does not show optional port" if printf '%s\n' "$NO_ARGS_OUTPUT" | grep -Fq 'Ten skrypt musi zostać uruchomiony jako root'; then fail "install_db.sh without arguments reaches root check instead of usage" fi +set +e +ONE_ARG_OUTPUT="$("$SCRIPT" 10.11 2>&1)" +ONE_ARG_STATUS=$? +set -e + +[ "$ONE_ARG_STATUS" -eq 1 ] \ + || fail "install_db.sh with only a version argument should reach the root check (status 1), got $ONE_ARG_STATUS: $ONE_ARG_OUTPUT" +printf '%s\n' "$ONE_ARG_OUTPUT" | grep -Fq 'Ten skrypt musi zostać uruchomiony jako root' \ + || fail "install_db.sh with only a version argument should default PORT to 3306 and reach the root check, got: $ONE_ARG_OUTPUT" + echo "install_db_cli_test: OK"