You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

6 months ago
#!/bin/bash
# 定义1个变量变量是git裸仓库名字例如/www/git/demo.git
6 months ago
<<<<<<< HEAD
6 months ago
GIT_REPO_NAME="/www/git/wx.sstbc.com.git"
6 months ago
=======
6 months ago
GIT_REPO_NAME="/data/git/wx.sstbc.com.git"
6 months ago
>>>>>>> 8508a4aca7d83d334aa2ec18b4291c6d5750a769
6 months ago
#检测系统里是否存在用户名是git的用户如果不存在就创建一个并且设置密码为git@2023
if ! id -u git > /dev/null 2>&1; then
useradd git
echo "已创建用户 git"
echo git:git@2023 | chpasswd
echo "密码已设置为 Git@2018"
else
echo "git用户已存在"
fi
# 检测系统里是否存在git用户组如果不存在就创建一个并把git用户加入git用户组
if grep "^git:" /etc/group >/dev/null 2>&1; then
echo "git用户组已存在"
else
echo "创建git用户组..."
groupadd git
usermod -aG git git
fi
# 根据定义的裸仓库路径,在指定路径下创建裸仓库
echo "创建裸仓库..."
mkdir -p $GIT_REPO_NAME && cd $GIT_REPO_NAME && git init --bare
# 给上一步创建的裸仓库给予git用户组里git用户读写执行权限
echo "给裸仓库设置权限..."
chown git:git * -R
cd -
chown git:git "$GIT_REPO_NAME"
# 切换到当前脚本所在的目录初始化git仓库并且关联之前创建的本地裸仓库地址。
cd "$(dirname "$0")"
if [ -d ".git" ]; then
echo "该目录是一个Git仓库"
else
echo "该目录不是一个Git仓库"
echo "初始化git仓库..."
git init
fi
echo "关联仓库"
git remote add origin $GIT_REPO_NAME
# 输出这个裸仓库的本地链接地址和远程连接地址
echo "远程仓库关联git remote add production ssh://git@ip:$GIT_REPO_NAME"