Skip to content

Commit

Permalink
Merge pull request #148 from jingjingxyk/feature_downloadbox
Browse files Browse the repository at this point in the history
Feature downloadbox
  • Loading branch information
jingjingxyk committed May 21, 2023
2 parents b0a9b38 + 96ba2e6 commit dab9089
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux-aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [ push, pull_request ]

jobs:
linux-aarch64:
if: 0
if: 1
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion docs/macOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ brew uninstall --ignore-dependencies capstone

## 缺少 bison

下载源代码,自行编译安装
下载源代码,自行编译安装 (此问题已经决,安装依赖库时 已经包含bison源码编译)

## 缺少`libtool`

Expand Down
1 change: 1 addition & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ skip-download

# 构建依赖库之前,批量下载依赖库和扩展的脚本
sh sapi/scripts/download-dependencies-use-aria2.sh
sh sapi/scripts/download-dependencies-use-git.sh

```

Expand Down
4 changes: 2 additions & 2 deletions sapi/quickstart/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ bash sapi/quickstart/linux/run-alpine-3.16-container.sh
bash sapi/quickstart/linux/connection-swoole-cli-alpine.sh

# 准备构建基础软件
bash sapi/quickstart/linux/alpine-3.16-init.sh
sh sapi/quickstart/linux/alpine-3.16-init.sh


# 准备构建基础软件 使用中科大镜像源

bash sapi/quickstart/linux/alpine-3.16-init.sh --mirror china
sh sapi/quickstart/linux/alpine-3.16-init.sh --mirror china

```

Expand Down
34 changes: 34 additions & 0 deletions sapi/scripts/download-dependencies-use-git.sh
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__}
119 changes: 119 additions & 0 deletions sapi/src/DownloadBoxTrait.php
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)
);
}
}
Loading

0 comments on commit dab9089

Please sign in to comment.