Upload entrypoint.sh with huggingface_hub
Browse files- entrypoint.sh +44 -46
entrypoint.sh
CHANGED
|
@@ -1340,65 +1340,63 @@ sleep 5
|
|
| 1340 |
SETUP_CREDENTIALS=$(cat <<'CREDSCRIPT'
|
| 1341 |
const { DatabaseSync } = require("node:sqlite");
|
| 1342 |
const { randomBytes, scryptSync } = require("node:crypto");
|
| 1343 |
-
|
| 1344 |
-
// Find the SQLite database
|
| 1345 |
-
const fs = require("node:fs");
|
| 1346 |
const path = require("node:path");
|
| 1347 |
|
| 1348 |
-
|
| 1349 |
-
|
| 1350 |
-
"
|
| 1351 |
-
|
| 1352 |
-
|
| 1353 |
-
let dbPath = null;
|
| 1354 |
-
for (const dir of DB_DIRS) {
|
| 1355 |
-
if (fs.existsSync(dir)) {
|
| 1356 |
-
const files = fs.readdirSync(dir);
|
| 1357 |
-
for (const f of files) {
|
| 1358 |
-
if (f.endsWith(".sqlite") || f.endsWith(".db")) {
|
| 1359 |
-
dbPath = path.join(dir, f);
|
| 1360 |
-
break;
|
| 1361 |
-
}
|
| 1362 |
-
}
|
| 1363 |
-
if (dbPath) break;
|
| 1364 |
-
}
|
| 1365 |
-
}
|
| 1366 |
|
| 1367 |
-
|
| 1368 |
-
|
| 1369 |
-
|
|
|
|
|
|
|
| 1370 |
}
|
| 1371 |
|
| 1372 |
-
|
| 1373 |
-
|
| 1374 |
-
const db = new DatabaseSync(dbPath);
|
| 1375 |
-
|
| 1376 |
-
// Check if users table exists
|
| 1377 |
-
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='users'").all();
|
| 1378 |
-
if (tables.length === 0) {
|
| 1379 |
-
console.error("❌ users 表不存在,可能 BFF 尚未初始化");
|
| 1380 |
process.exit(1);
|
| 1381 |
}
|
| 1382 |
|
| 1383 |
-
|
| 1384 |
-
|
| 1385 |
-
const
|
| 1386 |
-
|
| 1387 |
-
|
| 1388 |
-
|
| 1389 |
-
|
| 1390 |
-
|
| 1391 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1392 |
console.log(" ✅ 用户 Gendle 密码已更新");
|
| 1393 |
} else {
|
| 1394 |
-
db.prepare("INSERT INTO users (username,
|
| 1395 |
-
|
| 1396 |
console.log(" ✅ 用户 Gendle 已创建");
|
| 1397 |
}
|
| 1398 |
|
| 1399 |
-
// Disable
|
| 1400 |
-
db.prepare("
|
| 1401 |
-
|
|
|
|
|
|
|
|
|
|
| 1402 |
|
| 1403 |
db.close();
|
| 1404 |
console.log(" ✅ 凭据配置完成");
|
|
|
|
| 1340 |
SETUP_CREDENTIALS=$(cat <<'CREDSCRIPT'
|
| 1341 |
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(" ✅ 凭据配置完成");
|