| 1 |
liveuser |
1 |
#!/usr/bin/php
|
|
|
2 |
<?php
|
|
|
3 |
|
|
|
4 |
/*
|
| 464 |
liveuser |
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 621 |
liveuser |
6 |
Copyright (C) 2015~2024 Min-Jhin,Chen
|
| 1 |
liveuser |
7 |
|
| 464 |
liveuser |
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/*
|
|
|
26 |
|
| 1 |
liveuser |
27 |
目的:
|
|
|
28 |
解析兩個目標的差異
|
|
|
29 |
第一個參數放舊版本,第二個參數放新版本,第三個參數可以放要把新版本物件複製到的地方.
|
|
|
30 |
|
|
|
31 |
安裝:
|
|
|
32 |
複製到 /usr/bin 底下,給予執行的權限
|
|
|
33 |
|
|
|
34 |
example log file content input:
|
|
|
35 |
# diff -qr coolbee_v1.00.13-6 coolbee_v1.00.13-7
|
|
|
36 |
Files coolbee_v1.00.13-6/application/controllers/admin/rpc_server.php and coolbee_v1.00.13-7/application/controllers/admin/rpc_server.php differ
|
|
|
37 |
Files coolbee_v1.00.13-6/application/controllers/app.php and coolbee_v1.00.13-7/application/controllers/app.php differ
|
|
|
38 |
Files coolbee_v1.00.13-6/application/controllers/cron.php and coolbee_v1.00.13-7/application/controllers/cron.php differ
|
|
|
39 |
Files coolbee_v1.00.13-6/application/controllers/dut.php and coolbee_v1.00.13-7/application/controllers/dut.php differ
|
|
|
40 |
Files coolbee_v1.00.13-6/application/controllers/portal.php and coolbee_v1.00.13-7/application/controllers/portal.php differ
|
|
|
41 |
Files coolbee_v1.00.13-6/application/controllers/y5busServer.php and coolbee_v1.00.13-7/application/controllers/y5busServer.php differ
|
|
|
42 |
Files coolbee_v1.00.13-6/application/core/HL_Model.php and coolbee_v1.00.13-7/application/core/HL_Model.php differ
|
|
|
43 |
Files coolbee_v1.00.13-6/application/helpers/vps_helper.php and coolbee_v1.00.13-7/application/helpers/vps_helper.php differ
|
|
|
44 |
Files coolbee_v1.00.13-6/application/language/chinese_traditional/setting_lang.php and coolbee_v1.00.13-7/application/language/chinese_traditional/setting_lang.php differ
|
|
|
45 |
Files coolbee_v1.00.13-6/application/language/english/setting_lang.php and coolbee_v1.00.13-7/application/language/english/setting_lang.php differ
|
|
|
46 |
Files coolbee_v1.00.13-6/application/language/french/setting_lang.php and coolbee_v1.00.13-7/application/language/french/setting_lang.php differ
|
|
|
47 |
Files coolbee_v1.00.13-6/application/language/spanish/setting_lang.php and coolbee_v1.00.13-7/application/language/spanish/setting_lang.php differ
|
|
|
48 |
Files coolbee_v1.00.13-6/application/language/zh-CN/setting_lang.php and coolbee_v1.00.13-7/application/language/zh-CN/setting_lang.php differ
|
|
|
49 |
Files coolbee_v1.00.13-6/application/libraries/HL_Log.php and coolbee_v1.00.13-7/application/libraries/HL_Log.php differ
|
|
|
50 |
Files coolbee_v1.00.13-6/application/models/dut_m.php and coolbee_v1.00.13-7/application/models/dut_m.php differ
|
|
|
51 |
Only in coolbee_v1.00.13-7: indexExtend.php
|
|
|
52 |
Files coolbee_v1.00.13-6/index.php and coolbee_v1.00.13-7/index.php differ
|
|
|
53 |
Only in coolbee_v1.00.13-7: logAgent.php
|
|
|
54 |
Files coolbee_v1.00.13-6/NOTICE.txt and coolbee_v1.00.13-7/NOTICE.txt differ
|
|
|
55 |
Files coolbee_v1.00.13-6/Release Note(ITRI).txt and coolbee_v1.00.13-7/Release Note(ITRI).txt differ
|
|
|
56 |
Files coolbee_v1.00.13-6/Release Note(RD).txt and coolbee_v1.00.13-7/Release Note(RD).txt differ
|
|
|
57 |
Files coolbee_v1.00.13-6/Release Note.txt and coolbee_v1.00.13-7/Release Note.txt differ
|
|
|
58 |
Files coolbee_v1.00.13-6/system/core/Common.php and coolbee_v1.00.13-7/system/core/Common.php differ
|
|
|
59 |
Files coolbee_v1.00.13-6/system/libraries/Log.php and coolbee_v1.00.13-7/system/libraries/Log.php differ
|
|
|
60 |
*/
|
|
|
61 |
|
|
|
62 |
//check param
|
|
|
63 |
if($_SERVER['argc']<3)
|
|
|
64 |
{
|
|
|
65 |
help();
|
|
|
66 |
return false;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
//有差異的檔案清單於新版本的目錄.
|
|
|
70 |
$files=array();
|
|
|
71 |
|
|
|
72 |
//pasre params
|
|
|
73 |
$ov=$_SERVER['argv'][1];
|
|
|
74 |
$nv=$_SERVER['argv'][2];
|
|
|
75 |
|
|
|
76 |
//如果存在要複製新版本檔案到目的地的參數
|
|
|
77 |
if(isset($_SERVER['argv'][3]))
|
|
|
78 |
{
|
|
|
79 |
$cp2=$_SERVER['argv'][3];
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
$cmd="diff -qr ".$ov." ".$nv;
|
|
|
83 |
exec($cmd,$output,$status);
|
|
|
84 |
if($status!==1 && $status!==0)
|
|
|
85 |
{
|
|
|
86 |
echo "error occur!\r\n";
|
|
|
87 |
print_r($output);
|
|
|
88 |
exit;
|
|
|
89 |
}
|
|
|
90 |
foreach($output as $line)
|
|
|
91 |
{
|
|
|
92 |
//檔案有差異
|
|
|
93 |
//Files coolbee_v1.00.13-6/Release Note(RD).txt and coolbee_v1.00.13-7/Release Note(RD).txt differ
|
|
|
94 |
if(strpos($line,"Files ")!==false && strpos($line,"differ")!==false)
|
|
|
95 |
{
|
|
|
96 |
if(strpos($line,"Files ")!==0)
|
|
|
97 |
{
|
|
|
98 |
continue;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
if(strpos($line," and ")!==false)
|
|
|
102 |
{
|
|
|
103 |
$spiltedStr=explode(" and ",$line);
|
|
|
104 |
$spiltedStr[1]=str_replace($nv."/","",$spiltedStr[1]);
|
|
|
105 |
$files[]=str_replace(" differ","",$spiltedStr[1]);
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
//只有某個版本有這檔案
|
|
|
110 |
//Only in coolbee_v1.00.13-7: indexExtend.php
|
|
|
111 |
//Only in patch: application
|
|
|
112 |
$onlyIn=strpos($line,"Only in ");
|
|
|
113 |
if($onlyIn!==false)
|
|
|
114 |
{
|
|
|
115 |
if($onlyIn!==0)
|
|
|
116 |
{
|
|
|
117 |
continue;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
$nvk=strpos($line,$nv);
|
|
|
121 |
if($nvk!==false)
|
|
|
122 |
{
|
|
|
123 |
if($nvk!==8)
|
|
|
124 |
{
|
|
|
125 |
continue;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
#剔除開頭的 "Only in ".$nv
|
|
|
129 |
$key2replace="Only in ".$nv;
|
|
|
130 |
$line=str_replace($key2replace,'',$line);
|
|
|
131 |
|
|
|
132 |
#剔除開頭的 "/"
|
|
|
133 |
if(strpos($line,"/")===0)
|
|
|
134 |
{
|
|
|
135 |
$line=substr($line,1);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
#替換開頭的 ": " 為 "/"
|
|
|
139 |
if(strpos($line,": ")===0)
|
|
|
140 |
{
|
|
|
141 |
$line=substr($line,2);
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
#置換 ": " 為 "/"
|
|
|
145 |
$key2replace=": ";
|
|
|
146 |
$line=str_replace($key2replace,'/',$line);
|
|
|
147 |
|
|
|
148 |
#取得新檔案
|
|
|
149 |
$files[]=$line;
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
//output file, folders should be patch
|
|
|
155 |
echo "以下為新版本的物件:\r\n";
|
|
|
156 |
foreach($files as $item)
|
|
|
157 |
{
|
|
|
158 |
echo $item."\r\n";
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
//copy new version item to $cp2
|
|
|
162 |
if(isset($cp2))
|
|
|
163 |
{
|
|
|
164 |
echo "複製新版本物件到patch目錄(".$cp2."):\r\n";
|
|
|
165 |
|
|
|
166 |
#重新建立要複製到的目錄
|
|
|
167 |
if(!file_exists($cp2))
|
|
|
168 |
{
|
|
|
169 |
mkdir($cp2,0770,true);
|
|
|
170 |
}
|
|
|
171 |
else
|
|
|
172 |
{
|
|
|
173 |
while(true)
|
|
|
174 |
{
|
|
|
175 |
$cp2=$cp2."-".time();
|
|
|
176 |
if(!file_exists($cp2))
|
|
|
177 |
{
|
|
|
178 |
mkdir($cp2,0770,true);
|
|
|
179 |
break;
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
echo "要複製到的目標已存在,更名為:".$cp2.PHP_EOL;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
foreach($files as $item)
|
|
|
186 |
{
|
|
|
187 |
//如果新版本物件是在第一層
|
|
|
188 |
if(strpos($item,"/")===false)
|
|
|
189 |
{
|
|
|
190 |
//複製新物件
|
|
|
191 |
|
|
|
192 |
//如果是檔案
|
|
|
193 |
if(is_file($nv."/".$item))
|
|
|
194 |
{
|
|
|
195 |
$cmd="/usr/bin/cp '".$nv."/".$item."' '".$cp2."/".$item."'";
|
|
|
196 |
}
|
|
|
197 |
//反之如果是目錄
|
|
|
198 |
else if(is_dir($nv."/".$item))
|
|
|
199 |
{
|
|
|
200 |
$cmd="/usr/bin/cp -R '".$nv."/".$item."' '".$cp2."/".$item."'";
|
|
|
201 |
}
|
|
|
202 |
exec($cmd,$output,$status);
|
|
|
203 |
echo "exec ".$cmd."\r\n";
|
|
|
204 |
if($status!==0)
|
|
|
205 |
{
|
|
|
206 |
echo "error occur!\r\n";
|
|
|
207 |
print_r($output);
|
|
|
208 |
exit;
|
|
|
209 |
}
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
//反之新版本物件在更深層
|
|
|
213 |
else
|
|
|
214 |
{
|
|
|
215 |
//建立新物件的路徑
|
|
|
216 |
$path2add=$cp2;
|
|
|
217 |
$sourcePath=$nv;
|
|
|
218 |
$dirs=explode("/",$item);
|
|
|
219 |
$layers=count($dirs);
|
|
|
220 |
$nvf=$dirs[$layers-1];
|
|
|
221 |
$nvf=str_replace(": ","/",$nvf);
|
|
|
222 |
|
|
|
223 |
for($i=0;$i<$layers-1;$i++)
|
|
|
224 |
{
|
|
|
225 |
$path2add=$path2add."/".$dirs[$i];
|
|
|
226 |
$sourcePath=$sourcePath."/".$dirs[$i];
|
|
|
227 |
@mkdir($path2add,0770,true);
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
//複製新物件
|
|
|
231 |
if(is_file($sourcePath."/".$nvf))
|
|
|
232 |
{
|
|
|
233 |
$cmd="/usr/bin/cp '".$sourcePath."/".$nvf."' '".$path2add."/".$nvf."'";
|
|
|
234 |
}
|
|
|
235 |
else if(is_dir($sourcePath."/".$nvf))
|
|
|
236 |
{
|
|
|
237 |
$cmd="/usr/bin/cp -R '".$sourcePath."/".$nvf."' '".$path2add."/".$nvf."'";
|
|
|
238 |
}
|
|
|
239 |
else if(!file_exists($sourcePath."/".$nvf))
|
|
|
240 |
{
|
|
|
241 |
echo "error occur!\r\n";
|
|
|
242 |
echo "file ".$sourcePath."/".$nvf." not exist";
|
|
|
243 |
exit;
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
exec($cmd,$output,$status);
|
|
|
247 |
echo "exec ".$cmd."\r\n";
|
|
|
248 |
if($status!==0)
|
|
|
249 |
{
|
|
|
250 |
echo "error occur!\r\n";
|
|
|
251 |
print_r($output);
|
|
|
252 |
exit;
|
|
|
253 |
}
|
|
|
254 |
}
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
//help
|
|
|
259 |
function help()
|
|
|
260 |
{
|
|
|
261 |
echo "usage:\r\n";
|
|
|
262 |
echo __FILE__ ." [old version] [new version] [copy new version item to]\r\n";
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
?>
|