Remove initial install feature in installer
This commit is contained in:
+3
-71
@@ -5,70 +5,23 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert'),
|
||||
async = require('async'),
|
||||
debug = require('debug')('installer:server'),
|
||||
express = require('express'),
|
||||
fs = require('fs'),
|
||||
http = require('http'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
installer = require('./installer.js'),
|
||||
json = require('body-parser').json,
|
||||
lastMile = require('connect-lastmile'),
|
||||
morgan = require('morgan'),
|
||||
safe = require('safetydance');
|
||||
morgan = require('morgan');
|
||||
|
||||
exports = module.exports = {
|
||||
start: start,
|
||||
stop: stop
|
||||
};
|
||||
|
||||
var PROVISION_CONFIG_FILE_JSON = '/root/userdata.json';
|
||||
var PROVISION_CONFIG_FILE_JS = '/root/userdata.js';
|
||||
var CLOUDRON_CONFIG_FILE = '/home/yellowtent/configs/cloudron.conf';
|
||||
var BOX_VERSIONS_URL = 'https://s3.amazonaws.com/prod-cloudron-releases/versions.json';
|
||||
|
||||
var gHttpServer = null; // update server; used for updates
|
||||
|
||||
function provision(callback) {
|
||||
if (fs.existsSync(CLOUDRON_CONFIG_FILE)) {
|
||||
debug('provision: already provisioned');
|
||||
return callback(null); // already provisioned
|
||||
}
|
||||
|
||||
var userData = null;
|
||||
|
||||
function retry(error) {
|
||||
if (error) console.error(error);
|
||||
setTimeout(provision.bind(null, callback), 5000);
|
||||
}
|
||||
|
||||
// check for .json file then .js
|
||||
if (fs.existsSync(PROVISION_CONFIG_FILE_JSON)) {
|
||||
userData = safe.require(PROVISION_CONFIG_FILE_JSON);
|
||||
if (!userData) return retry('Provisioning data invalid');
|
||||
} else if (fs.existsSync(PROVISION_CONFIG_FILE_JS)) {
|
||||
var tmp = safe.require(PROVISION_CONFIG_FILE_JS);
|
||||
if (!tmp) return retry('Provisioning data invalid');
|
||||
|
||||
// translate to expected format
|
||||
userData = { data: tmp };
|
||||
}
|
||||
|
||||
if (!userData) return retry('No user data file found. Waiting for it...');
|
||||
|
||||
// validate the bare minimum
|
||||
if (!userData.data || typeof userData.data !== 'object') return retry('user data misses "data" object');
|
||||
if (!userData.data.fqdn || typeof userData.data.fqdn !== 'string') return retry('fqdn in user data has to be a non-empty string');
|
||||
|
||||
// set the fallback
|
||||
if (!userData.data.boxVersionsUrl) userData.data.boxVersionsUrl = BOX_VERSIONS_URL;
|
||||
|
||||
if (typeof userData.data.boxVersionsUrl !== 'string') return retry('boxVersionsUrl in user data has to be a non-empty string');
|
||||
|
||||
installer.provision(userData, callback);
|
||||
}
|
||||
|
||||
function update(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
@@ -84,7 +37,7 @@ function update(req, res, next) {
|
||||
next(new HttpSuccess(202, { }));
|
||||
}
|
||||
|
||||
function startUpdateServer(callback) {
|
||||
function start(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
debug('Starting update server');
|
||||
@@ -107,7 +60,7 @@ function startUpdateServer(callback) {
|
||||
gHttpServer.listen(2020, '127.0.0.1', callback);
|
||||
}
|
||||
|
||||
function stopUpdateServer(callback) {
|
||||
function stop(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
debug('Stopping update server');
|
||||
@@ -118,27 +71,6 @@ function stopUpdateServer(callback) {
|
||||
gHttpServer = null;
|
||||
}
|
||||
|
||||
function start(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
debug('Starting Installer');
|
||||
|
||||
var actions = [
|
||||
startUpdateServer,
|
||||
provision
|
||||
];
|
||||
|
||||
async.series(actions, callback);
|
||||
}
|
||||
|
||||
function stop(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
async.series([
|
||||
stopUpdateServer
|
||||
], callback);
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
start(function (error) {
|
||||
if (error) console.error(error);
|
||||
|
||||
Reference in New Issue
Block a user