Skip to content

Instantly share code, notes, and snippets.

@adamancini
Created November 22, 2017 18:06
Show Gist options
  • Save adamancini/eeede41ea546f8d903b8c3260fd025d0 to your computer and use it in GitHub Desktop.
Save adamancini/eeede41ea546f8d903b8c3260fd025d0 to your computer and use it in GitHub Desktop.
#!/bin/bash
#run anywhere with curl and jq installed.
# 11/17 - [email protected]
set -e
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
NORMAL=$(tput sgr0)
password=Pa22word
url=ucp.dockr.life
token=$(curl -sk -d '{"username":"admin","password":"'$password'"}' https://$url/auth/login | jq -r .auth_token)
echo -n " adding teams "
curl -sk -X POST https://$url/accounts/ -H "Authorization: Bearer $token" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -d "{\"name\":\"fda\",\"isOrg\":true}" > /dev/null 2>&1
full_team_id=$(curl -sk -X POST https://$url/accounts/fda/teams -H "Authorization: Bearer $token" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -d "{\"name\":\"ctpfull\",\"description\":\"CTP Full\"}" | jq -r .id)
view_team_id=$(curl -sk -X POST https://$url/accounts/fda/teams -H "Authorization: Bearer $token" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -d "{\"name\":\"ctpview\",\"description\":\"CTP View\"}" | jq -r .id)
echo "$GREEN" "[ok]" "$NORMAL"
echo -n " adding users "
curl -skX POST https://$url/api/accounts -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Content-Type: application/json;charset=utf-8' -H "Authorization: Bearer $token" -d "{\"role\":1,\"username\":\"ctpfull1\",\"password\":\"$password\",\"first_name\":\"CTP Full\"}"
curl -skX POST https://$url/api/accounts -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Content-Type: application/json;charset=utf-8' -H "Authorization: Bearer $token" -d "{\"role\":1,\"username\":\"ctpview1\",\"password\":\"$password\",\"first_name\":\"CTP View\"}"
echo "$GREEN" "[ok]" "$NORMAL"
echo -n " adding users to teams "
curl -skX PUT "https://$url/accounts/fda/teams/ctpfull/members/ctpfull1" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{}" > /dev/null 2>&1
curl -skX PUT "https://$url/accounts/fda/teams/ctpview/members/ctpview1" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{}" > /dev/null 2>&1
echo "$GREEN" "[ok]" "$NORMAL"
echo -n " adding collections "
ctp_col_id=$(curl -skX POST "https://$url/collections" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{\"name\":\"ctp\",\"path\":\"/\",\"parent_id\": \"swarm\"}" | jq -r .id)
echo "$GREEN" "[ok]" "$NORMAL"
echo -n " adding grants "
curl -skX PUT https://$url/collectionGrants/$view_team_id/$ctp_col_id/viewonly -H "accept: application/json" -H "Authorization: Bearer $token"
curl -skX PUT https://$url/collectionGrants/$full_team_id/$ctp_col_id/fullcontrol -H "accept: application/json" -H "Authorization: Bearer $token"
curl -skX PUT https://$url/collectionGrants/$full_team_id/$ctp_col_id/fullcontrol -H "accept: application/json" -H "Authorization: Bearer $token"
echo "$GREEN" "[ok]" "$NORMAL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment