Remove version from cloudron.conf

The version and code move together, it's not really part of cloudron
configuration.

This can maybe even come from package.json later
This commit is contained in:
Girish Ramakrishnan
2014-10-23 12:34:53 -07:00
parent 2498311f24
commit 5ec406bf4d
7 changed files with 27 additions and 25 deletions
+1 -1
View File
@@ -9,7 +9,7 @@
"changelog": [
"Display version correctly"
],
"next": "0.2.0"
"next": "0.3.0"
},
"0.3.0": {
"revision": "d6cc39dd010beccbde78db6043ab6d4f8d1adefb",
+17 -1
View File
@@ -7,10 +7,23 @@ var path = require('path'),
safe = require('safetydance'),
assert = require('assert'),
_ = require('underscore'),
path = require('path'),
mkdirp = require('mkdirp');
var homeDir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
var production = process.env.NODE_ENV === 'production';
var currentVersion = (function () {
var versions = JSON.parse(fs.readFileSync(path.join(__dirname, 'VERSIONS.json')));
var firstVersion = Object.keys(versions).reduce(function (prev, cur) { return prev < cur ? prev : cur; });
var cur = firstVersion;
while (versions[cur].next !== null) {
cur = versions[cur].next;
}
return cur;
})();
var config = { };
if (production) {
@@ -45,7 +58,6 @@ config.save = function () {
config.adminOrigin = 'https://admin-' + config.fqdn;
config.token = null;
config.version = '0.5.0';
config.mailServer = null;
config.mailUsername = null;
config.mailDnsRecordIds = [ ];
@@ -83,5 +95,9 @@ config.get = function (key) {
return config[key];
};
config.version = function () {
return currentVersion;
};
exports = module.exports = config;
+1 -1
View File
@@ -196,7 +196,7 @@ function getConfig(callback) {
isDev: config.isDev,
fqdn: config.fqdn,
ip: getIp(),
version: config.version,
version: config.version(),
revision: stdout,
update: updater.availableUpdate()
})
-14
View File
@@ -70,20 +70,6 @@ else
echo "No update script to run"
fi
echo "Updating box version to $VERSION"
# Do not use json node binary. Seems to have some bug resulting in empty cloudron.conf
# in heredocs, single quotes preserves the quotes _and_ does variable expansion
REPLACE_VERSION_JS=$(cat <<EOF
var fs = require('fs');
var config = JSON.parse(fs.readFileSync('$HOME/cloudron.conf', 'utf8'));
config.version = '$VERSION';
fs.writeFileSync('$HOME/cloudron.conf', JSON.stringify(config, null, 4));
EOF
)
sudo -u yellowtent -H bash <<EOF
node -e "$REPLACE_VERSION_JS"
EOF
echo "Starting box..."
OUT=`supervisorctl start box`
RESULT=`echo $OUT | grep echo`
+2 -2
View File
@@ -82,7 +82,7 @@ Server.prototype._firstTime = function (req, res) {
userdb.count(function (error, count) {
if (error) return res.send(500, { status: http.STATUS_CODES[500], message: error.message || 'Internal Server error' });
return res.send(200, { activated: count !== 0, version: config.version });
return res.send(200, { activated: count !== 0, version: config.version() });
});
};
@@ -96,7 +96,7 @@ Server.prototype._firstTime = function (req, res) {
* @apiSuccess {String} version The current version string of the device.
*/
Server.prototype._getVersion = function (req, res) {
res.send(200, { version: config.version });
res.send(200, { version: config.version() });
};
/*
+1 -1
View File
@@ -98,7 +98,7 @@ describe('Server', function () {
expect(err).to.not.be.ok();
expect(res.statusCode).to.equal(200);
var versions = require('../../VERSIONS.json');
var latestVersion = Object.keys(versions).sort().pop();
var latestVersion = Object.keys(versions).sort().slice(0, -1).pop();
expect(res.body.version).to.equal(latestVersion);
done(err);
});
+5 -5
View File
@@ -29,7 +29,7 @@ Updater.prototype.availableUpdate = function () {
};
Updater.prototype._check = function () {
debug('check: for updates. box is on version ' + config.version);
debug('check: for updates. box is on version ' + config.version());
var that = this;
@@ -65,13 +65,13 @@ Updater.prototype._check = function () {
return;
}
if (!versions[config.version]) {
console.error('Cloudron runs on unknown version %s', config.version);
if (!versions[config.version()]) {
console.error('Cloudron runs on unknown version %s', config.version());
that._boxUpdateInfo = null;
return;
}
var next = versions[config.version].next;
var next = versions[config.version()].next;
if (next && versions[next] && versions[next].revision) {
debug('_check: new version %s available to revision %s.', next, versions[next].revision);
that._boxUpdateInfo = versions[next];
@@ -109,7 +109,7 @@ Updater.prototype.update = function (backupUrl, callback) {
var args = [
path.join(__dirname, 'scripts/update.sh'),
isDev ? config.version : this._boxUpdateInfo.version,
isDev ? config.version() : this._boxUpdateInfo.version,
isDev ? 'origin/master' : this._boxUpdateInfo.revision,
backupUrl
];