Subversion Repositories php-qbpwcf

Rev

Rev 226 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
/*
5
 
6
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
7
    Copyright (C) 2015~2024 Min-Jhin,Chen
8
 
9
    This file is part of QBPWCF.
10
 
11
    QBPWCF is free software: you can redistribute it and/or modify
12
    it under the terms of the GNU General Public License as published by
13
    the Free Software Foundation, either version 3 of the License, or
14
    (at your option) any later version.
15
 
16
    QBPWCF is distributed in the hope that it will be useful,
17
    but WITHOUT ANY WARRANTY; without even the implied warranty of
18
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
    GNU General Public License for more details.
20
 
21
    You should have received a copy of the GNU General Public License
22
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
23
 
24
*/
25
 
26
/*
27
安裝方式:
28
將該檔案移動到 /usr/bin/ 底下
29
 
30
描述:
31
將特定路徑底下的 qcow2 映象轉換與壓縮,以便節省空間。
32
*/
33
 
34
#使用命名空間qbpwcf
35
namespace qbpwcf;
36
 
37
#取得 lib path
38
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
39
 
40
#如果執行失敗
41
if($status!==0){
42
 
43
	#debug
44
	var_dump(__LINE__,$output);
45
 
46
	#結束執行,回傳shell 1.
47
	exit(1);
48
 
49
	}#if end
50
 
51
#儲存lib path
52
$folderOfUsrLib=$output[0];
53
 
54
#以該檔案的實際位置的 lib path 為 include path 首位
55
$output=array();
56
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
57
 
58
#如果執行失敗
59
if($status!==0){
60
 
61
	#debug
62
	var_dump(__LINE__,$output);
63
 
64
	#結束執行,回傳shell 1.
65
	exit(1);
66
 
67
	}#if end
68
 
69
#設置 include path 
70
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
71
 
72
#匯入外部套件
73
include("allInOne.php");
74
 
75
#如果參數只有1個
76
if($_SERVER["argc"]===1){
77
 
78
	#函式說明:
79
	#印出多行文字,結尾自動換行.
80
	#回傳的結果:
81
	#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
82
	#$result["function"],當前執行的函數名稱.
83
	#$result["error"],錯誤訊息陣列.
84
	#必填的參數:
85
	#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
86
	$conf["outputStringArray"][]="Description: convent and compress qcow2 image(s) in searched path.";
87
	$conf["outputStringArray"][]="Usage: ".$_SERVER["PHP_SELF"]." [search path]";
88
	$echoMultiLine=cmd::echoMultiLine($conf);
89
	unset($conf);
90
 
91
	#如果解析內容失敗
92
	if($echoMultiLine["status"]==="false"){
93
 
94
		#印出結果
95
		var_dump($echoMultiLine);
96
 
97
		#結束程式
98
		exit;
99
 
100
		}#if end
101
 
102
	#結束程式
103
	exit;
104
 
105
	}#if end
106
 
107
#涵式說明:
108
#尋找指定路徑下的虛擬硬碟,將之重新轉換與壓縮,再取掉代原有的檔案.
109
#回傳結果:
110
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
111
#$result["error"],錯誤訊息.
112
#$result["function"],當前執行的函數名稱.
113
#$result["argu"],所使用的參數.
114
#$result["found"],是否有找到可以轉換的檔案,"true"代表有;"false"代表沒有.
115
#$result["content"],有改變的虛擬硬碟位置字串陣列.
116
#必填參數:
117
#$conf["path"],字串,虛擬硬碟檔案的搜尋路徑.
118
$conf["path"]=$_SERVER["argv"][1];
119
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
120
#$conf["fileArgu"]=$_SERVER["PWD"]."/".basename(__FILE__);
121
$conf["fileArgu"]=__FILE__;
122
#備註:
123
#目前只支援qcow2格式的虛擬硬碟
124
$imgConvert=qemu::imgConvert($conf);
125
unset($conf);
126
 
127
#如果轉換失敗
128
if($imgConvert["status"]==="false"){
129
 
130
	#印出結果
131
	var_dump($imgConvert);
132
 
133
	#結束程式
134
	exit;
135
 
136
	}#if end
137
 
138
#函式說明:
139
#印出多行文字,結尾自動換行.
140
#回傳的結果:
141
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
142
#$result["function"],當前執行的函數名稱.
143
#$result["error"],錯誤訊息陣列.
144
#必填的參數:
145
#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
146
$conf["outputStringArray"][]="Complete convert and compress qcow2 image(s) in searched path: ".$_SERVER["argv"][1];
147
$echoMultiLine=cmd::echoMultiLine($conf);
148
unset($conf);
149
 
150
#如果解析內容失敗
151
if($echoMultiLine["status"]==="false"){
152
 
153
	#印出結果
154
	var_dump($echoMultiLine);
155
 
156
	#結束程式
157
	exit;
158
 
159
	}#if end
160
 
161
?>