当前位置: 首页 > 工具软件 > cgit > 使用案例 >

Ubuntu环境下cGit的配置与使用

凌景辉
2023-12-01

1、下载cgit
#cd ~
#wget -c https://git.zx2c4.com/cgit/snapshot/cgit-1.1.tar.xz
2、解压cgit
#tar xvf cgit-1.1.tar.xz
3、安装ssl、git或curl
#sudo apt-get install libssl-dev
#sudo apt-get install git
#sudo apt-get install curl
4、安装cgit
#mv cgit-1.1 cgit
#cd cgit
#make get-git
#make
#make install
5、安装apache2
#sudo apt-get install apache2
6、新建配置文件
#sudo touch /etc/apache2/conf-available/cgit.conf
7、配置apache2.conf
增加/etc/apache2/apache2.conf中 conf-available/*.conf
8、配置sites-enabled/000-default.conf
设置DocumentRoot /var/www/htdocs/cgit/
9、新建cgit.sh
#cd ~
#touch cgit.sh
#gedit cgit.sh

#!/bin/sh

set -e

[ -z "${SCAN_PATH}" ] && SCAN_PATH=/home/ubuntu/git

cgit_install()
{
  echo "scan-path=${SCAN_PATH}" | sudo tee -a /etc/cgitrc
  cat <<EOF | sudo tee -a /etc/cgitrc
source-filter=/usr/local/lib/cgit/filters/syntax-highlighting.sh

#virtual root
virtual-root=/

#css logo.
css=/cgit.css
logo=/cgit.png

#project
scan-path=/home/ubuntu/git/

#...
enable-index-links=1
enable-index-owner=1
enable-log-filecount=1
enable-log-linecount=1

#title
root-title=sylixos.com git repositories

#desc
root-desc=Git repositories hosted at sylixos.com
EOF
}

apache_install()
{
  sudo cp /etc/apache2/conf-available/cgit.conf \
       /etc/apache2/conf-available/cgit.conf.orig
  cat <<EOF | sudo tee /etc/apache2/conf-available/cgit.conf
<VirtualHost _default_:80>

ServerAdmin admin@example.com
    ServerName git.njsylixos.com

    DocumentRoot /var/www/htdocs/cgit/

    <Directory /var/www/htdocs/cgit/>
        AllowOverride None
        Options +ExecCGI
        Order allow,deny
        Allow from all
    </Directory>

    Alias /cgit.png /var/www/htdocs/cgit/cgit.png
    Alias /cgit.css /var/www/htdocs/cgit/cgit.css
    ScriptAlias / "/var/www/htdocs/cgit/cgit.cgi/"

    ErrorLog /var/log/apache2/cgit-error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/cgit-access.log combined

$(sed -e 's/^/  /g' /etc/apache2/conf-available/cgit.conf.orig)
</VirtualHost>
EOF
  sudo a2enmod cgid
  sudo service apache2 restart
}

create_repo()
{
  mkdir -p "${SCAN_PATH}"/test.git
  cd "${SCAN_PATH}"/test.git
  git init --bare
}

cgit_main()
{
  cgit_install
  apache_install
  create_repo
}

cgit_main

执行该脚本:#sudo ./cgit.sh

 类似资料: