-
Notifications
You must be signed in to change notification settings - Fork 0
/
2createProjectsAndCommitToGitLab.sh
executable file
·53 lines (42 loc) · 1.45 KB
/
2createProjectsAndCommitToGitLab.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# use same credentials for git as for gitlab user
ip=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
TARGETFOLDER=~/Devel
GITLAB_USER=root
GITLAB_PW=12345678
GITLAB_ADDR=$ip:10080
GITLAB_URL=gitlab
_TOKEN="curl -s http://$ip:10080/api/v3/session --data 'login=$GITLAB_USER&password=$GITLAB_PW' | jq '.private_token'"
TOKEN=$(eval $_TOKEN | tr -d '"')
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
createProject() {
docker run -it -e GITLAB_API_ENDPOINT=http://$GITLAB_URL/api/v4 \
-e GITLAB_API_PRIVATE_TOKEN=$TOKEN \
--net puppet_default \
test/gitlab-cli gitlab create_project $1
}
createProjectAndCommitToGitLab(){
local projectName=$1
local targetPath=$TARGETFOLDER/$projectName
echo "=== $targetPath ==="
rm -fr $targetPath
echo "--- Cloning..."
git clone http://$GITLAB_USER:$GITLAB_PW@$GITLAB_ADDR/root/$projectName.git $targetPath
#git config user.name $GITLAB_USER #don't use --global!
git config credential.helper cache #caches password for 15 min
echo "--- Copying..."
cp -r $projectName $TARGETFOLDER
echo "--- Committing..."
local currentPath=`pwd`;
cd $targetPath
git checkout -b production
git add .
git commit -a -m "inital commit"
git push -u origin production
cd $currentPath
}
createProject code
createProjectAndCommitToGitLab code
createProject monmodule
createProjectAndCommitToGitLab monmodule