adding users

This commit is contained in:
root
2025-12-21 22:38:38 -08:00
parent 18c4219d62
commit 81fb946074
2 changed files with 39 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ RUN apt-get update && apt-get install -y \
iproute2 \
nano \
dovecot-core \
jq \
&& rm -rf /var/lib/apt/lists/*
COPY start_network.sh /start_network.sh

View File

@@ -109,19 +109,51 @@ EOF
chmod +x /usr/bin/supervisorctl
fi
# 4. FIRST-BOOT ACCOUNT CREATION
# 4. ACCOUNT CREATION (Admin + USERS_JSON)
if [ -f "$ACCOUNTS_FILE" ]; then
echo "✅ Accounts file exists. Skipping creation."
else
echo "⚠️ Accounts file missing. Checking for ENV variables..."
echo "⚠️ Accounts file missing. Initializing..."
mkdir -p "$CONFIG_DIR"
# --- A. Create Admin Account ---
if [[ -n "$DMS_ADMIN_EMAIL" ]] && [[ -n "$DMS_ADMIN_PASSWORD" ]]; then
echo "📝 Generating admin account for $DMS_ADMIN_EMAIL..."
echo "📝 Creating Admin: $DMS_ADMIN_EMAIL..."
HASH=$(doveadm pw -s SHA512-CRYPT -p "$DMS_ADMIN_PASSWORD")
mkdir -p "$CONFIG_DIR"
echo "$DMS_ADMIN_EMAIL|$HASH" > "$ACCOUNTS_FILE"
echo "✅ Admin account created."
else
echo "❌ No accounts file and no DMS_ADMIN_PASSWORD env var found."
echo "❌ No DMS_ADMIN_EMAIL found. Creating empty accounts file."
touch "$ACCOUNTS_FILE"
fi
# --- B. Process USERS_JSON ---
if [[ -n "${USERS_JSON:-}" ]]; then
echo "📋 Found USERS_JSON. Parsing..."
# Determine Domain (from Admin Email or default)
DOMAIN_SUFFIX=$(echo "$DMS_ADMIN_EMAIL" | cut -d'@' -f2)
if [[ -z "$DOMAIN_SUFFIX" ]]; then DOMAIN_SUFFIX="poppyglen.cc"; fi
# Loop through users and append to file
echo "$USERS_JSON" | jq -c '.[]' | while read -r user_entry; do
U=$(echo "$user_entry" | jq -r '.username')
P=$(echo "$user_entry" | jq -r '.password')
if [[ -n "$U" && -n "$P" ]]; then
# Hash using local doveadm
UHASH=$(doveadm pw -s SHA512-CRYPT -p "$P")
# Check if username already has @domain, if not add it
if [[ "$U" != *"@"* ]]; then
FULL_USER="$U@$DOMAIN_SUFFIX"
else
FULL_USER="$U"
fi
echo "$FULL_USER|$UHASH" >> "$ACCOUNTS_FILE"
echo " -> Added User: $FULL_USER"
fi
done
fi
fi