-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetUp.sh
More file actions
executable file
·99 lines (72 loc) · 3.56 KB
/
setUp.sh
File metadata and controls
executable file
·99 lines (72 loc) · 3.56 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
export GITLAB_HOME=$PWD
GITLAB_HOST="localhost"
GITLAB_URL="http://$GITLAB_HOST"
./startGitLab.sh
PASSORD=$(docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password | tr '\r' '\n' | awk '{print $2}')
TOKEN_DATA="{\"grant_type\":\"password\", \"username\":\"root\", \"password\":\"$PASSORD\"}"
TOKEN_JSON=$(curl -s -X POST -H 'Content-type: application/json' -d "$TOKEN_DATA" "$GITLAB_URL/oauth/token")
TOKEN=$(echo "$TOKEN_JSON" | jq '.access_token' -r)
if [[ -n $TOKEN ]]; then
echo "Token: $TOKEN"
fi
BRUKER_IDS=$(curl -s -X GET -H "Authorization: Bearer $TOKEN" "$GITLAB_URL/api/v4/users" | jq '.[].id')
for a in $BRUKER_IDS; do
if [[ $a != "1" ]]; then
echo "Sletter bruker $a"
curl -s -X DELETE -H "Authorization: Bearer $TOKEN" "$GITLAB_URL/api/v4/users/$a"
fi
done
printf 'Venter på at brukerne er slettet'
until [[ -z $(curl -s -X GET -H "Authorization: Bearer $TOKEN" "$GITLAB_URL/api/v4/users" | jq '.[].username' | grep -v 'root' | grep -v 'ghost') ]]; do
echo -en '.'
sleep 0.1
done
echo .
echo "Oppretter buker 'du'"
DEG_ID=$(curl -s -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-type: application/json' -d '{"email":"degselv@example.com", "name": "Deg Selv", "username": "du", "password": "password", "skip_confirmation": true}' $GITLAB_URL/api/v4/users | jq '.id')
echo "Oppretter buker 'team'"
TEAM_ID=$(curl -s -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-type: application/json' -d '{"email":"teammedlem@example.com", "name": "Team Medlem", "username": "team", "password": "password", "skip_confirmation": true}' $GITLAB_URL/api/v4/users | jq '.id')
echo "Oppretter buker 'annen'"
ANNEN_ID=$(curl -s -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-type: application/json' -d '{"email":"annenbruker@example.com", "name": "Annen Bruker", "username": "annen", "password": "password", "skip_confirmation": true}' $GITLAB_URL/api/v4/users | jq '.id')
function hentProsjektet
{
curl -s -X GET -H "Authorization: Bearer $TOKEN" "$GITLAB_URL/api/v4/projects/root%2fProsjektet"
}
PROSJEKT_FINNES=$(hentProsjektet | jq '.id')
if [[ -n $PROSJEKT_FINNES ]]; then
echo "Sletter Prosjektet"
curl -s -o /dev/null -X DELETE -H "Authorization: Bearer $TOKEN" "$GITLAB_URL/api/v4/projects/root%2fProsjektet"
fi
function opprettProsjekt
{
curl -s -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-type: application/json' -d '{"name":"Prosjektet", "initialize_with_readme": true, "visibility": "public"}' $GITLAB_URL/api/v4/projects
}
echo "Oppretter Prosjektet"
PROSJEKT_ID=$(opprettProsjekt | jq '.id')
printf 'Venter på at Prosjektet skal opprettes'
until [[ $(hentProsjektet | jq '.message') == "null" ]]; do
printf '.'
sleep 1
PROSJEKT_ID=$(opprettProsjekt | jq '.id')
done
echo .
echo "ProsjektID: $PROSJEKT_ID"
sleep 1
echo "Slår av beskyttelse på 'main'"
curl -s -o /dev/null -X DELETE -H "Authorization: Bearer $TOKEN" "$GITLAB_URL/api/v4/projects/$PROSJEKT_ID/protected_branches/main"
echo "Legger til brukere på prosjektet"
curl -s -o /dev/null -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-type: application/json' -d "{\"user_id\":\"$DEG_ID,$ANNEN_ID,$TEAM_ID\", \"access_level\": 40}" "$GITLAB_URL/api/v4/projects/$PROSJEKT_ID/members"
rm -rf ditt
git clone http://du:password@${GITLAB_HOST}/root/Prosjektet.git ditt
cd ditt
git config user.name "Deg Selv"
git config user.email "degselv@example.com"
cd ..
rm -rf team
git clone http://team:password@${GITLAB_HOST}/root/Prosjektet.git team
cd team
git config user.name "Team Medlem"
git config user.email "teammedlem@example.com"
cd ..
./oppdater.sh annen