mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2026-02-24 07:19:35 -06:00
setup: fix IP address handling for database/service names
- Detect when FQDN starts with digit (IP address) - Generate 2 random letter prefix for database/service names - Use prefixed names for DB_NAME, DB_USER, INSTANCE_USER - Keep original FQDN for nginx configs and URLs - Prevents PostgreSQL errors with numeric database names Example: 192.168.1.50 -> xy192_168_1_50 for services
This commit is contained in:
12
setup.sh
12
setup.sh
@@ -376,6 +376,16 @@ init_instance_vars() {
|
||||
|
||||
# Create safe database name from FQDN
|
||||
DB_SAFE_NAME=$(echo "$FQDN" | sed 's/[^a-zA-Z0-9]/_/g' | sed 's/^_*//' | sed 's/_*$//')
|
||||
|
||||
# Check if FQDN starts with a digit (likely an IP address)
|
||||
if [[ "$FQDN" =~ ^[0-9] ]]; then
|
||||
# Generate 2 random letters for IP address prefixing
|
||||
RANDOM_PREFIX=$(tr -dc 'a-z' < /dev/urandom | head -c 2)
|
||||
DB_SAFE_NAME="${RANDOM_PREFIX}${DB_SAFE_NAME}"
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] IP address detected, prefixed with: $RANDOM_PREFIX" >> "$DEBUG_LOG"
|
||||
print_info "IP address detected ($FQDN), using prefix '$RANDOM_PREFIX' for database/service names"
|
||||
fi
|
||||
|
||||
DB_NAME="${DB_SAFE_NAME}"
|
||||
DB_USER="${DB_SAFE_NAME}"
|
||||
|
||||
@@ -416,7 +426,7 @@ init_instance_vars() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Creating dedicated user name..." >> "$DEBUG_LOG"
|
||||
|
||||
# Create dedicated user name (safe for system users)
|
||||
INSTANCE_USER=$(echo "$FQDN" | sed 's/[^a-zA-Z0-9]/_/g' | sed 's/^_*//' | sed 's/_*$//' | cut -c1-32)
|
||||
INSTANCE_USER=$(echo "$DB_SAFE_NAME" | cut -c1-32)
|
||||
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] INSTANCE_USER: $INSTANCE_USER" >> "$DEBUG_LOG"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user