git.php: store local repo clone in web/git (live: /www/sites/ParlzPackageManger/index/web/git); PMM_SRC_DIR override; permission hint

这个提交包含在:
JGZYES
2026-09-02 21:41:12 +08:00
父节点 f119eeec4c
当前提交 823fc54156
修改 2 个文件,包含 7 行新增15 行删除
+1 -1
查看文件
@@ -30,4 +30,4 @@
# source browser cache clone # source browser cache clone
web/.src/ web/.src/
web/repo/ web/git/
+6 -14
查看文件
@@ -7,18 +7,9 @@ define('PMM_SITE', 1);
require __DIR__ . '/_common.php'; require __DIR__ . '/_common.php';
$REPO_URL = 'https://github.com/JGZYES/ParlzPackageManger.git'; $REPO_URL = 'https://github.com/JGZYES/ParlzPackageManger.git';
/* Choose a PHP-writable location for the local repo clone (the web root may be /* Local repo clone lives in web/git (i.e. /www/sites/ParlzPackageManger/index/web/git
* owned by root, so PHP/php-fpm often can't create web/repo). */ * on the live host). PMM_SRC_DIR may override it. PHP needs write access there. */
function pick_repo_dir(): string { $REPO_DIR = getenv('PMM_SRC_DIR') ?: (__DIR__ . '/git');
$env = getenv('PMM_SRC_DIR');
if ($env && (is_dir($env) || @mkdir($env, 0775, true))) return $env;
$local = __DIR__ . '/repo';
if (is_dir($local) || @mkdir($local, 0775, true)) return $local;
$tmp = sys_get_temp_dir() . '/pmm-src';
@mkdir($tmp, 0775, true);
return $tmp;
}
$REPO_DIR = pick_repo_dir();
/* handle the one-click clone/pull early (no page output yet) */ /* handle the one-click clone/pull early (no page output yet) */
if (isset($_GET['action']) && $_GET['action'] === 'init') { if (isset($_GET['action']) && $_GET['action'] === 'init') {
@@ -28,7 +19,7 @@ if (isset($_GET['action']) && $_GET['action'] === 'init') {
$cmd = 'git clone --depth 1 ' . escapeshellarg($REPO_URL) . ' ' . escapeshellarg($REPO_DIR) . ' 2>&1'; $cmd = 'git clone --depth 1 ' . escapeshellarg($REPO_URL) . ' ' . escapeshellarg($REPO_DIR) . ' 2>&1';
$out = (string)@shell_exec($cmd); $out = (string)@shell_exec($cmd);
if (is_dir($REPO_DIR . '/.git')) echo 'OK'; if (is_dir($REPO_DIR . '/.git')) echo 'OK';
else echo '克隆失败:' . substr($out, 0, 220) . "\n已尝试写入 " . $REPO_DIR . ''; else echo '克隆失败:' . substr($out, 0, 220) . "\n请确保 PHP 对 ' . $REPO_DIR . ' 可写:chmod -R 775 ' . $REPO_DIR . ' 或其父目录;或设 PMM_SRC_DIR';
} else { } else {
$out = (string)@shell_exec('git -C ' . escapeshellarg($REPO_DIR) . ' pull --depth 1 2>&1'); $out = (string)@shell_exec('git -C ' . escapeshellarg($REPO_DIR) . ' pull --depth 1 2>&1');
echo 'OK (pull: ' . substr(trim($out), 0, 80) . ')'; echo 'OK (pull: ' . substr(trim($out), 0, 80) . ')';
@@ -91,7 +82,8 @@ pmm_header('source', '源码浏览');
<?php if (!$repo_ok): ?> <?php if (!$repo_ok): ?>
<div class="gh-card"> <div class="gh-card">
<div class="gh-repo">初始化本地源码仓库</div> <div class="gh-repo">初始化本地源码仓库</div>
<p class="src-clone-note">页面 PHP 可写目录 <code><?php echo esc($REPO_DIR); ?></code> 存放仓库副本。若服务器 web 根对 PHP 不可写,会在 <code>/tmp</code> 类的临时目录存一份(重启可能失效)。可改用环境变量 <code>PMM_SRC_DIR</code> 指定持久可写目录;或 <code>chmod 775</code> 仓库目录。初始化命令:</p> <p class="src-clone-note">页面 PMM 仓库副本存入 <code><?php echo esc($REPO_DIR); ?></code>。若 PHP 无写权限(web 根归 root),先
<code>chmod -R 775 <?php echo esc($REPO_DIR); ?></code> 或其父目录;或用环境变量 <code>PMM_SRC_DIR</code> 指定持久目录。初始化命令:</p>
<pre class="gh-code"><code>git clone --depth 1 <?php echo esc($REPO_URL); ?> <?php echo esc($REPO_DIR); ?></code></pre> <pre class="gh-code"><code>git clone --depth 1 <?php echo esc($REPO_URL); ?> <?php echo esc($REPO_DIR); ?></code></pre>
<div style="margin-top:12px"> <div style="margin-top:12px">
<button class="btn btn-sm" id="git-now" type="button">在线初始化 / 更新</button> <button class="btn btn-sm" id="git-now" type="button">在线初始化 / 更新</button>