Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create users_sync.sh #78

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
fix user deletion, adjust logic
  • Loading branch information
EvilOlaf authored Jun 13, 2024
commit 5f99e6c30381fa88605b1559d4c994e8a71efadf
13 changes: 7 additions & 6 deletions utils/users_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,20 @@ for i in $ORGMEMBERS; do
done

# remove local users not exsting in remote org
ORGMEMBERS_COMPARE=$(echo -n "`curl -L -s \
ORGMEMBERS_COMPARE=$(curl -L -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$ORG/members | jq -r ".[].login"`" \
| sed 's/\ /|/g' | sed -r 's/^/\(/' | sed -r 's/$/\)/')
https://api.github.com/orgs/$ORG/members | jq -r ".[].login" \
| grep -v -E -- "$BLOCKLIST" \
| tr '\n' '|' | sed -r 's/^/\(/' | sed -r 's/\|$/\)/')

for i in $LOCALMEMBERS; do

if ! [[ $i =~ $ORGMEMBERS_COMPARE ]]; then # compare local user against list of remote org members. If not found carry on
if [[ $i =~ $ORGMEMBERS_COMPARE ]]; then # compare local user against list of remote org members. If not found carry on
echo "$i is still member of remote org. Skipping..."
else
echo "$i is not or no longer in the list of remote org members. Removing its legacy..."
userdel --remove "$i"
else
echo "$i is still member of remote org. Skipping..."
fi
done
Loading