From 98891f4ba56b128aeadcf89f3f25edf0be652086 Mon Sep 17 00:00:00 2001 From: Spyros Ligouras Date: Thu, 18 Jul 2013 23:34:00 +0300 Subject: [PATCH] Added stage2 tasks to initialize the user's git repo --- app.coffee | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/app.coffee b/app.coffee index f1fc080e..7d42d540 100644 --- a/app.coffee +++ b/app.coffee @@ -4,6 +4,7 @@ request = require('request') {exec} = require('child_process') API_ENDPOINT = 'http://paras.rulemotion.com:1337' +HOME_PATH = '/home/haki' try state = require('./state.json') @@ -27,12 +28,16 @@ bootstrapTasks = [ return callback(error) try + if typeof body isnt 'object' + throw new Error(body) + body = JSON.parse(body) catch error callback(error) - + state.virgin = false state.uuid = body.uuid + state.giturl = body.giturl fs.writeFileSync('state.json', JSON.stringify(state)) @@ -51,6 +56,25 @@ stage1Tasks = [ (callback) -> exec('systemctl enable openvpn@client', callback) ] +stage2Tasks = [ + (callback) -> process.chdir("#{HOME_PATH}/hakiapp") + (callback) -> exec('npm install', callback) + (callback) -> exec('foreman start', callback) +] + async.series(stage1Tasks, -> console.log('Bootstrapped') -) + + async.doUntil( + -> fs.existsSync('hakiapp') + (callback) -> + process.chdir(HOME_PATH) + console.log('git clone') + exec("git clone #{state.giturl}") + setTimeout(callback, 1000) + (error) -> + if error? + console.error(error) + else + console.log('Initialized') + )