/
install
executable file
·126 lines (104 loc) · 2.8 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
#!/usr/bin/env php
<?php
/**
* Uses composer to install all dependencies required to run or test the
* project. Downloads composer if it doesn't already exist.
*
* PHP.Gt (http://php.gt)
* @copyright Copyright Ⓒ 2014 Bright Flair Ltd. (http://brightflair.com)
* @license Apache Version 2.0, January 2004. http://www.apache.org/licenses
*/
$HOME = $_SERVER["HOME"];
$gtDir = "$HOME/.gt";
$binDir = "$gtDir/PHP.Gt/bin";
$gtBinDir = "$gtDir/bin";
if(is_dir($gtDir)) {
exec("rm -rf $gtDir");
}
else {
mkdir($gtDir);
}
chdir($gtDir);
if(!file_exists("composer.phar")) {
echo "Installing composer..." . PHP_EOL;
$tempFile = "install-composer.php";
$installScript = @file_get_contents("https://getcomposer.org/installer");
if(!$installScript) {
echo("Failed installing composer. " . PHP_EOL
. "Are you connected to the internet?" . PHP_EOL);
exit(1);
}
file_put_contents($tempFile, $installScript);
passthru("php $tempFile", $composerReturn);
unlink($tempFile);
if($composerReturn != 0) {
echo("Something went wrong installing composer :(" . PHP_EOL);
}
}
passthru("./composer.phar create-project brightflair/php.gt PHP.Gt "
. "-s'dev' --keep-vcs", $installReturn);
if($installReturn != 0) {
echo("Something went wrong downloading PHP.Gt :(". PHP_EOL
. "Are you connected to the internet?" . PHP_EOL);
exit(1);
}
// OS-dependant stuff:
switch(PHP_OS) {
case "Darwin":
// OSX
// OSX does not load .bashrc, instead it loads .bash_profile...
// let's fix that.
$bashLoadScript = "$HOME/.bash_profile";
$bashExisting = "";
if(file_exists($bashLoadScript)) {
$bashExisting = file_get_contents($bashLoadScript);
}
if(!strstr($bashExisting, "#gt")) {
// TODO: Remove existing gt snippet rather than ignoring completely.
$bash = <<<BASH
#gt
[[ -s ~/.bashrc ]] && source ~/.bashrc
#gt-end
BASH;
file_put_contents($bashLoadScript, $bash, FILE_APPEND);
}
break;
default:
break;
}
if(!is_dir($gtBinDir)) {
mkdir($gtBinDir, 0775, true);
}
foreach (new DirectoryIterator($binDir) as $item) {
if($item->isDot()) {
continue;
}
$filename = $item->getFilename();
$pathname = $item->getPathname();
$linkname = "$gtBinDir/gt-$filename";
if(file_exists($linkname)) {
unlink($linkname);
}
symlink($pathname, $linkname);
}
$bashLoadScript = "$HOME/.bashrc";
$bashExisting = "";
if(file_exists($bashLoadScript)) {
$bashExisting = file_get_contents($bashLoadScript);
}
if(!strstr($bashExisting, "#gt")) {
// TODO: Remove existing gt snippet rather than ignoring completely.
// Add gtBinDir to path.
$bash = <<<BASH
#gt
if [[ ":\$PATH:" != *":$gtBinDir:"* ]]; then
PATH=\$PATH:$gtBinDir
export PATH
fi
#gt-end
BASH;
file_put_contents($bashLoadScript, $bash, FILE_APPEND);
}
echo PHP_EOL . "PHP.Gt successfully installed." . PHP_EOL
. "Restart your terminal to use gt-* commands." . PHP_EOL
. PHP_EOL;