script-server
script-server copied to clipboard
google groups
google added new feature to add permissions to google groups so you may see groups in project may be we can add it so, no need to define groups twice
thanks
Hi @yosefy, thanks for the ticket, it's a really nice one!
You can use my script, I fixed it like this:
#!/bin/bash
$gam=~/bin/gamdir/gam # this must be set to the path of gam on your system
JSON_FILE="$HOME/bin/script-server/conf/conf.json"
# get users from google group
echo "Building array..."
readarray -t EMAILS < <($gam print group-members group GOOGLEGROUPNAME fields email | grep GOOGLEGROUPNAME | cut -d ',' -f2)
NULL=`declare -p EMAILS`
echo -e "done.\n"
# create new json values from array
buildJSON () {
echo -n '[ '
while [ $# -gt 0 ]; do
x=${1//\\/\\\\}
echo -n \"${x//\"/\\\"}\"
[ $# -gt 1 ] && echo -n ', '
shift
done
echo ' ]'
}
echo "Building new JSON text..."
NEWLINE=`buildJSON "${EMAILS[@]}"`
NEWLINE_USERS=`echo -e "\"allowed_users\": $NEWLINE,"`
NEWLINE_ADMINS=`echo -e "\"admin_users\": $NEWLINE"`
echo " $NEWLINE_USERS"
echo " $NEWLINE_ADMINS"
echo -e "done.\n"
echo -n "Replacing lines in $JSON_FILE... "
sed -i "11s/.*/\t$NEWLINE_USERS/" $JSON_FILE
sed -i "12s/.*/\t$NEWLINE_ADMINS/" $JSON_FILE
echo -e "done.\n"
echo -n "Restarting service script-server..."
sleep 3 # without a short break we won't have much info in webUI
sudo systemctl restart script-server # to get new users working in script-server
echo " done." # won't appear in webUI of script-server anymore
- You will need to setup gam before from https://github.com/jay0lee/GAM/wiki and setup a project in google developers console.
- Change
sed -i "11s...andsed -i "12s...to the line numbers to replace of your conf.json. In my case ist 11 and 12. To make this more flexible you could also just search for the lines and assing line numbers as they are, even after manual editing. Up to you. - For the last command you need to modify sudoers file to prevent asking for sudoers password.
As all users in the group I am getting the users from are admins, it's the same in both replaced lines. Just create a new array from another group if different.
You can run this as cronjob or even with script-server to update users/admins after change in the google group.
Kay