Subversion Repositories php-qbpwcf

Rev

Rev 3 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 226
Line 1... Line 1...
1
#!/usr/bin/php
1
#!/usr/bin/php
2
<?php
2
<?php
3
 
3
 
4
/*
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2024 Min-Jhin,Chen
6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
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
11
    it under the terms of the GNU General Public License as published by
Line 17... Line 17...
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
18
    GNU General Public License for more details.
19
 
19
 
20
    You should have received a copy of the GNU General Public License
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/>.
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
    
22
 
23
*/
23
*/
24
 
24
 
25
/*
25
/*
26
 
26
 
27
目的:
27
目的:
Line 30... Line 30...
30
 
30
 
31
安裝:
31
安裝:
32
複製到 /usr/bin 底下,給予執行的權限
32
複製到 /usr/bin 底下,給予執行的權限
33
 
33
 
34
example log file content input:
34
example log file content input:
35
# diff -qr coolbee_v1.00.13-6 coolbee_v1.00.13-7 
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
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
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
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
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
40
Files coolbee_v1.00.13-6/application/controllers/portal.php and coolbee_v1.00.13-7/application/controllers/portal.php differ
Line 95... Line 95...
95
	{
95
	{
96
		if(strpos($line,"Files ")!==0)
96
		if(strpos($line,"Files ")!==0)
97
		{
97
		{
98
			continue;
98
			continue;
99
		}
99
		}
100
		
100
 
101
		if(strpos($line," and ")!==false)
101
		if(strpos($line," and ")!==false)
102
		{
102
		{
103
			$spiltedStr=explode(" and ",$line);
103
			$spiltedStr=explode(" and ",$line);
104
			$spiltedStr[1]=str_replace($nv."/","",$spiltedStr[1]);			
104
			$spiltedStr[1]=str_replace($nv."/","",$spiltedStr[1]);
105
			$files[]=str_replace(" differ","",$spiltedStr[1]);			
105
			$files[]=str_replace(" differ","",$spiltedStr[1]);
106
		}
106
		}
107
	}
107
	}
108
	
108
 
109
	//只有某個版本有這檔案
109
	//只有某個版本有這檔案
110
	//Only in coolbee_v1.00.13-7: indexExtend.php
110
	//Only in coolbee_v1.00.13-7: indexExtend.php
111
	//Only in patch: application
111
	//Only in patch: application
112
	$onlyIn=strpos($line,"Only in ");
112
	$onlyIn=strpos($line,"Only in ");
113
	if($onlyIn!==false)
113
	if($onlyIn!==false)
114
	{
114
	{
115
		if($onlyIn!==0)
115
		if($onlyIn!==0)
116
		{
116
		{
117
			continue;
117
			continue;
118
		}
118
		}
119
		
119
 
120
		$nvk=strpos($line,$nv);
120
		$nvk=strpos($line,$nv);
121
		if($nvk!==false)
121
		if($nvk!==false)
122
		{
122
		{
123
			if($nvk!==8)
123
			if($nvk!==8)
124
			{
124
			{
125
				continue;
125
				continue;
126
			}
126
			}
127
			
127
 
128
			#剔除開頭的 "Only in ".$nv
128
			#剔除開頭的 "Only in ".$nv
129
			$key2replace="Only in ".$nv;
129
			$key2replace="Only in ".$nv;
130
			$line=str_replace($key2replace,'',$line);
130
			$line=str_replace($key2replace,'',$line);
131
			
131
 
132
			#剔除開頭的 "/"
132
			#剔除開頭的 "/"
133
			if(strpos($line,"/")===0)
133
			if(strpos($line,"/")===0)
134
			{
134
			{
135
				$line=substr($line,1);	
135
				$line=substr($line,1);
136
			} 
136
			}
137
			
137
 
138
			#替換開頭的 ": " 為 "/"
138
			#替換開頭的 ": " 為 "/"
139
			if(strpos($line,": ")===0)
139
			if(strpos($line,": ")===0)
140
			{
140
			{
141
				$line=substr($line,2);	
141
				$line=substr($line,2);
142
			} 
142
			}
143
			
143
 
144
			#置換 ": " 為 "/"
144
			#置換 ": " 為 "/"
145
			$key2replace=": ";
145
			$key2replace=": ";
146
			$line=str_replace($key2replace,'/',$line);
146
			$line=str_replace($key2replace,'/',$line);
147
			
147
 
148
			#取得新檔案
148
			#取得新檔案
149
			$files[]=$line;
149
			$files[]=$line;
150
		}
150
		}
151
	}	
151
	}
152
}
152
}
153
 
153
 
154
//output file, folders should be patch
154
//output file, folders should be patch
155
echo "以下為新版本的物件:\r\n";
155
echo "以下為新版本的物件:\r\n";
156
foreach($files as $item)
156
foreach($files as $item)
Line 160... Line 160...
160
 
160
 
161
//copy new version item to $cp2
161
//copy new version item to $cp2
162
if(isset($cp2))
162
if(isset($cp2))
163
{
163
{
164
	echo "複製新版本物件到patch目錄(".$cp2."):\r\n";
164
	echo "複製新版本物件到patch目錄(".$cp2."):\r\n";
165
	
165
 
166
	#重新建立要複製到的目錄
166
	#重新建立要複製到的目錄
167
	if(!file_exists($cp2))
167
	if(!file_exists($cp2))
168
	{
168
	{
169
		mkdir($cp2,0770,true);
169
		mkdir($cp2,0770,true);
170
	}
170
	}
Line 179... Line 179...
179
				break;
179
				break;
180
			}
180
			}
181
		}
181
		}
182
		echo "要複製到的目標已存在,更名為:".$cp2.PHP_EOL;
182
		echo "要複製到的目標已存在,更名為:".$cp2.PHP_EOL;
183
	}
183
	}
184
	
184
 
185
	foreach($files as $item)
185
	foreach($files as $item)
186
	{
186
	{
187
		//如果新版本物件是在第一層
187
		//如果新版本物件是在第一層
188
		if(strpos($item,"/")===false)
188
		if(strpos($item,"/")===false)
189
		{
189
		{
190
			//複製新物件
190
			//複製新物件
191
			
191
 
192
			//如果是檔案
192
			//如果是檔案
193
			if(is_file($nv."/".$item))
193
			if(is_file($nv."/".$item))
194
			{
194
			{
195
				$cmd="/usr/bin/cp '".$nv."/".$item."' '".$cp2."/".$item."'";
195
				$cmd="/usr/bin/cp '".$nv."/".$item."' '".$cp2."/".$item."'";
196
			}
196
			}
Line 206... Line 206...
206
				echo "error occur!\r\n";
206
				echo "error occur!\r\n";
207
				print_r($output);
207
				print_r($output);
208
				exit;
208
				exit;
209
			}
209
			}
210
		}
210
		}
211
		
211
 
212
		//反之新版本物件在更深層
212
		//反之新版本物件在更深層
213
		else
213
		else
214
		{
214
		{
215
			//建立新物件的路徑
215
			//建立新物件的路徑
216
			$path2add=$cp2;
216
			$path2add=$cp2;
217
			$sourcePath=$nv;				
217
			$sourcePath=$nv;
218
			$dirs=explode("/",$item);
218
			$dirs=explode("/",$item);
219
			$layers=count($dirs);
219
			$layers=count($dirs);
220
			$nvf=$dirs[$layers-1];
220
			$nvf=$dirs[$layers-1];
221
			$nvf=str_replace(": ","/",$nvf);
221
			$nvf=str_replace(": ","/",$nvf);
222
			
222
 
223
			for($i=0;$i<$layers-1;$i++)
223
			for($i=0;$i<$layers-1;$i++)
224
			{
224
			{
225
				$path2add=$path2add."/".$dirs[$i];
225
				$path2add=$path2add."/".$dirs[$i];
226
				$sourcePath=$sourcePath."/".$dirs[$i];				
226
				$sourcePath=$sourcePath."/".$dirs[$i];
227
				@mkdir($path2add,0770,true);
227
				@mkdir($path2add,0770,true);
228
			}
228
			}
229
			
229
 
230
			//複製新物件
230
			//複製新物件
231
			if(is_file($sourcePath."/".$nvf))
231
			if(is_file($sourcePath."/".$nvf))
232
			{
232
			{
233
				$cmd="/usr/bin/cp '".$sourcePath."/".$nvf."' '".$path2add."/".$nvf."'";
233
				$cmd="/usr/bin/cp '".$sourcePath."/".$nvf."' '".$path2add."/".$nvf."'";
234
			}
234
			}
Line 240... Line 240...
240
			{
240
			{
241
				echo "error occur!\r\n";
241
				echo "error occur!\r\n";
242
				echo "file ".$sourcePath."/".$nvf." not exist";
242
				echo "file ".$sourcePath."/".$nvf." not exist";
243
				exit;
243
				exit;
244
			}
244
			}
245
			
245
 
246
			exec($cmd,$output,$status);
246
			exec($cmd,$output,$status);
247
			echo "exec ".$cmd."\r\n";
247
			echo "exec ".$cmd."\r\n";
248
			if($status!==0)
248
			if($status!==0)
249
			{				
249
			{
250
				echo "error occur!\r\n";
250
				echo "error occur!\r\n";
251
				print_r($output);
251
				print_r($output);
252
				exit;
252
				exit;
253
			}
253
			}
254
		}
254
		}