自动检测新增主要项目,在hook pre-recevie 添加脚本
#!/bin/bash
#目标:自动检测新增主要项目,在hook pre-recevie 添加脚本
#2018-12-25
PRO_NAME=(abc.git project.git)
BASE_DIR="/opt/gitlab/git-data/repositories"
DATE_TIME=`date '+%Y-%m-%d %H:%M:%S'`
HOOK_DIR="custom_hooks"
LOG_DIR="/opt/gitlab/githook_script/sh/log/add_prerecive_hook.log"
for job in ${PRO_NAME[*]}
do
real_dir=(`find $BASE_DIR -type d -name "$job"`)
num=${#real_dir[@]}
for (( i=0;i<$num;i++ ));
do
cus_hook=`ls ${real_dir[$i]}|grep -w "$HOOK_DIR"`
if [ ! $cus_hook ];then
echo "$DATE_TIME" >> $LOG_DIR
ln -s /opt/gitlab/githook_script/custom_hooks ${real_dir[$i]}/custom_hooks
chown git.git ${real_dir[$i]}/custom_hooks
echo "新增工程目录 ${job}">> $LOG_DIR
echo "新增hooks连接,地址为:${real_dir[$i]}" >> $LOG_DIR
sleep 2
fi
done
done
最后添加一个crontab ,定时执行脚本。