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
Add blocklist and token support
  • Loading branch information
EvilOlaf authored Jun 11, 2024
commit 1345b0cf04f4f205724ca9db184222c352bae018
24 changes: 19 additions & 5 deletions utils/users_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
# where are the user directories?
# NO trailing slash!
# the owner of the parent directory must be "root"!
# configure nginx accordingly
USERPATH=/var/www/users

# which group is used to catch and jail users into their sftp chroot?
SFTPGROUP=sftponly

# classic token from any organization member with "read:org" permission
TOKEN=xxxxxxxxxxxxxxxx

# the organization you want to read members from
ORG=armbian

# Users that shall not get access
BLOCKLIST='armbianworker|examplemember1|examplemember2'

### DO NOT EDIT BELOW! ###

Expand Down Expand Up @@ -42,12 +50,18 @@ fi



# grab a list of current remote org members and make it comparable
ORGMEMBERS=$(curl -s https://api.github.com/orgs/armbian/members | jq -r ".[].login")
# Grab a list of local directories and make it comparable
# grab a list of current remote org members, filter blocked ones
ORGMEMBERS=$(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" \
| grep -v -E -- "$BLOCKLIST" )
# Grab a list of local directories...
# We assume that existing directory means locally existing user as well
LOCALMEMBERS=$(echo -n "`ls members/`")
LOCALMEMBERS_COMP=$(echo -n "`ls members/`" | sed 's/\ /|/g' |sed -r 's/^/\(/' |sed -r 's/$/\)/')
LOCALMEMBERS=$(echo -n "`ls $USERPATH`")
# ...and make it comparable for shell
LOCALMEMBERS_COMP=$(echo -n "`ls $USERPATH`" | sed 's/\ /|/g' |sed -r 's/^/\(/' |sed -r 's/$/\)/')


# loop through remote org members and add if not existing
Expand Down
Loading