added bootstrap and stage1 procedures

This commit is contained in:
Spyros Ligouras 2013-07-18 14:07:39 +03:00
parent 6effb8b053
commit 84e0273e8a
2 changed files with 18 additions and 3 deletions

View File

@ -1,10 +1,10 @@
fs = require('fs')
async = require('async')
request = require('request')
{exec} = require('child_process')
API_ENDPOINT = 'http://paras.rulemotion.com:1337'
try
state = require('state.json')
catch e
@ -12,11 +12,13 @@ catch e
process.exit()
bootstrapTasks = [
# get config from extra partition
(callback) ->
try
callback(null, require('/mnt/config.json'))
catch error
callback(error)
# bootstraping
(config, callback) ->
request.post("#{API_ENDPOINT}/associate", {
user: config.id
@ -33,9 +35,21 @@ bootstrapTasks = [
state.uuid = body.uuid
fs.writeFileSync('state.json', JSON.strigify(state))
fs.writeFileSync('/etc/openvpn/ca.crt', body.ca)
fs.writeFileSync('/etc/openvpn/client.crt', body.cert)
fs.writeFileSync('/etc/openvpn/client.key', body.key)
callback(null)
)
]
stage1Tasks = [
(callback) -> async.waterfall(bootstrapTasks, callback)
(callback) -> exec('systemctl start openvpn@client', callback)
(callback) -> exec('systemctl enable openvpn@client', callback)
]
async.series(stage1Tasks, ->
console.log('Bootstrapped')
)

View File

@ -1,4 +1,5 @@
{
"virgin": true,
"uuid": null
"uuid": null,
"giturl": null
}