#!/bin/bash
# ------------------------------------------------------------------
# AUTHOR: [LucidLink Support]
# NAME: group_script.sh
# VERSION: 1.0.1
# DESCRIPTION: Lists groups from Filespace instance 1 and imports
# into Filespace instance 2
#
# 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: ./group_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 groups from instance 1 and create in instance 2 ---
lucid --instance 1 group --password ''$1'' | cut -d ' ' -f 1 | grep 'lucid\\' > lucid_groups.txt
while read -r group; do
groupcreate=("lucid --instance 2 group --create '$group' --password '$2'")
echo "$groupcreate" >> lucid_group_commands.txt
eval $groupcreate 2>&1 | tee -a lucid_groups_output.txt
done < lucid_groups.txt

exit
