#!/bin/bash
# ------------------------------------------------------------------
# AUTHOR: [LucidLink Support]
# NAME: sso_lucid_share_user_script.sh
# VERSION: 1.0.1
# DESCRIPTION: Lists shares 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
# ------------------------------------------------------------------

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

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

# --- List instance 1 share assignments, apply users and groups shares within instance 2 ---
lucid --instance 1 share --configured --password ''$1'' | sed -e 's/ \{2,\}/;/g;s/\[user\]/;user/g;s/\[group\]/;group/g;s/ ;/;/g;s/read, write/read,write/g' | tail -n +2 | grep "\S" > lucid_shares.txt
while read -r sharedpath usergroup type sharedas permissions; do
shareassign=("lucid --instance 2 share --set '$sharedpath' --$type '$usergroup' --permissions $permissions --password '$2'")
echo "$shareassign" >> lucid_shares_commands.txt
eval $shareassign 2>&1 | tee -a lucid_shares_output.txt
done < lucid_shares.txt

exit
