Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 924 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/bin/php
<?php

/*

        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
    Copyright (C) 2015~2024 Min-Jhin,Chen

    This file is part of QBPWCF.

    QBPWCF is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QBPWCF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.

*/

/*
安裝方式:
將該檔案移動到 /usr/bin/ 底下

描述:
將特定路徑底下的 qcow2 映象轉換與壓縮,以便節省空間。
*/

#使用命名空間qbpwcf
namespace qbpwcf;

#取得 lib path
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);

#如果執行失敗
if($status!==0){

        #debug
        var_dump(__LINE__,$output);

        #結束執行,回傳shell 1.
        exit(1);

        }#if end

#儲存lib path
$folderOfUsrLib=$output[0];

#以該檔案的實際位置的 lib path 為 include path 首位
$output=array();
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);

#如果執行失敗
if($status!==0){

        #debug
        var_dump(__LINE__,$output);

        #結束執行,回傳shell 1.
        exit(1);

        }#if end

#設置 include path 
set_include_path($output[0].PATH_SEPARATOR.get_include_path());

#匯入外部套件
include("allInOne.php");

#如果參數只有1個
if($_SERVER["argc"]===1){

        #函式說明:
        #印出多行文字,結尾自動換行.
        #回傳的結果:
        #$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
        #$result["function"],當前執行的函數名稱.
        #$result["error"],錯誤訊息陣列.
        #必填的參數:
        #$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
        $conf["outputStringArray"][]="Description: convent and compress qcow2 image(s) in searched path.";
        $conf["outputStringArray"][]="Usage: ".$_SERVER["PHP_SELF"]." [search path]";
        $echoMultiLine=cmd::echoMultiLine($conf);
        unset($conf);

        #如果解析內容失敗
        if($echoMultiLine["status"]==="false"){

                #印出結果
                var_dump($echoMultiLine);

                #結束程式
                exit;

                }#if end

        #結束程式
        exit;

        }#if end

#涵式說明:
#尋找指定路徑下的虛擬硬碟,將之重新轉換與壓縮,再取掉代原有的檔案.
#回傳結果:
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
#$result["error"],錯誤訊息.
#$result["function"],當前執行的函數名稱.
#$result["argu"],所使用的參數.
#$result["found"],是否有找到可以轉換的檔案,"true"代表有;"false"代表沒有.
#$result["content"],有改變的虛擬硬碟位置字串陣列.
#必填參數:
#$conf["path"],字串,虛擬硬碟檔案的搜尋路徑.
$conf["path"]=$_SERVER["argv"][1];
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
#$conf["fileArgu"]=$_SERVER["PWD"]."/".basename(__FILE__);
$conf["fileArgu"]=__FILE__;
#備註:
#目前只支援qcow2格式的虛擬硬碟
$imgConvert=qemu::imgConvert($conf);
unset($conf);

#如果轉換失敗
if($imgConvert["status"]==="false"){

        #印出結果
        var_dump($imgConvert);

        #結束程式
        exit;

        }#if end

#函式說明:
#印出多行文字,結尾自動換行.
#回傳的結果:
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
#$result["function"],當前執行的函數名稱.
#$result["error"],錯誤訊息陣列.
#必填的參數:
#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
$conf["outputStringArray"][]="Complete convert and compress qcow2 image(s) in searched path: ".$_SERVER["argv"][1];
$echoMultiLine=cmd::echoMultiLine($conf);
unset($conf);

#如果解析內容失敗
if($echoMultiLine["status"]==="false"){

        #印出結果
        var_dump($echoMultiLine);

        #結束程式
        exit;

        }#if end

?>