#!/bin/bash
# ------------------------------------------------------------------
# AUTHOR: [LucidLink Support]
# NAME: sso_groups_script.sh
# VERSION: 1.0.1
# DESCRIPTION: Single sign-on group import script. Creates groups
# from backup substituting Azure/Okta SSO providers.
#
# 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: ./sso_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 SSO providers ---
cat sso_groups_backup.txt | cut -d ' ' -f 1 | sed 's/okta\\/sso\\/g;s/azure\\/sso\\/g' | grep -v 'lucid\\' | grep 'sso\\' > sso_groups_import.txt
while read -r group; do
groupcreate=("lucid2 group --create '$group' --password '$1'")
echo "$groupcreate" >> sso_groups_commands.txt
eval $groupcreate 2>&1 | tee -a sso_groups_output.txt
done < sso_groups_import.txt

exit