feat : sudoers bug (WIP)
This commit is contained in:
@@ -70,7 +70,7 @@ if ! require_cmd "$SUDO_BIN"; then
|
||||
fail "sudo absent sur la cible"
|
||||
fi
|
||||
|
||||
if ! "$SUDO_BIN" -n true >/dev/null 2>&1; then
|
||||
if ! "$SUDO_BIN" -n /usr/bin/true >/dev/null 2>&1; then
|
||||
fail "sudo non interactif indisponible pour l'utilisateur courant"
|
||||
fi
|
||||
|
||||
@@ -78,12 +78,15 @@ if [[ ! "$PGPORT" =~ ^[0-9]+$ ]]; then
|
||||
fail "PGPORT invalide : $PGPORT"
|
||||
fi
|
||||
|
||||
POSTGRES_INSTALLED="no"
|
||||
|
||||
if ! require_cmd psql || ! require_cmd pg_restore || ! require_cmd createdb || ! require_cmd dropdb; then
|
||||
[[ "${AUTO_INSTALL_POSTGRES,,}" == "yes" ]] || fail "PostgreSQL absent et AUTO_INSTALL_POSTGRES=no"
|
||||
|
||||
log "PostgreSQL absent : installation en cours..."
|
||||
"$SUDO_BIN" -n apt update >/dev/null 2>&1 || fail "échec de apt update"
|
||||
"$SUDO_BIN" -n apt install -y $POSTGRES_PACKAGE_LIST >/dev/null 2>&1 || fail "échec de l'installation PostgreSQL"
|
||||
POSTGRES_INSTALLED="yes"
|
||||
log "Installation PostgreSQL terminée."
|
||||
else
|
||||
log "PostgreSQL déjà installé."
|
||||
@@ -98,20 +101,20 @@ fi
|
||||
|
||||
log "Vérification de la disponibilité de PostgreSQL..."
|
||||
for _ in {1..20}; do
|
||||
if "$SUDO_BIN" -n -u postgres psql -d postgres -c "SELECT 1;" >/dev/null 2>&1; then
|
||||
if "$SUDO_BIN" -n -u postgres /usr/bin/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 psql -d postgres -c "SELECT 1;" >/dev/null 2>&1; then
|
||||
fail "PostgreSQL ne répond pas correctement"
|
||||
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"
|
||||
fi
|
||||
|
||||
if [[ "${AUTO_CREATE_PGUSER,,}" == "yes" ]]; then
|
||||
ROLE_EXISTS="$(
|
||||
"$SUDO_BIN" -n -u postgres psql -d postgres -tAc \
|
||||
"$SUDO_BIN" -n -u postgres /usr/bin/psql -d postgres -tAc \
|
||||
"SELECT 1 FROM pg_roles WHERE rolname='${PGUSER//\'/\'\'}'" 2>/dev/null || true
|
||||
)"
|
||||
|
||||
@@ -123,7 +126,7 @@ if [[ "${AUTO_CREATE_PGUSER,,}" == "yes" ]]; then
|
||||
ROLE_ATTRIBUTES="LOGIN SUPERUSER CREATEDB CREATEROLE"
|
||||
fi
|
||||
|
||||
"$SUDO_BIN" -n -u postgres psql -d postgres -c \
|
||||
"$SUDO_BIN" -n -u postgres /usr/bin/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}"
|
||||
|
||||
@@ -133,10 +136,6 @@ if [[ "${AUTO_CREATE_PGUSER,,}" == "yes" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! "$SUDO_BIN" -n -u postgres true >/dev/null 2>&1; then
|
||||
fail "sudo -n -u postgres indisponible"
|
||||
fi
|
||||
|
||||
if ! psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d postgres -c "SELECT 1;" >/dev/null 2>&1; then
|
||||
fail "connexion PostgreSQL locale impossible avec PGUSER=${PGUSER}"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user