'install', 'cache-dir' => 'd:/dist-cache/', 'tool-dir' => '', //'oss-host' => 'http://distribute-helper.oss-cn-hangzhou.aliyuncs.com', 'oss-host' => 'http://192.168.3.10:8996', 'mysql-host'=> '', ); } //解析部署配置文件 function loadConfig($cfgPath){ $config = json_decode(file_get_contents($cfgPath), true); if(!$config){ logError("failed to decode config file",$cfgPath); return false; } if(! $config['distribute-mode']){ logError("distribute-mode node not exists"); return false; } if(! $config['cache-dir'] ){ logError("cache-dir node not exists"); return false; } return $config; } //多线程下载文件 function downloadToDir($toolDir,$ossHost,$repoName,$fileName,$targetDir){ if (!file_exists($targetDir)){ mkdir($targetDir,0777,true); } $targetPath = pathJoin($targetDir,$fileName); if( file_exists($targetPath) ) { return $targetPath; } $gopeed = getGoPeedPath($toolDir); $remoteUrl = pathJoin($ossHost,$repoName,$fileName); $cmd = $gopeed." -D=" . $targetDir . " " . $remoteUrl; system($cmd, $ret); if ($ret != 0) { return false; } return $targetPath; } //解压缩文件 function unzipFile($toolDir,$zipFile, $targetDir){ $fileExt = getFileExt($zipFile); if($fileExt == "zip"){ $zip= new \ZipArchive; if($zip->open($zipFile)==true){ $zip->extractTo($targetDir); $zip->close(); return true; } else{ return false; } } if($fileExt == "7z"){ $sevenZip = get7ZipPath($toolDir); $logPath = $zipFile . '.log'; $cmd = $sevenZip . " x $zipFile -o$targetDir -aoa > " . $logPath; system($cmd, $ret); if ($ret != 0) { return false; } return true; } return false; }