#!/bin/sh if [ ! -e /data/go/bin ];then echo "/data/go/bin 目录不存在, 正在创建" echo "mkdir -p /data/go/bin" mkdir -p /data/go/bin echo "chmod 777 -R /data/go/bin" chmod -R 777 /data/go/bin fi CURDIR=`pwd` echo "当前目录:${CURDIR},开始执行创建git hook 脚本" GitPath="${CURDIR}/.git" if [ ! -d $GitPath ]; then echo "请执行 git init 初始化git 项目" exit -1 fi GitHookPath="${CURDIR}/.git/hooks" if [ ! -d $GitHookPath ]; then echo "$GitHookPath 不存在" exit -1 fi # 下载脚本 curl -O https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/code.shell curl -O https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/message.shell # copy 文件,如果存在,则备份历史文本 # commit go 文件检测,脚本 GitCommitCheckPath="${GitPath}/hooks/pre-commit" GitCommitCheckOldPath="$GitCommitCheckPath.old" if [ -f $GitCommitCheckPath ]; then echo "cp $GitCommitCheckPath $GitCommitCheckOldPath" cp $GitCommitCheckPath $GitCommitCheckOldPath fi; echo "mv code.shell $GitCommitCheckPath" mv code.shell $GitCommitCheckPath chmod 755 $GitCommitCheckPath # commit 消息脚本 GitCommitMessagePath="${GitPath}/hooks/commit-msg" GitCommitMessageOldPath="$GitCommitMessagePath.old" if [ -f $GitCommitMessagePath ]; then echo "cp $GitCommitMessagePath $GitCommitMessageOldPath" cp $GitCommitMessagePath $GitCommitMessageOldPath fi; echo "mv message.shell $GitCommitMessagePath" mv message.shell $GitCommitMessagePath echo "chmod 755 $GitCommitMessagePath" chmod 755 $GitCommitMessagePath GoFmtPath=/data/go/bin/gofmt if [ ! -f $GoFmtPath ];then echo "curl -o $GoFmtPath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/gofmt" curl -o $GoFmtPath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/gofmt echo "chmod 777 $GoFmtPath" chmod 777 $GoFmtPath fi GoImportPath=/data/go/bin/goimports if [ ! -f $GoImportPath ];then echo "curl -o $GoImportPath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/goimports" curl -o $GoImportPath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/goimports echo "chmod 777 $GoImportPath" chmod 777 $GoImportPath fi GoLinePath=/data/go/bin/golint if [ ! -f $GoLinePath ];then echo "curl -o $GoLinePath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/golint" curl -o $GoLinePath https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/golint echo "chmod 777 $GoLinePath" chmod 777 $GoLinePath fi # https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/gofmt # https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/goimports # https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/golint # rm ./.git/hooks/pre-commit # rm ./.git/hooks/commit-msg # curl -O https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/code.shell # curl -O https://tyut.oss-cn-beijing.aliyuncs.com/static/shell/message.shell # mv code.shell ./.git/hooks/pre-commit # chmod 755 ./.git/hooks/pre-commit # mv message.shell ./.git/hooks/commit-msg # chmod 755 ./.git/hooks/commit-msg echo "执行完成,请创建 git hook 脚本成功,请提交代码试一试 .... "