Gitolite:手动编译conf文件?

Gitolite:手动编译conf文件?

我正在编写一个用于服务器上的 repo 管理的 Web UI,以避免必须克隆 gitolite-admin、编辑 conf 和 keydir 文件,然后推送。

管理员只需登录 Web 应用程序,获取所有存储库和每个存储库的权限列表,然后从那里他可以添加新的存储库、用户的 SSH 密钥等。

我搜索了一个可以帮我做所有事情的 Python 模块,但我找到的最好的东西是https://github.com/smailq/gitolite-manager/blob/master/gitolite_manager/gitolite.py它还远未完成,所以我编写了一个 Python 脚本,它可以解析和编辑 gitolite.conf 文件中的权限、添加/删除 SSH 密钥以及在存储库目录中添加/删除新的存储库。

我想避免克隆 gitolite-admin、编辑和推送它,因为这意味着为 Apache 创建一个 SSH 密钥,将该密钥添加到 gitolite 管理员等。从安装和分发的角度来看,这很麻烦。

我以 git 身份登录并运行~git/bin/gitolite compile,conf 编译成功,一切按预期进行,存储库的权限正常。

当我尝试以 root 或 Apache 用户身份运行编译命令时出现了问题。

我收到以下错误信息:

root@debian:/home/git/bin# ./gitolite compile
FATAL: errors found but logfile could not be created
FATAL: /root/.gitolite/logs/gitolite-2014-05.log: No such file or directory
FATAL: die      chdir /root/.gitolite failed: No such file or directory<<newline>>


www-data@debian:/home/git/bin$ ./gitolite compile
FATAL: errors found but logfile could not be created
FATAL: /var/www/.gitolite/logs/gitolite-2014-05.log: No such file or directory
FATAL: die      chdir /var/www/.gitolite failed: No such file or directory<<newline>>

在我看来,gitolite 使用运行该命令的用户的主目录。

我尝试设置环境变量GL_BINDIRGL_REPO_BASEGL_ADMIN_BASE指向正确的目录,但没有成功:

root@debian:/home/git/bin# export GL_BINDIR=/home/git/bin/
root@debian:/home/git/bin# export GL_REPO_BASE=/home/git/repositories/
root@debian:/home/git/bin# export GL_ADMIN_BASE=/home/git/.gitolite
root@debian:/home/git/bin# ./gitolite compile
FATAL: errors found but logfile could not be created
FATAL: /root/.gitolite/logs/gitolite-2014-05.log: No such file or directory
FATAL: die      chdir /root/.gitolite failed: No such file or directory<<newline>>

有没有什么办法,无需修改 gitolite 代码,就可以以 git 以外的其他用户身份运行编译?

答案1

与 gitolite 的作者交谈后我找到了一个解决方案:

我将其添加到 sudoers 中作为测试:

yoshi ALL=(git) NOPASSWD: /home/git/bin/gitolite

并且运行这些命令的效果正如预期的那样:

yoshi@debian ~ $ sudo -u git /home/git/bin/gitolite compile

Initialized empty Git repository in /home/git/repositories/testrepo.git/

yoshi@debian ~ $ sudo -u git /home/git/bin/gitolite trigger POST_COMPILE
yoshi@debian ~ $

相关内容