Skip to content

Instantly share code, notes, and snippets.

@bjcubsfan
Forked from lanwin/add_users_to_projects.sh
Created March 9, 2012 16:35
Show Gist options
  • Save bjcubsfan/2007388 to your computer and use it in GitHub Desktop.
Save bjcubsfan/2007388 to your computer and use it in GitHub Desktop.
Script to Automatically add all GitLab users to all projects
#!/bin/sh
baseurl=http://mygitlaburl
usermail=adminuser@mymailserver
userpass=adminpassword
repo_access=2 #0=denied 1=read 2=read&write
project_access=2 #0=deined 1=read 2=report 3=admin
# login
curl -s -I -c cookies.txt -d "utf8=✓&user[email]=$usermail&user[password]=$userpass&commit=Sign+in" $baseurl/users/sign_in
# get auth token
authtoken=`curl -s -c cookies.txt -b cookies.txt $baseurl | grep -Po '(?<=<meta content=")([^"]+)(?=" name="csrf-token" />)'`
# get user ids
userIdsStr=`curl -s -c cookies.txt -b cookies.txt $baseurl/admin | grep -Po '(?<=href="/admin/users/)\d+(?=/edit")'|tr '\n' ','|sed 's/,/\&user_ids\[\]=/g'`
# get project codes and filter out private projects
projectCodes=`curl -s -c cookies.txt -b cookies.txt $baseurl/admin/projects | grep -Po '(?<=href="/admin/projects/)([^/]+)(?=/edit")' | grep -v 'private'`
for projectCode in $projectCodes
do
echo "> Project: $projectCode"
postdata="utf8=✓&_method=put&authenticity_token=$authtoken&user_ids[]=$userIdsStr&project_access=$project_access&repo_access=$repo_access&commit=Add"
curl -s -I -b cookies.txt -d $postdata $baseurl/admin/projects/$projectCode/team_update
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment