Gendle commited on
Commit
a0978fc
·
verified ·
1 Parent(s): 43370b4

Upload entrypoint.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. entrypoint.sh +11 -38
entrypoint.sh CHANGED
@@ -1342,64 +1342,37 @@ const { DatabaseSync } = require("node:sqlite");
1342
  const { randomBytes, scryptSync } = require("node:crypto");
1343
  const os = require("node:os");
1344
  const path = require("node:path");
 
1345
 
1346
- // Match hermes-web-ui CLI: WEB_UI_HOME = HERMES_WEB_UI_HOME || $HOME/.hermes-web-ui
1347
  const WEB_UI_HOME = process.env.HERMES_WEB_UI_HOME?.trim()
1348
  || path.join(os.homedir(), ".hermes-web-ui");
1349
  const DB_FILE = path.join(WEB_UI_HOME, "hermes-web-ui.db");
1350
 
1351
- // Same hash function as hermes-web-ui CLI (scrypt:salt:hash format)
1352
  function hashPassword(password) {
1353
  const salt = randomBytes(16).toString("hex");
1354
  const hash = scryptSync(password, salt, 64).toString("hex");
1355
  return "scrypt:" + salt + ":" + hash;
1356
  }
1357
 
1358
- if (!require("node:fs").existsSync(DB_FILE)) {
1359
- console.error(" 数据库文件不存在: " + DB_FILE);
1360
  process.exit(1);
1361
  }
1362
 
1363
- console.log(" 📁 数据库: " + DB_FILE);
1364
-
1365
  const db = new DatabaseSync(DB_FILE);
1366
 
1367
- // Create table (idempotent, matches hermes-web-ui schema)
1368
- db.exec(\`CREATE TABLE IF NOT EXISTS users (
1369
- id INTEGER PRIMARY KEY AUTOINCREMENT,
1370
- username TEXT NOT NULL UNIQUE,
1371
- password_hash TEXT NOT NULL,
1372
- role TEXT NOT NULL DEFAULT 'admin',
1373
- status TEXT NOT NULL DEFAULT 'active',
1374
- created_at INTEGER NOT NULL,
1375
- updated_at INTEGER NOT NULL,
1376
- last_login_at INTEGER
1377
- )\`);
1378
 
1379
  const now = Date.now();
1380
- const passwordHash = hashPassword("hm951753");
1381
-
1382
- // Upsert Gendle user
1383
- const existing = db.prepare("SELECT id FROM users WHERE username = ?").get("Gendle");
1384
- if (existing?.id) {
1385
- db.prepare(\`UPDATE users SET password_hash = ?, role = 'super_admin', status = 'active', updated_at = ? WHERE id = ?\`)
1386
- .run(passwordHash, now, existing.id);
1387
- console.log(" ✅ 用户 Gendle 密码已更新");
1388
- } else {
1389
- db.prepare("INSERT INTO users (username, password_hash, role, status, created_at, updated_at) VALUES (?, ?, 'super_admin', 'active', ?, ?)")
1390
- .run("Gendle", passwordHash, now, now);
1391
- console.log(" ✅ 用户 Gendle 已创建");
1392
- }
1393
-
1394
- // Disable old admin user if exists
1395
- const adminCheck = db.prepare("SELECT id FROM users WHERE username = 'admin' AND username != 'Gendle'").get();
1396
- if (adminCheck?.id) {
1397
- db.prepare("UPDATE users SET status = 'disabled' WHERE id = ?").run(adminCheck.id);
1398
- console.log(" ✅ admin 用户已禁用");
1399
- }
1400
 
 
 
1401
  db.close();
1402
- console.log(" ✅ 凭据配置完成");
1403
  CREDSCRIPT
1404
  )
1405
 
 
1342
  const { randomBytes, scryptSync } = require("node:crypto");
1343
  const os = require("node:os");
1344
  const path = require("node:path");
1345
+ const fs = require("node:fs");
1346
 
1347
+ // Match hermes-web-ui CLI: DB at $HERMES_WEB_UI_HOME or $HOME/.hermes-web-ui/hermes-web-ui.db
1348
  const WEB_UI_HOME = process.env.HERMES_WEB_UI_HOME?.trim()
1349
  || path.join(os.homedir(), ".hermes-web-ui");
1350
  const DB_FILE = path.join(WEB_UI_HOME, "hermes-web-ui.db");
1351
 
 
1352
  function hashPassword(password) {
1353
  const salt = randomBytes(16).toString("hex");
1354
  const hash = scryptSync(password, salt, 64).toString("hex");
1355
  return "scrypt:" + salt + ":" + hash;
1356
  }
1357
 
1358
+ if (!fs.existsSync(DB_FILE)) {
1359
+ console.error("DB not found: " + DB_FILE);
1360
  process.exit(1);
1361
  }
1362
 
 
 
1363
  const db = new DatabaseSync(DB_FILE);
1364
 
1365
+ // Force recreate users table to fix any schema corruption
1366
+ db.exec("DROP TABLE IF EXISTS users");
1367
+ db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL UNIQUE, password_hash TEXT NOT NULL, role TEXT NOT NULL DEFAULT 'admin', status TEXT NOT NULL DEFAULT 'active', created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, last_login_at INTEGER)");
 
 
 
 
 
 
 
 
1368
 
1369
  const now = Date.now();
1370
+ db.prepare("INSERT INTO users (username, password_hash, role, status, created_at, updated_at) VALUES (?, ?, 'super_admin', 'active', ?, ?)")
1371
+ .run("Gendle", hashPassword("hm951753"), now, now);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1372
 
1373
+ var users = db.prepare("SELECT username, role FROM users").all();
1374
+ console.log("Users: " + JSON.stringify(users));
1375
  db.close();
 
1376
  CREDSCRIPT
1377
  )
1378