Use same shell

This commit is contained in:
Alexandre
2025-02-15 12:11:33 +01:00
parent b4f13c4104
commit d57cd4255b
2 changed files with 42 additions and 43 deletions

View File

@@ -38,5 +38,5 @@
"slug": "postgres", "slug": "postgres",
"udev": true, "udev": true,
"url": "https://github.com/alexbelgium/hassio-addons/tree/master/postgres", "url": "https://github.com/alexbelgium/hassio-addons/tree/master/postgres",
"version": "15.7-28" "version": "15.7-29"
} }

View File

@@ -59,6 +59,8 @@ fi
bashio::log.info "Waiting for PostgreSQL to start..." bashio::log.info "Waiting for PostgreSQL to start..."
( bashio::net.wait_for 5432 localhost 900
# Set PostgreSQL connection variables # Set PostgreSQL connection variables
DB_PORT=5432 DB_PORT=5432
DB_HOSTNAME=localhost DB_HOSTNAME=localhost
@@ -69,8 +71,6 @@ if bashio::config.has_value "POSTGRES_USER"; then
fi fi
export DB_PORT DB_HOSTNAME DB_USERNAME DB_PASSWORD export DB_PORT DB_HOSTNAME DB_USERNAME DB_PASSWORD
( bashio::net.wait_for 5432 localhost 900
until pg_isready -h "$DB_HOSTNAME" -p "$DB_PORT" -U "$DB_USERNAME" >/dev/null 2>&1; do until pg_isready -h "$DB_HOSTNAME" -p "$DB_PORT" -U "$DB_USERNAME" >/dev/null 2>&1; do
echo "PostgreSQL is starting up..." echo "PostgreSQL is starting up..."
sleep 2 sleep 2
@@ -81,56 +81,55 @@ done
############################### ###############################
update_postgres() { update_postgres() {
# Read the previous PostgreSQL version from file
OLD_PG_VERSION=$(cat "$PG_VERSION_FILE" 2>/dev/null || echo "$PG_MAJOR_VERSION")
# Read the previous PostgreSQL version from file if [ "$OLD_PG_VERSION" != "$PG_MAJOR_VERSION" ]; then
OLD_PG_VERSION=$(cat "$PG_VERSION_FILE" 2>/dev/null || echo "$PG_MAJOR_VERSION") bashio::log.warning "PostgreSQL major version changed ($OLD_PG_VERSION$PG_MAJOR_VERSION). Running upgrade..."
if [ "$OLD_PG_VERSION" != "$PG_MAJOR_VERSION" ]; then OLD_BIN_DIR="/usr/lib/postgresql/$OLD_PG_VERSION/bin"
bashio::log.warning "PostgreSQL major version changed ($OLD_PG_VERSION$PG_MAJOR_VERSION). Running upgrade..." NEW_BIN_DIR="/usr/lib/postgresql/$PG_MAJOR_VERSION/bin"
OLD_BIN_DIR="/usr/lib/postgresql/$OLD_PG_VERSION/bin" # Check if the old PostgreSQL binaries exist
NEW_BIN_DIR="/usr/lib/postgresql/$PG_MAJOR_VERSION/bin" if [ ! -d "$OLD_BIN_DIR" ]; then
bashio::log.warning "Old PostgreSQL binaries ($OLD_PG_VERSION) not found! Downloading..."
# Check if the old PostgreSQL binaries exist # Determine the package URL (adjust this as needed for your PostgreSQL distribution)
if [ ! -d "$OLD_BIN_DIR" ]; then PG_DOWNLOAD_URL="https://ftp.postgresql.org/pub/source/v$OLD_PG_VERSION/postgresql-$OLD_PG_VERSION.tar.gz"
bashio::log.warning "Old PostgreSQL binaries ($OLD_PG_VERSION) not found! Downloading..."
# Determine the package URL (adjust this as needed for your PostgreSQL distribution) # Create a temporary directory for the download
PG_DOWNLOAD_URL="https://ftp.postgresql.org/pub/source/v$OLD_PG_VERSION/postgresql-$OLD_PG_VERSION.tar.gz" TMP_DIR=$(mktemp -d)
cd "$TMP_DIR" || exit 1
# Create a temporary directory for the download # Download and extract PostgreSQL source
TMP_DIR=$(mktemp -d) wget "$PG_DOWNLOAD_URL" -O postgresql.tar.gz
cd "$TMP_DIR" || exit 1 tar -xzf postgresql.tar.gz
# Download and extract PostgreSQL source # Build only the necessary binaries
wget "$PG_DOWNLOAD_URL" -O postgresql.tar.gz cd "postgresql-$OLD_PG_VERSION" || exit 1
tar -xzf postgresql.tar.gz ./configure --prefix="$OLD_BIN_DIR"
make -j$(nproc)
make install
# Build only the necessary binaries # Clean up
cd "postgresql-$OLD_PG_VERSION" || exit 1 cd /config || exit 1
./configure --prefix="$OLD_BIN_DIR" rm -rf "$TMP_DIR"
make -j$(nproc) fi
make install
# Clean up # Run pg_upgrade with the correct paths
cd /config || exit 1 pg_upgrade --old-datadir="$PGDATA" \
rm -rf "$TMP_DIR" --new-datadir="$PGDATA-new" \
--old-bindir="$OLD_BIN_DIR" \
--new-bindir="$NEW_BIN_DIR"
# Replace old data directory with upgraded one
mv "$PGDATA" "$PGDATA-old"
mv "$PGDATA-new" "$PGDATA"
rm -rf "$PGDATA-old"
# Store the new PostgreSQL version
echo "$PG_MAJOR_VERSION" > "$PG_VERSION_FILE"
fi fi
# Run pg_upgrade with the correct paths
pg_upgrade --old-datadir="$PGDATA" \
--new-datadir="$PGDATA-new" \
--old-bindir="$OLD_BIN_DIR" \
--new-bindir="$NEW_BIN_DIR"
# Replace old data directory with upgraded one
mv "$PGDATA" "$PGDATA-old"
mv "$PGDATA-new" "$PGDATA"
rm -rf "$PGDATA-old"
# Store the new PostgreSQL version
echo "$PG_MAJOR_VERSION" > "$PG_VERSION_FILE"
fi
} }
##################################### #####################################