#!/bin/bash
# ------------------------------------------------------------------
# AUTHOR: [LucidLink Support]
# NAME: sso_shares_script.sh
# VERSION: 1.0.1
# DESCRIPTION: Single sign-on share import script. Creates shares
# 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
# ------------------------------------------------------------------

IFS=";"
USAGE="Usage: ./sso_shares_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 share backup excluding Lucid users and substitute SSO provider ---
cat sso_shares_backup.txt | sed -e 's/ \{2,\}/;/g;s/\[user\]/;user/g;s/\[group\]/;group/g;s/okta\\/sso\\/g;s/azure\\/sso\\/g;s/ ;/;/g;s/read, write/read,write/g' | grep -v 'lucid\\' | grep 'sso\\' > sso_shares_import.txt
while read -r sharedpath usergroup type sharedas permissions; do
shareset=("lucid2 share --set '$sharedpath' --$type '$usergroup' --permissions $permissions --password '$1'")
echo "$shareset" >> sso_shares_commands.txt
eval $shareset 2>&1 | tee -a sso_shares_output.txt
done < sso_shares_import.txt

exit