From 888395739324ccb2e2c3300da178d1307021b0d9 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Fri, 20 Mar 2026 14:48:11 +0100 Subject: [PATCH] fix(discourse): create admin via rails runner, fix invalid email --- ct/discourse.sh | 4 ++-- install/discourse-install.sh | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ct/discourse.sh b/ct/discourse.sh index e9387dd69..2ddb8c10e 100644 --- a/ct/discourse.sh +++ b/ct/discourse.sh @@ -73,5 +73,5 @@ msg_ok "Completed Successfully!\n" echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" echo -e "${INFO}${YW} Access it using the following URL:${CL}" echo -e "${TAB}${GATEWAY}${BGN}http://${IP}${CL}" -echo -e "${INFO}${YW} Admin Setup:${CL}" -echo -e "${TAB}${GATEWAY}${BGN}Create the first account in the web UI (use admin@local to match developer emails)${CL}" +echo -e "${INFO}${YW} Credentials saved in:${CL}" +echo -e "${TAB}/root/discourse.creds" diff --git a/install/discourse-install.sh b/install/discourse-install.sh index 09ed75817..d6cf565ab 100644 --- a/install/discourse-install.sh +++ b/install/discourse-install.sh @@ -55,7 +55,7 @@ DISCOURSE_DB_NAME=discourse DISCOURSE_DB_USERNAME=discourse DISCOURSE_DB_PASSWORD=${DISCOURSE_DB_PASS} DISCOURSE_REDIS_URL=redis://localhost:6379 -DISCOURSE_DEVELOPER_EMAILS=admin@local +DISCOURSE_DEVELOPER_EMAILS=admin@discourse.local DISCOURSE_HOSTNAME=${LOCAL_IP} DISCOURSE_SMTP_ADDRESS=localhost DISCOURSE_SMTP_PORT=25 @@ -96,6 +96,29 @@ $STD bundle exec rails db:migrate $STD bundle exec rails db:seed msg_ok "Set Up Database" +msg_info "Creating Admin Account" +ADMIN_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c16) +$STD bundle exec rails runner " +user = User.new(email: 'admin@discourse.local', username: 'admin', password: '${ADMIN_PASS}') +user.active = true +user.admin = true +user.approved = true +user.save!(validate: false) +user.activate +user.grant_admin! +user.change_trust_level!(TrustLevel[4]) +SiteSetting.has_login_hint = false +SiteSetting.wizard_enabled = false +" +{ + echo "Discourse Credentials" + echo "Admin Username: admin" + echo "Admin Email: admin@discourse.local" + echo "Admin Password: ${ADMIN_PASS}" + echo "Database Password: ${DISCOURSE_DB_PASS}" +} >~/discourse.creds +msg_ok "Created Admin Account" + msg_info "Building Discourse Assets" cd /opt/discourse export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"