blob: a4f757a11e1bbbe8e82d030d94bf3210751f117d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/bin/bash
set -eu
# /usr/local/bin/git-bare
# Check if the running user is root or sudo user
if [ "$(id -u)" -ne 0 ]; then
if ! sudo -v &> /dev/null; then
echo "Please run the script as root or with sudo user"
exit 1
fi
fi
# Check if git is installed
if ! command -v git &> /dev/null; then
echo "Git is not installed, please install Git first."
exit 1
fi
read -p "Please enter the repository name (without .git)." reponame
if [ -d "/home/git/${reponame}.git" ]; then
echo "Repository ${reponame} already exists"
exit 1
else
git init --bare "/home/git/${reponame}.git"
cd "/home/git/${reponame}.git"
read -p "Please enter the repository description:" description
echo "${description}." | sudo tee "description" > /dev/null
# Update the Git repository info
if ! git update-server-info &> /dev/null; then
echo "Failed to update Git repository information, exiting..."
exit 1
fi
chown -R git:www-data "/home/git/${reponame}.git"
chmod -R ug+rwx,o-rwx "/home/git/${reponame}.git"
echo "The repository was created successfully."
fi
|