#!/bin/bash
# ------------------------------------------------------------------
# AUTHOR: [LucidLink Support]
# NAME: legacy_sso_admin_script.sh
# VERSION: 1.0.1
# DESCRIPTION: Lists users from Filespace instance 1 and imports
# into Filespace instance 2, assigning Admin roles.
#
# 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
# ------------------------------------------------------------------

IFS=";"
USAGE="Usage: ./legacy_sso_admin_script.sh <fs1rootpwd> <fs2rootpwd>
Request failed with: Bad Request
Empty required parameter 'password' is not allowed!"

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

# --- List user Admin role assigments in instance 1 and assign accordingly within instance 2 ---
lucid --instance 1 user --password ''$1'' | awk '{print $1,$NF}' | sed 's/user//g;s/ Administrator/;admin/g' | grep ';admin' | grep -v 'lucid\\' | grep "\S" > legacy_sso_admin_role.txt
while read -r user role; do
usrcreate=("lucid --instance 2 user --set '$user' --add-role $role --password '$2'")
echo "$usrcreate" >> legacy_sso_admin_role_commands.txt
eval $usrcreate 2>&1 | tee -a legacy_sso_admin_role_output.txt
done < legacy_sso_admin_role.txt

exit
