feat: make install_db.sh's PORT argument optional, defaulting to 3306
This commit is contained in:
+10
-8
@@ -69,14 +69,20 @@ trap cleanup EXIT
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Użycie:
|
||||
$0 <MARIADB_VERSION> <PORT>
|
||||
$0 <MARIADB_VERSION> [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
|
||||
|
||||
if [[ $# -ge 2 && -n "${2:-}" ]]; then
|
||||
PORT="$2"
|
||||
else
|
||||
PORT="3306"
|
||||
fi
|
||||
|
||||
MARIADB_DIR="/usr/local/mariadb-$MARIADB_VERSION"
|
||||
|
||||
@@ -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 '<MARIADB_VERSION> <PORT>' \
|
||||
|| fail "install_db.sh usage does not show required version and port"
|
||||
printf '%s\n' "$NO_ARGS_OUTPUT" | grep -Fq '<MARIADB_VERSION> [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"
|
||||
|
||||
Reference in New Issue
Block a user