-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·165 lines (138 loc) · 5.48 KB
/
install
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/php
<?php
$installer = new Installer();
$installer->installProgram();
class Installer {
private $startDirectory;
private $titleData;
private $completionData;
private $bootStrapData;
private $programDataFolder;
private $programExecutorFolder;
private $programNameMachine = "ptdeploy";
private $programNameFriendly = "PTDeploy"; // 12 chars
public function __construct() {
$this->populateStartDirectory();
$this->populateTitle();
$this->populateCompletion();
$this->populateExecutorFile();
}
public function installProgram() {
$this->showTitle();
$this->askForProgramDataFolder();
$this->askForProgramExecutorFolder();
$this->deleteProgramDataFolderAsRootIfExists();
$this->makeProgramDataFolderIfNeeded();
$this->copyFilesToProgramDataFolder();
$this->deleteExecutorIfExists();
$this->saveExecutorFile();
$this->deleteInstallationFiles();
$this->changePermissions();
$this->showCompletion();
}
private function showTitle() {
print $this->titleData ;
}
private function showCompletion() {
print $this->completionData ;
}
private function askForProgramDataFolder() {
$question = 'What is the program data directory?';
$question .= ' Found "/opt/'.$this->programNameMachine.'" - use this? (Enter nothing for yes, no end slash)';
$input = self::askForInput($question);
$this->programDataFolder = ($input=="") ? "/opt/$this->programNameMachine" : $input ;
}
private function askForProgramExecutorFolder(){
$question = 'What is the program executor directory?';
$question .= ' Found "/usr/bin" - use this? (Enter nothing for yes, No Trailing Slash)';
$input = self::askForInput($question);
$this->programExecutorFolder = ($input=="") ? "/usr/bin" : $input ;
}
private function deleteProgramDataFolderAsRootIfExists(){
if ( is_dir($this->programDataFolder)) {
$command = 'rm -rf '.$this->programDataFolder;
self::executeAndOutput($command, "Program Data Folder $this->programDataFolder Deleted if existed"); }
return true;
}
private function makeProgramDataFolderIfNeeded(){
if (!file_exists($this->programDataFolder)) {
mkdir($this->programDataFolder, 0777, true); }
}
private function copyFilesToProgramDataFolder(){
$command = 'cp -r '.dirname(__FILE__).'/.* '.$this->programDataFolder;
self::executeAndOutput($command, "Program Data folder populated with hidden files");
$command = 'cp -r '.dirname(__FILE__).'/* '.$this->programDataFolder;
return self::executeAndOutput($command, "Program Data folder populated with other files");
}
private function deleteExecutorIfExists(){
$command = 'rm -f '.$this->programExecutorFolder.'/'.$this->programNameMachine;
self::executeAndOutput($command, "Program Executor Deleted if existed");
return true;
}
private function deleteInstallationFiles(){
$command = 'rm -rf '.$this->startDirectory.'/'.$this->programNameMachine;
self::executeAndOutput($command);
}
private function saveExecutorFile(){
$this->populateExecutorFile();
return file_put_contents($this->programExecutorFolder.'/'.$this->programNameMachine, $this->bootStrapData);
}
private function changePermissions(){
$command = "chmod -R 775 $this->programDataFolder";
self::executeAndOutput($command);
$command = "chmod 775 $this->programExecutorFolder/$this->programNameMachine";
self::executeAndOutput($command);
}
private function askForInput($question, $required=null) {
$fp = fopen('php://stdin', 'r');
$last_line = false;
while (!$last_line) {
print "$question\n";
$inputLine = fgets($fp, 1024);
if ($required && strlen($inputLine)==0 ) {
print "You must enter a value. Please try again.\n"; }
else {$last_line = true;} }
$inputLine = $this->stripNewLines($inputLine);
return $inputLine;
}
private function populateTitle() {
$this->titleData = <<<TITLE
*******************************
* Golden Contact Computing *
* $this->programNameFriendly *
*******************************
TITLE;
}
private function populateCompletion() {
$this->completionData = <<<COMPLETION
... All done!
*******************************
Thanks for installing , visit www.gcsoftshop.co.uk for more
COMPLETION;
}
private function populateExecutorFile() {
$this->bootStrapData = "#!/usr/bin/php\n
<?php\n
require('$this->programDataFolder/src/Bootstrap.php');\n
?>";
}
private function populateStartDirectory() {
$this->startDirectory = str_replace("/$this->programNameMachine", "", dirname(__FILE__));
}
private function stripNewLines($inputLine) {
$inputLine = str_replace("\n", "", $inputLine);
$inputLine = str_replace("\r", "", $inputLine);
return $inputLine;
}
private function executeAndOutput($command, $message=null) {
$outputArray = array();
exec($command, $outputArray);
$outputText = "";
foreach ($outputArray as $outputValue) {
$outputText .= "$outputValue\n"; }
if ($message !== null) {
$outputText .= "$message\n"; }
print $outputText;
return true;
}
}