Skip to content

Commit 20fd374

Browse files
committed
fix(trek): reset admin password via direct DB update after server init
1 parent acfbb23 commit 20fd374

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

install/trek-install.sh

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,7 @@ COOKIE_SECURE=false
4646
FORCE_HTTPS=false
4747
LOG_LEVEL=info
4848
TZ=UTC
49-
ADMIN_EMAIL=admin@trek.local
50-
ADMIN_PASSWORD=${ADMIN_PASSWORD}
5149
EOF
52-
{
53-
echo ""
54-
echo "TREK Admin Credentials"
55-
echo "Email: admin@trek.local"
56-
echo "Password: ${ADMIN_PASSWORD}"
57-
echo "(Change password after first login)"
58-
echo ""
59-
} >>~/trek.creds
6050
msg_ok "Set up Server"
6151

6252
msg_info "Creating Service"
@@ -80,6 +70,32 @@ EOF
8070
systemctl enable -q --now trek
8171
msg_ok "Created Service"
8272

73+
msg_info "Waiting for TREK to initialize"
74+
for i in $(seq 1 30); do
75+
if curl -sf http://localhost:3000/api/health >/dev/null 2>&1; then
76+
break
77+
fi
78+
sleep 1
79+
done
80+
cd /opt/trek/server
81+
$STD node -e "
82+
const Database = require('better-sqlite3');
83+
const bcrypt = require('bcryptjs');
84+
const db = new Database('./data/travel.db');
85+
const hash = bcrypt.hashSync('${ADMIN_PASSWORD}', 12);
86+
db.prepare('UPDATE users SET password_hash = ?, must_change_password = 0 WHERE email = ?').run(hash, 'admin@trek.local');
87+
db.close();
88+
"
89+
{
90+
echo ""
91+
echo "TREK Admin Credentials"
92+
echo "Email: admin@trek.local"
93+
echo "Password: ${ADMIN_PASSWORD}"
94+
echo ""
95+
} >>~/trek.creds
96+
msg_ok "TREK initialized"
97+
msg_ok "Created Service"
98+
8399
motd_ssh
84100
customize
85101
cleanup_lxc

0 commit comments

Comments
 (0)