前几天学习了linux搭建git服务器及自动化部署,周末没事研究下怎么使用shell脚本实现,这样以后使用的时候也方便

#!/bin/bashread -p "请输入项目名称:" nameif [ "$name" = "" ];then    echo "项目名称为空,停止执行"    exitfi# git目录git_dir="/git/$name"# git仓库git_repository="/git/$name/$name.git"# web文件目录web_dir="/home/wwwroot/$name"# 钩子文件file_path="$git_repository/hooks/post-receive"# 创建并修改web文件目录所有者if [ ! -d "$web_dir" ];then    mkdir $web_dir    echo "$web_dir文件夹创建成功"else    echo "$web_dir文件夹已存在"fichown -R git:git $web_dir# 创建git目录if [ ! -d "$git_dir" ];then    mkdir $git_dir    echo "$git_dir文件夹创建成功"else    echo "$git_dir文件夹已存在"fichown git:git $git_dir# 创建git仓库if [ ! -d "$git_repository" ];then    git init --bare $git_repository    echo "仓库$git_repository创建成功"else    echo "仓库$git_repository已存在"fichown -R git:git $git_repository# 创建git钩子文件touch $file_pathecho "git --work-tree=$web_dir --git-dir=$git_repository checkout -f" > $file_pathchown -R git:git $file_pathchmod +x $file_pathif [ -f "$file_path" ];then    echo "钩子文件创建成功"else    echo "钩子文件创建失败"fi