-
Notifications
You must be signed in to change notification settings - Fork 5
/
make
executable file
·130 lines (94 loc) · 2.38 KB
/
make
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
#!/usr/bin/php
<?php
/**
* @author Alessandro Garcez <dev@alessandrogarcez.com.br>
* @copyright (c) 2014, Alessandro Garcez
* @version 1.0.0
*/
require 'defines.inc.php';
$buildroot = getUserHomePath() . '/BUILD/PHARS';
$sourcename = NAME . '-' . SOURCEVERSION . '.phar';
define('BUILDROOT', $buildroot);
define('SOURCE', $sourcename);
define('SOURCEPATH', BUILDROOT . '/' . SOURCE);
main($argc, $argv);
function main($argc, $argv) {
$option = ($argc > 1) ? $argv[1] : '';
switch ($option) {
case 'installer':
generateInstaller();
break;
case '--help':
showHelp();
break;
default:
showHelp();
break;
}
}
function showHelp() {
echo '
./make [option]
installer to build a package for installation.
--help show help
';
}
function generateInstaller() {
createBuildPath();
if (existsSource()) {
echo "Package already exists, please update the version.\n ";
return false;
}
createPharFile();
}
function createBuildPath() {
if (!is_dir(BUILDROOT)) {
mkdir(BUILDROOT, 0777, true);
}
}
function getUserHomePath() {
$usr_id = posix_getuid();
$usr = posix_getpwuid($usr_id);
return $usr['dir'];
}
function createPharFile() {
$phar = new Phar(SOURCEPATH, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, SOURCE);
packageFiles($phar, PROJECTFOLDER);
$phar->setStub($phar->createDefaultStub("install"));
echo "####################\ncreated ".SOURCEPATH."\n####################\n";
return true;
}
function existsSource() {
if (file_exists(SOURCEPATH)) {
return true;
} else {
return false;
}
}
function packageFiles($phar, $path = '.', $level = 0) {
$ignore = explode('|', IGNOREDFILES);
array_push($ignore, 'make');
$confs = explode('|', CONFS);
$dh = opendir($path);
while (false !== ( $file = readdir($dh) )) {
$is_conf = false;
if (!in_array($file, $ignore)) {
$fullpath = $path . '/' . $file;
if (in_array($file, $confs) || in_array($fullpath, $confs)) {
$is_conf = true;
$file = $file . '.new';
}
if (is_dir($fullpath)) {
packageFiles($phar, $fullpath, ($level + 1));
} else {
echo "Coping " . $fullpath . "\n";
$str_file_index = $str_file = str_replace(PROJECTFOLDER . '/', '', $fullpath);
if($is_conf) {
$str_file_index = $str_file.'.new';
}
$phar[$str_file_index] = file_get_contents(PROJECTFOLDER . '/' . $str_file);
}
}
}
closedir($dh);
}