My linux world » Git

Git


Prerequiste

I assume that you have a Centos installation.

Installation

You can copy/paste this script and use it to configure automatically your server.

  1. #!/bin/bash
  2.  
  3. echo "install tools git gitweb git-daemon"
  4. dnf -y install git gitweb git-daemon
  5.  
  6. echo "create trees in /opt/git"
  7. mkdir -p /opt/git/cgi-bin
  8. mkdir -p /opt/git/repos
  9. mkdir -p /opt/git/bin
  10. mkdir -p /opt/git/conf
  11.  
  12. echo "create /opt/git/conf/gitweb.conf"
  13. cat > /opt/git/conf/gitweb.conf << "EOF"
  14. $projectroot='/opt/git/repos/';
  15. $site_name="My git trees";
  16. $my_uri="/";
  17. @stylesheets = ("/gitweb.css");
  18. $favicon = "/git-favicon.png";
  19. $logo = "/git-logo.png";
  20. EOF
  21.  
  22.  
  23.  
  24.  
  25. echo "copy gitweb.cgi to /opt/git/cgi-bin and update script var \$projectroot"
  26. _oldpath="/var/lib/git"
  27. _newpath="/opt/git/repos"
  28.  
  29. #Escape char for sed:
  30. _oldpath="${_oldpath//\//\\/}"
  31. _newpath="${_newpath//\//\\/}"
  32.  
  33. #replace
  34. echo oldpath : ${_oldpath}
  35. sed -e "s/${_oldpath}/${_newpath}/g" /var/www/git/gitweb.cgi > /opt/git/cgi-bin/gitweb.cgi
  36.  
  37. chmod a+x /opt/git/cgi-bin/gitweb.cgi
  38.  
  39.  
  40.  
  41.  
  42. echo "copy gitweb requistes to /var/www/html"
  43. cp /var/www/git/*.png /var/www/html
  44. cp /var/www/git/*.css /var/www/html
  45. cp /var/www/git/*.js /var/www/html
  46.  
  47. echo "configure httpd (create /etc/httpd/conf.d/git.conf)"
  48. cat > /etc/httpd/conf.d/git.conf << "EOF"
  49. ScriptAliasMatch ^/git/(.*)$ /opt/git/cgi-bin/gitweb.cgi/$1
  50. <Directory "/opt/git/cgi-bin/">
  51. SetHandler cgi-script
  52. AllowOverride All
  53. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  54. Require all granted
  55. </Directory>
  56. ErrorLog /var/log/httpd/git-error.log
  57. CustomLog /var/log/httpd/git-access.log common
  58.  
  59. <Location /git/>
  60. # Load git mod
  61. DAV On
  62. Options ExecCGI FollowSymLinks Indexes
  63. Require all granted
  64. </Location>
  65. EOF
  66.  
  67. echo "create symbolic link for the repo"
  68. ln -s /opt/git/repos /var/www/html/git
  69.  
  70. echo "create /opt/git/bin/create.sh"
  71. cat > /opt/git/bin/create.sh << "EOF"
  72. git init --bare /opt/git/repos/$1.git
  73.  
  74. #update repos:
  75. cd /opt/git/repos/$1.git
  76. cp hooks/post-update.sample hooks/post-update
  77. chmod +x hooks/post-update
  78. git update-server-info
  79. cd -
  80.  
  81. #owner and mod
  82. chown -R apache:apache /opt/git/repos/$1.git
  83. chmod -R 750 /opt/git/repos/$1.git
  84.  
  85. EOF
  86. chmod a+x /opt/git/bin/create.sh
  87.  
  88. echo "create a sample repository named 'myrepos'"
  89. /opt/git/bin/create.sh myrepos
  90.  
  91. echo "Now restart httpd"
  92. systemctl restart httpd.service
  93.  
  94. myip=`hostname -I`
  95. echo "Now meet you here: http://$myip/git/"
  96.  

That’s all 🙂
Administration – git


Copyright © 2023 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.

Fork me on GitHub