c17743d869
the infra version is bumped because the nginx's dhparams path has changed and the sftp server key path has changed.
49 lines
2.3 KiB
JavaScript
49 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
const async = require('async'),
|
|
fs = require('fs'),
|
|
safe = require('safetydance');
|
|
|
|
const BOX_DATA_DIR = '/home/yellowtent/boxdata';
|
|
const PLATFORM_DATA_DIR = '/home/yellowtent/platformdata';
|
|
|
|
exports.up = function (db, callback) {
|
|
let funcs = [];
|
|
|
|
const acmeKey = safe.fs.readFileSync(`${BOX_DATA_DIR}/acme/acme.key`);
|
|
if (acmeKey) {
|
|
funcs.push(db.runSql.bind(db, 'INSERT INTO blobs (id, value) VALUES (?, ?)', [ 'acme_account_key', acmeKey ]));
|
|
funcs.push(fs.unlink.bind(fs.fsyncSync, `${BOX_DATA_DIR}/acme`));
|
|
}
|
|
const dhparams = safe.fs.readFileSync(`${BOX_DATA_DIR}/dhparams.pem`);
|
|
if (dhparams) {
|
|
safe.fs.writeFileSync(`${PLATFORM_DATA_DIR}/dhparams.pem`, dhparams);
|
|
funcs.push(db.runSql.bind(db, 'INSERT INTO blobs (id, value) VALUES (?, ?)', [ 'dhparams', dhparams ]));
|
|
// leave the dhparms here for the moment because startup code regenerates box config and reloads nginx. at that point,
|
|
// nginx config of apps has not been removed yet and the reload fails.
|
|
// funcs.push(fs.unlink.bind(fs, `${BOX_DATA_DIR}/dhparams.pem`));
|
|
}
|
|
const turnSecret = safe.fs.readFileSync(`${BOX_DATA_DIR}/addon-turn-secret`);
|
|
if (turnSecret) {
|
|
funcs.push(db.runSql.bind(db, 'INSERT INTO blobs (id, value) VALUES (?, ?)', [ 'addon_turn_secret', turnSecret ]));
|
|
funcs.push(fs.unlink.bind(fs, `${BOX_DATA_DIR}/addon-turn-secret`));
|
|
}
|
|
|
|
// sftp keys get moved to platformdata in start.sh
|
|
const sftpPublicKey = safe.fs.readFileSync(`${BOX_DATA_DIR}/sftp/ssh/ssh_host_rsa_key.pub`);
|
|
const sftpPrivateKey = safe.fs.readFileSync(`${BOX_DATA_DIR}/sftp/ssh/ssh_host_rsa_key`);
|
|
if (sftpPublicKey) {
|
|
safe.fs.writeFileSync(`${PLATFORM_DATA_DIR}/sftp/ssh/ssh_host_rsa_key.pub`, sftpPublicKey);
|
|
safe.fs.writeFileSync(`${PLATFORM_DATA_DIR}/sftp/ssh/ssh_host_rsa_key`, sftpPrivateKey);
|
|
funcs.push(db.runSql.bind(db, 'INSERT INTO blobs (id, value) VALUES (?, ?)', [ 'sftp_public_key', sftpPublicKey ]));
|
|
funcs.push(db.runSql.bind(db, 'INSERT INTO blobs (id, value) VALUES (?, ?)', [ 'sftp_private_key', sftpPrivateKey ]));
|
|
funcs.push(fs.rmdir.bind(fs, `${BOX_DATA_DIR}/sftp`, { recursive: true }));
|
|
}
|
|
|
|
async.series(funcs, callback);
|
|
};
|
|
|
|
exports.down = function(db, callback) {
|
|
callback();
|
|
};
|