1
|
|
|
var program = require('commander'); |
2
|
|
|
var shell = require('shelljs'); |
3
|
|
|
var chalk = require('chalk'); |
4
|
|
|
var co = require('co'); |
5
|
|
|
var prompt = require('co-prompt'); |
6
|
|
|
|
7
|
|
|
// .arguments('<file>') |
8
|
|
|
// .option('-u, --username <username>', 'The user to authenticate as') |
9
|
|
|
// .option('-p, --password <password>', 'The user\'s password') |
10
|
|
|
program |
11
|
|
|
.usage('[options] <enviroment ...>') |
12
|
|
|
// .option('-u, --username <username>', 'The user to authenticate as') |
13
|
|
|
.arguments('<enviroment>') |
14
|
|
|
.action(function(enviroment) { |
15
|
|
|
|
16
|
|
|
shell.mkdir('-p',['applications/assets/icons']); |
17
|
|
|
|
18
|
|
|
shell.echo('Build Server Vagrant ('+enviroment+')'); |
19
|
|
|
|
20
|
|
|
if ( enviroment === 'dev' ){ |
21
|
|
|
|
22
|
|
|
var vagrantId = shell.exec("vagrant global-status | grep d1b0server | awk '{ print $1}'", {silent:true}); |
23
|
|
|
|
24
|
|
|
var vagrantCode; |
25
|
|
|
if ( vagrantId.code !== 0 ){ |
26
|
|
|
//ERRORE |
27
|
|
|
process.stderr.write(chalk.red("Errore: "+vagrantId.stderr+ " - "+vagrantId.output)); |
28
|
|
|
process.exit(1); |
|
|
|
|
29
|
|
|
} else { |
30
|
|
|
vagrantCode = vagrantId.output.trim(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if ( !vagrantCode ) { |
34
|
|
|
process.stdout.write(chalk.bold.cyan("Vagrant server not found")+"\n"); |
35
|
|
|
|
36
|
|
|
shell.exec('./scripts/generatekey.sh'); |
37
|
|
|
shell.exec('./scripts/generateSSL.sh'); |
38
|
|
|
shell.exec('./scripts/roles_update.sh'); |
39
|
|
|
|
40
|
|
|
shell.cd('server/'); |
41
|
|
|
|
42
|
|
|
var upVagrant = shell.exec("vagrant up", {silent:true}); |
43
|
|
|
if ( upVagrant.code !== 0 ){ |
44
|
|
|
//ERRORE |
45
|
|
|
process.stderr.write(chalk.red("Errore: "+upVagrant.stderr+ " - "+upVagrant.output)); |
46
|
|
|
process.exit(1); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
process.stdout.write("Vagrant server UP.\n"); |
50
|
|
|
|
51
|
|
|
shell.echo('Install Server Required Package and Config'); |
52
|
|
|
var ansibleProc = shell.exec('ansible-playbook -i '+enviroment+'.hosts site.yml'); |
53
|
|
|
if ( ansibleProc.code !== 0 ){ |
54
|
|
|
//ERRORE |
55
|
|
|
process.stderr.write(chalk.red("Errore ... ")); |
56
|
|
|
process.exit(1); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
process.stdout.write("Vagrant server installation packages completed.\n"); |
60
|
|
|
|
61
|
|
|
shell.cd('..'); |
62
|
|
|
|
63
|
|
|
} else { |
64
|
|
|
process.stdout.write("Find vagrant server: "+vagrantCode+". Skip creation.\n"); |
65
|
|
|
// non funziona vagrant up by name or uuid |
66
|
|
|
// var upVagrant = shell.exec("vagrant up "+vagrantCode); |
67
|
|
|
|
68
|
|
|
shell.cd('server/'); |
69
|
|
|
|
70
|
|
|
var upVagrant = shell.exec("vagrant up", {silent:true}); |
|
|
|
|
71
|
|
|
if ( upVagrant.code !== 0 ){ |
72
|
|
|
//ERRORE |
73
|
|
|
process.stderr.write(chalk.red("Errore: "+upVagrant.stderr+ " - "+upVagrant.output)); |
74
|
|
|
process.exit(1); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
process.stdout.write("Vagrant server UP.\n"); |
78
|
|
|
|
79
|
|
|
shell.cd('..'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} else { |
83
|
|
|
|
84
|
|
|
shell.echo('Install Server Required Package and Config'); |
85
|
|
|
var ansibleProc = shell.exec('ansible-playbook -i '+enviroment+'.hosts site.yml', {silent:true}); |
|
|
|
|
86
|
|
|
if ( ansibleProc.code !== 0 ){ |
87
|
|
|
//ERRORE |
88
|
|
|
process.stderr.write(chalk.red("Errore ... ")); |
89
|
|
|
process.exit(1); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
shell.echo('Completed'); |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
}) |
97
|
|
|
.parse(process.argv); |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
if (!process.argv.slice(2).length) { |
101
|
|
|
program.outputHelp(make_red); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
function make_red(txt) { |
105
|
|
|
return chalk.red(txt); //display the help text in red on the console |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
//console.log(shell.pwd()); |
109
|
|
|
|