'linux', 'Windows' => 'win', 'BSD' => 'freebsd', 'Darwin' => 'macos', default => throw new WrongUsageException('Unsupported OS!'), }; $config = Config::getPkg("{$pkg_name}-{$arch}-{$os}"); } if ($config === null) { throw new WrongUsageException("Package [{$pkg_name}] does not exist, please check the name and correct it !"); } // Download package Downloader::downloadPackage($pkg_name, $config, $force); // After download, read lock file name $lock = json_decode(FileSystem::readFile(DOWNLOAD_PATH . '/.lock.json'), true); $filename = DOWNLOAD_PATH . '/' . ($lock[$pkg_name]['filename'] ?? $lock[$pkg_name]['dirname']); $extract = $lock[$pkg_name]['move_path'] === null ? (PKG_ROOT_PATH . '/' . $pkg_name) : $lock[$pkg_name]['move_path']; FileSystem::extractPackage($pkg_name, $filename, $extract); // if contains extract-files, we just move this file to destination, and remove extract dir if (is_array($config['extract-files'] ?? null) && is_assoc_array($config['extract-files'])) { foreach ($config['extract-files'] as $file => $target) { $target = FileSystem::convertPath(FileSystem::replacePathVariable($target)); if (!is_dir($dir = dirname($target))) { f_mkdir($dir, 0755, true); } logger()->debug("Moving package [{$pkg_name}] file {$file} to {$target}"); rename(FileSystem::convertPath($extract . '/' . $file), $target); } FileSystem::removeDir($extract); } } }