#!/bin/bash
# ------------------------------------------------------------------
# AUTHOR: [LucidLink Support]
# NAME: jit_groups_script.sh
# VERSION: 1.0.1
# DESCRIPTION: Single sign-on group import script. Creates groups
# from backup.
#
# THE SCRIPT IS PROVIDED “AS IS” AND “AS AVAILABLE” AND IS WITHOUT
# WARRANTY OF ANY KIND. PLEASE REVIEW ALL TERMS AND CONDITIONS.
# https://www.lucidlink.com/legal-documents
# ------------------------------------------------------------------

USAGE="Usage: ./jit_groups_script.sh <password>
Request failed with: Bad Request
Empty required parameter 'password' is not allowed!"

# --- Ensure password ---
if [ $# == 0 ] ; then
    echo "$USAGE"
    exit 1;
fi

# --- Loop through backup creating group substituting jit_ providers ---
cat jit_groups_backup.txt | cut -d ' ' -f 1 | grep -v 'lucid\\' | grep 'sso\\' > jit_groups_import.txt
while read -r group; do
groupcreate=("lucid2 group --create '$group' --password '$1'")
echo "$groupcreate" >> jit_groups_commands.txt
eval $groupcreate 2>&1 | tee -a jit_groups_output.txt
done < jit_groups_import.txt

exit