From 3126173f82b887e354a03ae1559eddb3d5af2f6a Mon Sep 17 00:00:00 2001 From: lachtan obecny Date: Mon, 17 Aug 2026 21:18:32 +0200 Subject: [PATCH] fixup! fixup! Pritup pres PHP a docker --- app/public/index.php | 43 +++++++++++++++++++++++++++++++++++++++---- compose.yaml | 5 ++++- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/app/public/index.php b/app/public/index.php index 88e9631..a98f8fa 100644 --- a/app/public/index.php +++ b/app/public/index.php @@ -2,7 +2,6 @@ declare(strict_types=1); -define('REPO_RAW_BASE_URL', getenv('REPO_RAW_BASE_URL') ?: 'https://git.fnet.cz/lachtan/get/raw/branch/master/'); const MANIFEST_PATH = 'manifest.yaml'; const TEMPLATES_DIRECTORY = __DIR__ . '/../templates'; const FETCH_TIMEOUT_SECONDS = 5; @@ -64,6 +63,22 @@ function renderScriptTemplate(string $templateName, array $placeholders): string return $script; } +$repoRawBaseUrl = getenv('REPO_RAW_BASE_URL'); + +if ($repoRawBaseUrl === false || $repoRawBaseUrl === '') { + sendPlainTextError(500, 'REPO_RAW_BASE_URL is not configured'); +} + +define('REPO_RAW_BASE_URL', $repoRawBaseUrl); + +$publicBaseUrl = getenv('PUBLIC_BASE_URL'); + +if ($publicBaseUrl === false || $publicBaseUrl === '') { + sendPlainTextError(500, 'PUBLIC_BASE_URL is not configured'); +} + +define('PUBLIC_BASE_URL', $publicBaseUrl); + $requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?? '/'; $name = trim(rawurldecode($requestPath), '/'); @@ -71,16 +86,24 @@ if ($name === '') { sendPlainTextError(400, 'Missing name of the installable item'); } +$isRawRequest = str_starts_with($name, 'raw/'); + +if ($isRawRequest) { + $name = substr($name, strlen('raw/')); +} + +$repoHost = parse_url(REPO_RAW_BASE_URL, PHP_URL_HOST); + $manifestYaml = fetchRaw(MANIFEST_PATH); if ($manifestYaml === false) { - sendPlainTextError(502, 'Failed to fetch the manifest from git.fnet.cz'); + sendPlainTextError(502, "Failed to fetch the manifest from $repoHost"); } $manifest = yaml_parse($manifestYaml); if ($manifest === false) { - sendPlainTextError(502, 'Failed to parse the manifest from git.fnet.cz'); + sendPlainTextError(502, "Failed to parse the manifest from $repoHost"); } $entry = $manifest[$name] ?? null; @@ -93,8 +116,20 @@ if (!is_string($entry['source'] ?? null) || !is_string($entry['target'] ?? null) sendPlainTextError(500, "Malformed manifest entry for item '$name'"); } +if ($isRawRequest) { + $content = fetchRaw($entry['source']); + + if ($content === false) { + sendPlainTextError(502, "Failed to fetch the file from $repoHost"); + } + + header('Content-Type: application/octet-stream'); + echo $content; + exit; +} + $variables = [ - 'SOURCE_URL' => REPO_RAW_BASE_URL . escapeForDoubleQuotedShellString(ltrim($entry['source'], '/')), + 'SOURCE_URL' => rtrim(PUBLIC_BASE_URL, '/') . '/raw/' . rawurlencode($name), 'TARGET_PATH' => resolveHomePath($entry['target']), 'POST_INSTALL' => $entry['post_install'] ?? '', ]; diff --git a/compose.yaml b/compose.yaml index c9017c4..5b3a6da 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,6 +1,9 @@ services: get: build: . + environment: + REPO_RAW_BASE_URL: https://git.hell/lachtan/get/raw/branch/master/ + PUBLIC_BASE_URL: https://get.fnet.cz/ ports: - - "${PORT:-8082}:80" + - "8082:80" restart: unless-stopped