From 4fe1d95c810e1830bd89156a95248b1d1a6653af Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Fri, 27 Mar 2026 15:41:05 +0100 Subject: [PATCH] fix(ente): auto-whitelist admin by user_id from database The admin CLI requires the user to be whitelisted via their numeric user_id in museum.yaml's internal.admin field. The helper script ente-upgrade-subscription now: 1. Looks up user_id from PostgreSQL by email 2. Adds internal.admin to museum.yaml if not present 3. Restarts museum 4. Runs the subscription upgrade This replaces the previous approach that incorrectly assumed the first user was auto-admin (that fallback only works when internal section is completely absent AND was unreliable). --- install/ente-install.sh | 17 ++++++++++++++++- json/ente.json | 8 ++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/install/ente-install.sh b/install/ente-install.sh index cf59ad1f..05cea509 100644 --- a/install/ente-install.sh +++ b/install/ente-install.sh @@ -309,7 +309,22 @@ if [ -z "$1" ]; then exit 1 fi EMAIL="$1" -echo "Upgrading subscription for: $EMAIL" +DB_NAME="$(grep -A1 '^db:' /opt/ente/server/museum.yaml | awk '/name:/{print $2}')" +DB_USER="$(grep -A2 '^db:' /opt/ente/server/museum.yaml | awk '/user:/{print $2}')" +USER_ID=$(psql -U "$DB_USER" -d "$DB_NAME" -tAc "SELECT user_id FROM users WHERE email='$EMAIL' LIMIT 1;") +if [ -z "$USER_ID" ]; then + echo "Error: No user found with email $EMAIL" + exit 1 +fi +echo "Found user ID: $USER_ID for $EMAIL" +if ! grep -q "^internal:" /opt/ente/server/museum.yaml; then + printf '\ninternal:\n admin: %s\n' "$USER_ID" >> /opt/ente/server/museum.yaml + echo "Added admin entry to museum.yaml" + systemctl restart ente-museum + sleep 2 +else + echo "internal: section already exists in museum.yaml — verify admin is set" +fi ente admin update-subscription -a "$EMAIL" -u "$EMAIL" --no-limit True EOF chmod +x /usr/local/bin/ente-upgrade-subscription diff --git a/json/ente.json b/json/ente.json index 8b029c2e..bbf8f236 100644 --- a/json/ente.json +++ b/json/ente.json @@ -41,15 +41,11 @@ "type": "warning" }, { - "text": "First-Start: The first registered user automatically becomes admin", - "type": "info" - }, - { - "text": "First-Start: Add your account to the CLI: `ente account add` (export dir: any path, e.g. /photos)", + "text": "First-Start: Add your account to the CLI first: `ente account add` (export dir: any path, e.g. /photos)", "type": "warning" }, { - "text": "First-Start: Remove the subscription limit: `ente admin update-subscription -a -u --no-limit True`", + "text": "First-Start: Whitelist admin and remove subscription limit: `ente-upgrade-subscription `", "type": "warning" }, {