| 1 |
liveuser |
1 |
#!/bin/php
|
|
|
2 |
<?php
|
|
|
3 |
|
|
|
4 |
/*
|
|
|
5 |
|
|
|
6 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 621 |
liveuser |
7 |
Copyright (C) 2015~2024 Min-Jhin,Chen
|
| 1 |
liveuser |
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 |
|
| 466 |
liveuser |
37 |
#以該檔案的實際位置的 lib path 為 include path 首位
|
| 924 |
liveuser |
38 |
exec("cd ".pathinfo(__FILE__)["dirname"]."/../lib/qbpwcf;pwd;",$output,$status);
|
| 466 |
liveuser |
39 |
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
|
|
|
40 |
|
| 464 |
liveuser |
41 |
#匯入外部套件
|
| 466 |
liveuser |
42 |
include("allInOne.php");
|
| 1 |
liveuser |
43 |
|
|
|
44 |
#如果參數只有1個
|
|
|
45 |
if($_SERVER["argc"]===1){
|
|
|
46 |
|
|
|
47 |
#函式說明:
|
|
|
48 |
#印出多行文字,結尾自動換行.
|
|
|
49 |
#回傳的結果:
|
|
|
50 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
51 |
#$result["function"],當前執行的函數名稱.
|
|
|
52 |
#$result["error"],錯誤訊息陣列.
|
|
|
53 |
#必填的參數:
|
|
|
54 |
#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
|
|
|
55 |
$conf["outputStringArray"][]="Description: convent and compress qcow2 image(s) in searched path.";
|
|
|
56 |
$conf["outputStringArray"][]="Usage: ".$_SERVER["PHP_SELF"]." [search path]";
|
|
|
57 |
$echoMultiLine=cmd::echoMultiLine($conf);
|
|
|
58 |
unset($conf);
|
|
|
59 |
|
|
|
60 |
#如果解析內容失敗
|
|
|
61 |
if($echoMultiLine["status"]==="false"){
|
|
|
62 |
|
|
|
63 |
#印出結果
|
|
|
64 |
var_dump($echoMultiLine);
|
|
|
65 |
|
|
|
66 |
#結束程式
|
|
|
67 |
exit;
|
|
|
68 |
|
|
|
69 |
}#if end
|
|
|
70 |
|
|
|
71 |
#結束程式
|
|
|
72 |
exit;
|
|
|
73 |
|
|
|
74 |
}#if end
|
|
|
75 |
|
|
|
76 |
#涵式說明:
|
|
|
77 |
#尋找指定路徑下的虛擬硬碟,將之重新轉換與壓縮,再取掉代原有的檔案.
|
|
|
78 |
#回傳結果:
|
|
|
79 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
80 |
#$result["error"],錯誤訊息.
|
|
|
81 |
#$result["function"],當前執行的函數名稱.
|
|
|
82 |
#$result["argu"],所使用的參數.
|
|
|
83 |
#$result["found"],是否有找到可以轉換的檔案,"true"代表有;"false"代表沒有.
|
|
|
84 |
#$result["content"],有改變的虛擬硬碟位置字串陣列.
|
|
|
85 |
#必填參數:
|
|
|
86 |
#$conf["path"],字串,虛擬硬碟檔案的搜尋路徑.
|
|
|
87 |
$conf["path"]=$_SERVER["argv"][1];
|
|
|
88 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
89 |
#$conf["fileArgu"]=$_SERVER["PWD"]."/".basename(__FILE__);
|
|
|
90 |
$conf["fileArgu"]=__FILE__;
|
|
|
91 |
#備註:
|
|
|
92 |
#目前只支援qcow2格式的虛擬硬碟
|
|
|
93 |
$imgConvert=qemu::imgConvert($conf);
|
|
|
94 |
unset($conf);
|
|
|
95 |
|
|
|
96 |
#如果轉換失敗
|
|
|
97 |
if($imgConvert["status"]==="false"){
|
|
|
98 |
|
|
|
99 |
#印出結果
|
|
|
100 |
var_dump($imgConvert);
|
|
|
101 |
|
|
|
102 |
#結束程式
|
|
|
103 |
exit;
|
|
|
104 |
|
|
|
105 |
}#if end
|
|
|
106 |
|
|
|
107 |
#函式說明:
|
|
|
108 |
#印出多行文字,結尾自動換行.
|
|
|
109 |
#回傳的結果:
|
|
|
110 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
111 |
#$result["function"],當前執行的函數名稱.
|
|
|
112 |
#$result["error"],錯誤訊息陣列.
|
|
|
113 |
#必填的參數:
|
|
|
114 |
#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
|
|
|
115 |
$conf["outputStringArray"][]="Complete convert and compress qcow2 image(s) in searched path: ".$_SERVER["argv"][1];
|
|
|
116 |
$echoMultiLine=cmd::echoMultiLine($conf);
|
|
|
117 |
unset($conf);
|
|
|
118 |
|
|
|
119 |
#如果解析內容失敗
|
|
|
120 |
if($echoMultiLine["status"]==="false"){
|
|
|
121 |
|
|
|
122 |
#印出結果
|
|
|
123 |
var_dump($echoMultiLine);
|
|
|
124 |
|
|
|
125 |
#結束程式
|
|
|
126 |
exit;
|
|
|
127 |
|
|
|
128 |
}#if end
|
|
|
129 |
|
|
|
130 |
?>
|