feat : sudoers bug (WIP)
This commit is contained in:
@@ -70,8 +70,12 @@ if ! require_cmd "$SUDO_BIN"; then
|
||||
fail "sudo absent sur la cible"
|
||||
fi
|
||||
|
||||
if ! "$SUDO_BIN" -n /usr/bin/true >/dev/null 2>&1; then
|
||||
fail "sudo non interactif indisponible pour l'utilisateur courant"
|
||||
if ! "$SUDO_BIN" -n /usr/bin/systemctl --version >/dev/null 2>&1; then
|
||||
fail "sudo non interactif indisponible pour systemctl"
|
||||
fi
|
||||
|
||||
if ! "$SUDO_BIN" -n -u postgres /usr/bin/psql -d postgres -c "SELECT 1;" >/dev/null 2>&1; then
|
||||
fail "sudo -n -u postgres indisponible"
|
||||
fi
|
||||
|
||||
if [[ ! "$PGPORT" =~ ^[0-9]+$ ]]; then
|
||||
@@ -101,20 +105,20 @@ fi
|
||||
|
||||
log "Vérification de la disponibilité de PostgreSQL..."
|
||||
for _ in {1..20}; do
|
||||
if "$SUDO_BIN" -n -u postgres /usr/bin/psql -d postgres -c "SELECT 1;" >/dev/null 2>&1; then
|
||||
if "$SUDO_BIN" -n -u postgres psql -d postgres -c "SELECT 1;" >/dev/null 2>&1; then
|
||||
log "PostgreSQL répond correctement."
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if ! "$SUDO_BIN" -n -u postgres /usr/bin/psql -d postgres -c "SELECT 1;" >/dev/null 2>&1; then
|
||||
fail "PostgreSQL ne répond pas correctement ou sudo -u postgres n'autorise pas psql"
|
||||
if ! "$SUDO_BIN" -n -u postgres psql -d postgres -c "SELECT 1;" >/dev/null 2>&1; then
|
||||
fail "PostgreSQL ne répond pas correctement"
|
||||
fi
|
||||
|
||||
if [[ "${AUTO_CREATE_PGUSER,,}" == "yes" ]]; then
|
||||
ROLE_EXISTS="$(
|
||||
"$SUDO_BIN" -n -u postgres /usr/bin/psql -d postgres -tAc \
|
||||
"$SUDO_BIN" -n -u postgres psql -d postgres -tAc \
|
||||
"SELECT 1 FROM pg_roles WHERE rolname='${PGUSER//\'/\'\'}'" 2>/dev/null || true
|
||||
)"
|
||||
|
||||
@@ -126,7 +130,7 @@ if [[ "${AUTO_CREATE_PGUSER,,}" == "yes" ]]; then
|
||||
ROLE_ATTRIBUTES="LOGIN SUPERUSER CREATEDB CREATEROLE"
|
||||
fi
|
||||
|
||||
"$SUDO_BIN" -n -u postgres /usr/bin/psql -d postgres -c \
|
||||
"$SUDO_BIN" -n -u postgres psql -d postgres -c \
|
||||
"CREATE ROLE \"${PGUSER}\" WITH ${ROLE_ATTRIBUTES} PASSWORD '${PGPASSWORD//\'/\'\'}';" \
|
||||
>/dev/null 2>&1 || fail "échec de création du rôle ${PGUSER}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user