#!/usr/bin/env bash
function getListByKey() {
json=$1
key=$2
echo $json | grep -Po '"$key":(.+?),' | grep -Po '\d+'
}
function groupProjects() {
groupList=''
groupList=$(curl -H "PRIVATE-TOKEN: $pricateToken" https://XgitlabIpX/api/v3/groups)
#echo $groupList
idList=(`echo $groupList | grep -Po '"id":(.+?),' | grep -Po '\d+'`)
nameList=(`echo $groupList | grep -Po '"name":(.+?),' | awk -F '\"' '{print $4}'`)
#遍历 group id list
echo "您有 ${#idList[@]} 个分组 "
for(( i=0;i<${#idList[@]};i++)) do
echo "目录 ${nameList[i]}"
mkdir ${nameList[i]}
cd ${nameList[i]}
projectsList=$(curl -H "PRIVATE-TOKEN: $pricateToken" https://XgitlabIpX/api/v3/groups/${idList[i]}/projects)
sshList=(`echo $projectsList | grep -Po '(ssh)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]'`)
for(( j=0;j<${#sshList[@]};j++)) do
echo "准备克隆第$[$i+1] 分组下的第$[$j+1] 个项目${sshList[j]}";
git clone ${sshList[j]}
done
cd ..
done;
}
function allProjects() {
allList=''
allList=$(curl -H "PRIVATE-TOKEN: $pricateToken" https://XgitlabIpX/api/v3/projects)
#echo $groupList
sshList=(`echo $allList | grep -Po '(ssh)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]'`)
for(( j=0;j<${#sshList[@]};j++)) do
echo "准备克隆第$[$j+1] 个项目${sshList[j]}";
git clone ${sshList[j]};
done;
}
#JNTMcqKTyytmUxRaWwsx
echo -e "请输入你的私密令牌: \n如果没有,请前往https://XgitlabIpX/ 项目--个人资料设置--个人访问令牌--创建个人令牌(该令牌再次刷新就无法查看,请记得保存)"
#Private token
read pricateToken
echo $pricateToken
while true
do
#Individual group List
echo "下载个人所有项目请输入1,下载所属群组下的项目请输入2"
read putKey
if [ $putKey = "1" ]; then
allProjects
break
elif [ $putKey = "2" ]; then
groupProjects
break
else
echo "请输入正确的指令"
fi
done
相关文章
暂无评论...