Commit 70894e70 authored by Efthymia Bika's avatar Efthymia Bika

Initialize templates file

parent fc6e38c9
......@@ -7,6 +7,7 @@ var execSync = require('child_process').execSync;
var BAAS_HOME_DIR = '.baas';
var CLOUDS_CONF_FILE = 'clouds.rc';
var BACKUP_CONF_FILE = 'backups.rc';
var TEMPLATES_FILE = 'templates.rc';
var BAAS_LOG_DIR = path.join(get_user_home(), BAAS_HOME_DIR, 'log');
var BAAS_CACHE_DIR = path.join(get_user_home(), BAAS_HOME_DIR, 'cache');
var RESTORE_DEFAULT_DIR = path.join(get_user_home(), "Downloads");
......@@ -18,6 +19,27 @@ function get_user_home() {
return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
}
var templates_data = {
"Backup_Home": {
"name": "Backup_Home",
"local_dir": get_user_home(),
"cloud": "",
"passphrase": "",
"container": "Backup_Home",
"exclude": "",
"include": ""
},
"Backup_etc": {
"name": "Backup_etc",
"local_dir": "/etc",
"cloud": "",
"passphrase": "",
"container": "Backup_etc",
"exclude": "",
"include": ""
}
}
function get_unix_path(target) {
if(process.platform == 'win32') {
var out = execSync(CYGWIN_BASH +
......@@ -31,6 +53,18 @@ function get_unix_path(target) {
var DUPLICITY_PATH = get_unix_path("duplicity");
var TIMEVIEW_PATH = get_unix_path("timeview.py");
function create_conf_files() {
create_conf_file(CLOUDS_CONF_FILE);
create_conf_file(BACKUP_CONF_FILE);
write_file_if_empty(TEMPLATES_FILE, templates_data);
mkdirp(BAAS_LOG_DIR, function(err) {
if(err) console.error(err);
});
mkdirp(BAAS_CACHE_DIR, function(err) {
if(err) console.error(err);
});
}
function create_baas_dir() {
var dir = path.join(get_user_home(), BAAS_HOME_DIR);
fs.stat(dir, function (err, stats) {
......@@ -39,29 +73,16 @@ function create_baas_dir() {
if(error) return console.error(error);
console.log("Successfully created " + dir);
// Create conf files under new directory
create_conf_file(CLOUDS_CONF_FILE);
create_conf_file(BACKUP_CONF_FILE);
mkdirp(BAAS_LOG_DIR, function(err) {
if(err) console.error(err);
});
mkdirp(BAAS_CACHE_DIR, function(err) {
if(err) console.error(err);
});
create_conf_files();
});
return;
}
if(stats.isFile()) {
return console.error("Failed to create " + dir + ", File exists.");
} else {
// Directory found, check for conf files
create_conf_file(CLOUDS_CONF_FILE);
create_conf_file(BACKUP_CONF_FILE);
mkdirp(BAAS_LOG_DIR, function(err) {
if(err) console.error(err);
});
mkdirp(BAAS_CACHE_DIR, function(err) {
if(err) console.error(err);
});
if(stats.isFile()) {
return console.error("Failed to create " + dir + ", File exists.");
} else {
// Directory found, check for conf files
create_conf_files();
}
}
});
}
......@@ -92,6 +113,18 @@ function write_conf_file(filename, data) {
}
function write_file_if_empty(filename, data) {
var file = path.join(get_user_home(), BAAS_HOME_DIR, filename);
fs.stat(file, function(err, stats) {
if(err || (stats && stats.size == 0)) {
fs.writeFile(file, JSON.stringify(data, null, 2), function(error) {
if(error) return console.error(error);
console.log("Successfully initialized " + file);
});
}
});
}
function load_data_from_file(filename, callback) {
var conf_file = path.join(get_user_home(), BAAS_HOME_DIR, filename);
fs.stat(conf_file, function (err, stats) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment