#!/bin/bash
# ------------------------------------------------------------------
# AUTHOR: [LucidLink Support]
# NAME: share_user_script.sh
# VERSION: 1.0.2
# 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: ./shares_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 instance 1 share assignments, apply users and groups shares within instance 2 ---
lucid2 --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' | grep 'lucid\\' > lucid_shares.txt
while read -r sharedpath usergroup type sharedas permissions; do
shareassign=("lucid2 --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
