cryptpad/scripts/install.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-12-20 23:56:41 +08:00
const nThen = require("nthen");
const Fs = require("fs");
const Path = require("path");
const Decrees = require("../lib/decrees");
var config = require("../lib/load-config");
var Hash = require('../www/common/common-hash');
var Env = require("../lib/env").create(config);
Env.Log = { error: console.log };
var path = Path.join(Env.paths.decree, 'decree.ndjson');
2022-12-21 00:00:23 +08:00
var token;
2022-12-20 23:56:41 +08:00
nThen(function (w) {
Decrees.load(Env, w(function (err) {
if (err) {
console.error(err);
w.abort();
return;
}
if (Env.installToken) {
console.log('Existing token');
token = Env.installToken;
}
}));
}).nThen(function (w) {
if (Env.installToken) { return; }
console.log(Env.paths.decree);
2022-12-21 00:00:23 +08:00
token = Hash.createChannelId() + Hash.createChannelId();
2022-12-20 23:56:41 +08:00
var decree = ["ADD_INSTALL_TOKEN",[token],"",+new Date()];
Fs.appendFile(path, JSON.stringify(decree) + '\n', w(function (err) {
if (err) { console.log(err); return; }
}));
}).nThen(function () {
console.log('Install token:');
console.log(token);
var url = config.httpUnsafeOrigin + '/install/';
console.log(`Please visit ${url} to create your first admin user`);
});