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
| #!/usr/bin/env php
<?php
$kebab = array('kebab-project',
dirname(__FILE__) . '/www',
'git@github.com:kebab-project/kebab-project.git',
'origin/HEAD');
$extjs = array('extjs',
dirname(__FILE__) . '/www/web/assets/vendors',
'git@github.com:kebab-project/vendor-extjs.git',
'origin/HEAD');
Menu::show();
switch (Menu::getLine()) {
case 'K':
echo "You want to install Kebab Project\n";
Installer::install($kebab);
break;
case "E":
echo "You want to install ExtJS\n";
Installer::install($extjs);
break;
default:
echo "\033[31mWrong choice\033[37m\r\n";
}
class Menu
{
public static function show()
{
echo "What do you install? \n"
. "K - Kebab \n"
. "E - Extjs \n";
}
public static function getLine()
{
$handle = fopen ("php://stdin","r");
return trim(fgets($handle));
}
public static function isYes($input)
{
return in_array($input, array('YES', 'Yes', 'yes', 'Y', 'y', 'OK', 'Ok', 1));
}
public static function isNo($input)
{
return in_array($input, array('NO', 'No', 'no', 'N', 'n', 0));
}
}
class Installer
{
public static function install($data)
{
list($name, $path, $url, $branch) = $data;
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
echo "> Installing $name \n";
if (!is_dir($path . '/.git')) {
system(sprintf('git clone %s %s', escapeshellarg($url), escapeshellarg($path)));
}
system(sprintf('cd %s && git fetch origin && git reset --hard %s', escapeshellarg($path), escapeshellarg($branch)));
echo "> $name is installed correctly. Do you want to delete the .git folder? \n"
. "Yes \n";
if (Menu::isYes(Menu::getLine())) {
system(sprintf('rm -R -f %s/.git', escapeshellarg($path)));
echo '.git folder is deleted \n';
}
}
}
|