Skip to content

Commit f71f68a

Browse files
committed
[gitlab] - Import user repositories
1 parent 08854de commit f71f68a

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

gitlab/gitlab_user_load.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
#!/bin/bash
3+
4+
INSTANCE="$1"
5+
USERNAME="$2"
6+
GITLAB_REPOS_BASEURL="$3"
7+
PATH_GIT="${4:-/srv/scm/git}"
8+
9+
if [ -z "$INSTANCE" -o -z "$USERNAME" -o -z "$GITLAB_REPOS_BASEURL" ]; then
10+
echo "Usage $0 GITLAB USERNAME BASEURL [PATH]";
11+
exit 1;
12+
fi
13+
14+
ACTIVE_USER=`gitlab -g "$INSTANCE" current-user get`
15+
ACTIVE_ID=`gitlab -g "$INSTANCE" user list | tr '\n' ':' | sed "s/::/|/g" | tr '|' '\n' | grep "$ACTIVE_USER" | cut -d ':' -f2`
16+
17+
echo "Connecting to $INSTANCE Gitlab as $ACTIVE_USER ($ACTIVE_ID)"
18+
echo "Repositories base URL $GITLAB_REPOS_BASEURL"
19+
echo "Importing $USERNAME repositories"
20+
21+
USERID=`gitlab -g "$INSTANCE" user create --email "$USERNAME@cuban.tech" --password '12345678' --username "$USERNAME" --name "$USERNAME @ github" | grep '^id' | cut -d ':' -f2`
22+
23+
echo "[x] - Create Gitlab user $USERNAME ($USERID) ... ok"
24+
25+
ls -1 $PATH_GIT/$USERNAME | while read REPONAME ; do
26+
PROJECT_ID=`gitlab -g "$INSTANCE" user-project create --user-id $USERID --name "$REPONAME" --visibility internal --description "Local mirror of https://github.com/$USERNAME/$REPONAME" --issues-enabled false --wiki-enabled true --snippets-enabled false | grep '^id' | cut -d ':' -f2`
27+
echo "[x] - Create project ($PROJECT_ID) to mirror https://github.com/$USERNAME/$REPONAME ... ok"
28+
gitlab -g "$INSTANCE" project-member create --project-id $PROJECT_ID --access-level 40 --user-id $ACTIVE_ID > /dev/null
29+
echo "[x] - Add $ACTIVE_USER ($ACTIVE_ID) as MASTER member in https://github.com/$USERNAME/$REPONAME ... ok"
30+
cd /srv/scm/git/$USERNAME/$REPONAME
31+
git remote rm cubantech.lan
32+
git remote add cubantech.lan "$GITLAB_REPOS_BASEURL/$USERNAME/${REPONAME}.git" && git push cubantech.lan
33+
echo "[x] - Upload repository to remote $GITLAB_REPOS_BASEURL/$USERNAME/${REPONAME}.git ... ok"
34+
done
35+
36+

0 commit comments

Comments
 (0)