annotate cgit/git-bare @ 5:19a4c3672796 default tip

RE:重新新增Cgit配置文件
author Franklin Schmit <meokcin@gmail.com>
date Wed, 04 Sep 2024 08:15:23 +0800
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
1 #!/bin/bash
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
2
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
3 set -eu
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
4
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
5 # /usr/local/bin/git-bare
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
6
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
7 echo "1.make sure you are running with root user or sudo privileged"
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
8 echo "2.make sure you have installed cURL and Git"
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
9 echo ""
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
10 echo "Press Enter to continue..."
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
11 read
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
12
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
13 # Check if the running user is root or sudo user
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
14 if [ "$(id -u)" -ne 0 ]; then
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
15 if ! sudo -v &> /dev/null; then
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
16 echo "Please run the script as root or with sudo privileged!"
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
17 exit 1
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
18 fi
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
19 fi
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
20
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
21 # Check if cURL is installed
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
22 if ! command -v curl &> /dev/null; then
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
23 echo "cURL is not installed, please install curl first."
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
24 echo "sudo apt update && sudo apt install -y curl"
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
25 exit 1
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
26 fi
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
27
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
28 # Check if Git is installed
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
29 if ! command -v git &> /dev/null; then
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
30 echo "Git is not installed, please install git first."
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
31 echo "sudo apt update && sudo apt install -y git"
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
32 exit 1
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
33 fi
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
34
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
35 read -p "Please enter the repository name (without .git)." reponame
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
36
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
37 if [ -d "/home/git/${reponame}.git" ]; then
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
38 echo "Repository ${reponame} already exists"
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
39 exit 1
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
40 else
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
41 git init --bare "/home/git/${reponame}.git"
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
42 cd "/home/git/${reponame}.git"
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
43
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
44 read -p "Please enter the repository description:" description
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
45 echo "${description}." | sudo tee "description" > /dev/null
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
46
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
47 # Update the Git repository info
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
48 if ! git update-server-info &> /dev/null; then
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
49 echo "Failed to update Git repository information, exiting..."
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
50 exit 1
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
51 fi
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
52
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
53 # Set up the new repository's post-receive
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
54 curl -s https://git.xvo.es/self-hosted/plain/cgit/post-receive.agefile -o hooks/post-receive
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
55 chmod +x hooks/post-receive
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
56
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
57 # Set user groups and permissions for the repository
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
58 chown -R git:www-data "/home/git/${reponame}.git"
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
59 chmod -R ug+rwx,o-rwx "/home/git/${reponame}.git"
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
60 echo "New bare repository ${reponame} initialized successfully."
19a4c3672796 RE:重新新增Cgit配置文件
Franklin Schmit <meokcin@gmail.com>
parents:
diff changeset
61 fi
备案号:苏ICP备2024087954号-2 | 渝公网安备50010402001513