Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions lib/Migration/InstallDeps.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use OCA\Recognize\Helper\TAR;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IConfig;
use OCP\Http\Client\IClientService;
use OCP\IBinaryFinder;
use OCP\Migration\IOutput;
Expand All @@ -39,6 +40,7 @@ final class InstallDeps implements IRepairStep {
public const NODE_SERVER_UNOFFICIAL = 'https://unofficial-builds.nodejs.org/download/release/';

protected IAppConfig $config;
private IConfig $systemConfig;
private string $binaryDir;
private string $preGypBinaryDir;
private string $ffmpegDir;
Expand All @@ -52,8 +54,9 @@ final class InstallDeps implements IRepairStep {
private IBinaryFinder $binaryFinder;
private string $nodeModulesDir;

public function __construct(IAppConfig $config, IClientService $clientService, LoggerInterface $logger, IBinaryFinder $binaryFinder) {
public function __construct(IAppConfig $config, IConfig $systemConfig, IClientService $clientService, LoggerInterface $logger, IBinaryFinder $binaryFinder) {
$this->config = $config;
$this->systemConfig = $systemConfig;
$this->binaryDir = dirname(__DIR__, 2) . '/bin/';
$this->nodeModulesDir = dirname(__DIR__, 2) . '/node_modules/';
$this->preGypBinaryDir = dirname(__DIR__, 2) . '/node_modules/@mapbox/node-pre-gyp/bin/';
Expand Down Expand Up @@ -185,10 +188,25 @@ protected function testBinary(string $binaryPath): ?string {
return trim(implode("\n", $output));
}


/**
* Build proxy environment variable prefix from Nextcloud system config.
*
* @return string Empty string or "HTTPS_PROXY=... HTTP_PROXY=... " prefix
*/
protected function getProxyEnv() : string {
$proxy = $this->systemConfig->getSystemValueString('proxy', '');
if ($proxy === '') {
return '';
}
return 'HTTPS_PROXY=' . escapeshellarg($proxy) . ' '
. 'HTTP_PROXY=' . escapeshellarg($proxy) . ' ';
}

protected function runTfjsInstall(string $nodeBinary) : void {
$oriCwd = getcwd();
chdir($this->tfjsPath);
$cmd = 'PATH='.escapeshellcmd($this->preGypBinaryDir).':'.escapeshellcmd($this->binaryDir).':$PATH ' . escapeshellcmd($nodeBinary) . ' ' . escapeshellarg($this->tfjsInstallScript) . ' cpu ' . escapeshellarg('download');
$cmd = $this->getProxyEnv() . 'PATH='.escapeshellcmd($this->preGypBinaryDir).':'.escapeshellcmd($this->binaryDir).':$PATH ' . escapeshellcmd($nodeBinary) . ' ' . escapeshellarg($this->tfjsInstallScript) . ' cpu ' . escapeshellarg('download');
try {
exec($cmd . ' 2>&1', $output, $returnCode); // Appending 2>&1 to avoid leaking sterr
} catch (\Throwable $e) {
Expand All @@ -205,7 +223,7 @@ protected function runTfjsInstall(string $nodeBinary) : void {
protected function runTfjsGpuInstall(string $nodeBinary) : void {
$oriCwd = getcwd();
chdir($this->tfjsGPUPath);
$cmd = 'PATH='.escapeshellcmd($this->preGypBinaryDir).':'.escapeshellcmd($this->binaryDir).':$PATH ' . escapeshellcmd($nodeBinary) . ' ' . escapeshellarg($this->tfjsGpuInstallScript) . ' gpu ' . escapeshellarg('download');
$cmd = $this->getProxyEnv() . 'PATH='.escapeshellcmd($this->preGypBinaryDir).':'.escapeshellcmd($this->binaryDir).':$PATH ' . escapeshellcmd($nodeBinary) . ' ' . escapeshellarg($this->tfjsGpuInstallScript) . ' gpu ' . escapeshellarg('download');
try {
exec($cmd . ' 2>&1', $output, $returnCode); // Appending 2>&1 to avoid leaking sterr
} catch (\Throwable $e) {
Expand All @@ -222,7 +240,7 @@ protected function runTfjsGpuInstall(string $nodeBinary) : void {
protected function runFfmpegInstall(string $nodeBinary): void {
$oriCwd = getcwd();
chdir($this->ffmpegDir);
$cmd = escapeshellcmd($nodeBinary) . ' ' . escapeshellarg($this->ffmpegInstallScript);
$cmd = $this->getProxyEnv() . escapeshellcmd($nodeBinary) . ' ' . escapeshellarg($this->ffmpegInstallScript);
try {
exec($cmd . ' 2>&1', $output, $returnCode); // Appending 2>&1 to avoid leaking sterr
} catch (\Throwable $e) {
Expand Down