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
remove debug
  • Loading branch information
EvilOlaf authored Jun 11, 2024
commit 0d07a6f064f1cc3bfb1104e00108529a12b20ad7
9 changes: 3 additions & 6 deletions utils/users_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ USERPATH=/var/www/users
SFTPGROUP=sftponly

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

# the organization you want to read members from
ORG=armbian
Expand Down Expand Up @@ -55,7 +55,7 @@ then
echo "Add this to your \"sshd_config\" if not done already."
echo ""
echo "Match Group $SFTPGROUP"
echo " ChrootDirectory $PATUSERH/%u"
echo " ChrootDirectory $USERPATH/%u"
echo " ForceCommand internal-sftp"
echo " AllowTcpForwarding no"
echo ""
Expand Down Expand Up @@ -83,17 +83,14 @@ echo "Already existing members at \"$USERPATH\": \"$LOCALMEMBERS\"."
# ...and make it comparable for shell (remove trailing slash, replace newline with | and add round brackets)
LOCALMEMBERS_COMPARE=$(echo -n "`ls -d -- */`" | sed 's/\///g' | tr '\n' '|' | sed -r 's/^/\(/' | sed -r 's/$/\)/')

# DEBUG
exit 0
# END DEBUG

# loop through remote org members and add if not existing
for i in $ORGMEMBERS; do

if ! [[ $i =~ $LOCALMEMBERS_COMPARE ]]; then # skip locally already existing users

# create local user and directory
echo " $i - no local directory found. Creating..."
echo "$i - no local directory found. Creating..."
if ! useradd -m -s /bin/bash -G "$SFTPGROUP" -d "$USERPATH"/"$i" "$i"
then
echo "$i's directory could not be created for whatever reason"
Expand Down
Loading