Skip to content

Instantly share code, notes, and snippets.

@lichti
Created September 19, 2016 21:48
Show Gist options
  • Save lichti/1b4ef239a2acdc752c57f778d9262cc7 to your computer and use it in GitHub Desktop.
Save lichti/1b4ef239a2acdc752c57f778d9262cc7 to your computer and use it in GitHub Desktop.
move users from one group to another
#/bin/bash
USER=$1
PASS=$2
GROUPOLD=$3
GROUPNEW=$4
JIRAURL="https://dafiti.jira.com/rest/api/2"
STARTAT=0
MAXRESULT=50
QTD=$(curl -s -u "${USER}:${PASS}" "${JIRAURL}/group?groupname=${GROUPOLD}" | jq '.users.size')
echo $QTD
LAST="false"
echo '' > /tmp/users-${GROUPOLD}.json
while [ "$LAST" = "false" ];
do
USERS=$(curl -s -u "${USER}:${PASS}" "${JIRAURL}/group/member?groupname=${GROUPOLD}&maxResults=${MAXRESULT}&startAt=${STARTAT}")
LAST=$(echo $USERS | jq '.isLast')
echo "$USERS" | jq -c '.values[] | { name: .name }' >> /tmp/users-${GROUPOLD}.json
STARTAT=$((STARTAT + MAXRESULT))
done
while read LINHA;
do
curl -s -u "${USER}:${PASS}" "${JIRAURL}/group/user?groupname=${GROUPNEW}" -X POST -H 'Content-Type: application/json' -d "${LINHA}"
done < /tmp/users-${GROUPOLD}.json
while read LINHA;
do
USER_DEL=$(echo ${LINHA} | jq -c '.name' | sed s/\"//g)
curl -s -u "${USER}:${PASS}" "${JIRAURL}/group/user?groupname=${GROUPOLD}&username=${USER_DEL}" -X DELETE -H 'Content-Type: application/json'
done < /tmp/users-${GROUPOLD}.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment