-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from jingjingxyk/feature_downloadbox
Feature downloadbox
- Loading branch information
Showing
8 changed files
with
270 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
set -exu | ||
__DIR__=$( | ||
cd "$(dirname "$0")" | ||
pwd | ||
) | ||
__PROJECT__=$( | ||
cd ${__DIR__}/../../ | ||
pwd | ||
) | ||
cd ${__PROJECT__} | ||
|
||
|
||
mkdir -p ${__PROJECT__}/var/ | ||
|
||
cd ${__PROJECT__}/var/ | ||
|
||
|
||
test -f download_library_use_git.sh && bash download_library_use_git.sh | ||
test -f download_extension_use_git.sh && bash download_extension_use_git.sh | ||
|
||
|
||
cd ${__PROJECT__} | ||
|
||
mkdir -p pool/lib | ||
mkdir -p pool/ext | ||
|
||
# cp -rf ${__PROJECT__}/var/download/* ${__PROJECT__}/pool/lib | ||
|
||
awk 'BEGIN { cmd="cp -ri var/libraries/* pool/lib" ; print "n" |cmd; }' | ||
awk 'BEGIN { cmd="cp -ri var/extensions/* pool/ext"; print "n" |cmd; }' | ||
|
||
cd ${__PROJECT__} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SwooleCli; | ||
|
||
trait DownloadBoxTrait | ||
{ | ||
|
||
protected function generateLibraryDownloadLinks(): void | ||
{ | ||
$this->mkdirIfNotExists($this->getWorkDir() . '/var/', 0755, true); | ||
$download_urls = []; | ||
foreach ($this->libraryList as $item) { | ||
if (empty($item->url) || $item->enableDownloadScript) { | ||
continue; | ||
} | ||
$url = ''; | ||
$item->mirrorUrls[] = $item->url; | ||
if (!empty($item->mirrorUrls)) { | ||
$newMirrorUrls = []; | ||
foreach ($item->mirrorUrls as $value) { | ||
$newMirrorUrls[] = trim($value); | ||
} | ||
$url = implode("\t", $newMirrorUrls); | ||
} | ||
$download_urls[] = $url . PHP_EOL . " out=" . $item->file; | ||
} | ||
file_put_contents($this->getWorkDir() . '/var/download_library_urls.txt', implode(PHP_EOL, $download_urls)); | ||
|
||
$download_urls = []; | ||
foreach ($this->extensionMap as $item) { | ||
if (empty($item->peclVersion) || $item->enableDownloadScript) { | ||
continue; | ||
} | ||
$item->file = $item->name . '-' . $item->peclVersion . '.tgz'; | ||
$item->path = $this->extensionDir . '/' . $item->file; | ||
$item->url = "https://pecl.php.net/get/{$item->file}"; | ||
$download_urls[] = $item->url . PHP_EOL . " out=" . $item->file; | ||
} | ||
file_put_contents($this->getWorkDir() . '/var/download_extension_urls.txt', implode(PHP_EOL, $download_urls)); | ||
|
||
|
||
$shell_cmd_header = <<<'EOF' | ||
#!/bin/bash | ||
set -exu | ||
__DIR__=$( | ||
cd "$(dirname "$0")" | ||
pwd | ||
) | ||
cd ${__DIR__} | ||
mkdir -p ${__DIR__}/var/tmp | ||
mkdir -p ${__DIR__}/libraries | ||
mkdir -p ${__DIR__}/extensions | ||
|
||
EOF; | ||
|
||
$download_scripts = []; | ||
foreach ($this->libraryList as $item) { | ||
if (!$item->enableDownloadScript) { | ||
continue; | ||
} | ||
if (empty($item->file)) { | ||
$item->file = $item->name . '.tar.gz'; | ||
} | ||
$cacheDir = '${__DIR__}/var/tmp'; | ||
$workDir = '${__DIR__}/var'; | ||
$downloadScript = <<<EOF | ||
mkdir -p {$cacheDir} | ||
cd {$cacheDir} | ||
test -d {$item->downloadDirName} && rm -rf {$item->downloadDirName} | ||
{$item->downloadScript} | ||
cd {$item->downloadDirName} | ||
test -f {$workDir}/libraries/{$item->file} || tar -czf {$workDir}/{$item->file} ./ | ||
cp -f {$workDir}/{$item->file} "\${__DIR__}/libraries/" | ||
cd {$workDir} | ||
EOF; | ||
|
||
$download_scripts[] = $downloadScript . PHP_EOL; | ||
} | ||
file_put_contents( | ||
$this->getWorkDir() . '/var/download_library_use_git.sh', | ||
$shell_cmd_header . PHP_EOL . implode(PHP_EOL, $download_scripts) | ||
); | ||
$download_scripts = []; | ||
foreach ($this->extensionMap as $item) { | ||
if (!$item->enableDownloadScript) { | ||
continue; | ||
} | ||
if (!empty($item->peclVersion)) { | ||
$item->file = $item->name . '-' . $item->peclVersion . '.tgz'; | ||
} | ||
if (empty($item->peclVersion) && empty($item->file)) { | ||
$item->file = $item->name . '.tgz'; | ||
} | ||
$cacheDir = '${__DIR__}/var/tmp'; | ||
$workDir = '${__DIR__}/var'; | ||
$downloadScript = <<<EOF | ||
mkdir -p {$cacheDir} | ||
cd {$cacheDir} | ||
test -d {$item->downloadDirName} && rm -rf {$item->downloadDirName} | ||
{$item->downloadScript} | ||
cd {$item->downloadDirName} | ||
test -f {$workDir}/extensions/{$item->file} || tar -czf {$workDir}/{$item->file} ./ | ||
cp -f {$workDir}/{$item->file} "\${__DIR__}/extensions/" | ||
cd {$workDir} | ||
EOF; | ||
|
||
$download_scripts[] = $downloadScript . PHP_EOL; | ||
} | ||
file_put_contents( | ||
$this->getWorkDir() . '/var/download_extension_use_git.sh', | ||
$shell_cmd_header . PHP_EOL . implode(PHP_EOL, $download_scripts) | ||
); | ||
} | ||
} |
Oops, something went wrong.