-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathConfigurate.php
125 lines (89 loc) · 3.31 KB
/
Configurate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace BaseReality\Tool;
require __DIR__.'/../vendor/autoload.php';
use Intahwebz\Configurator\Configurator;
class Configurate {
private $filesToGenerate;
private $environment;
private $inputDir;
private $outputDir;
function getRequiredArgs() {
return array('argCount' => 1 );
}
function setArg($position, $value) {
$allowedVars = array(
'amazonec2',
'macports',
'centos',
'centos_guest',
);
if (in_array($value, $allowedVars) == true){
$this->environment = $value;
}
else{
$errorMessage = "Environment [$value] not known.";
$separatorString = '';
foreach ($allowedVars as $allowedVar) {
$errorMessage .= $separatorString.$allowedVar;
$separatorString = ', ';
}
throw new \Exception($errorMessage);
}
$this->environment = $value;
}
function init(array $properties = array()) {
$this->inputDir = $properties['inputDir'];
$this->outputDir = $properties['outputDir'];
$this->filesToGenerate = array(
$this->inputDir.'data/conf/imageTaskRunner.conf.php' => $this->outputDir.'autogen/imageTaskRunner.conf',
$this->inputDir.'data/conf/libratoStats.conf.php' => $this->outputDir.'autogen/libratoStats.conf',
$this->inputDir.'data/conf/imagick.nginx.conf.php' => $this->outputDir.'autogen/imagick.nginx.conf',
$this->inputDir.'data/conf/imagick.php-fpm.conf.php' => $this->outputDir.'autogen/imagick.php-fpm.conf',
$this->inputDir.'data/conf/imagick-demos.php.ini.php' => $this->outputDir.'autogen/imagick-demos.php.ini',
$this->inputDir.'data/conf/addImagickConfig.sh.php' => $this->outputDir.'autogen/addImagickConfig.sh',
);
}
function main() {
$configurator = new Configurator();
if ($this->environment == null) {
throw new \Exception("Configurate does not have it's environment set.");
}
$configurator->addConfig($this->environment, "./deployConfig.php");
foreach($this->filesToGenerate as $inputFilename => $outputFilename){
$configFile = $configurator->configurate($inputFilename);
@mkdir(dirname($outputFilename), 0755, true);
$fileHandle = fopen($outputFilename, "w");
if($fileHandle === FALSE){
echo "Failed to read [".$outputFilename."] for writing.";
exit(-1);
}
fwrite($fileHandle, $configFile);
fclose($fileHandle);
}
\Intahwebz\Configurator\Functions::load();
convertToFPM(
$this->outputDir.'autogen/imagick-demos.php.ini',
$this->outputDir.'autogen/imagick-demos.php.fpm.ini'
);
}
}
$tool = new Configurate();
$properties = [];
$properties['inputDir'] = __DIR__.'/../';
$properties['outputDir'] = __DIR__.'/../';
if ($argc <= 1) {
echo "Please select a config from: ";
var_dump(array(
'amazonec2',
'macports',
'centos',
'centos_guest',
));
exit(0);
}
$config = $argv[1];
$tool->setArg(0, $config);
$tool->init(
$properties
);
$tool->main();