#!/bin/bash
# ------------------------------------------------------------------
# AUTHOR: [LucidLink Support]
# NAME: jit_shares_script.sh
# VERSION: 1.0.1
# DESCRIPTION: Single sign-on share import script. Creates shares
# from backup.
#
# 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: ./jit_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 importing SSO provider ---
cat jit_shares_backup.txt | sed -e 's/ \{2,\}/;/g;s/\[user\]/;user/g;s/\[group\]/;group/g;s/ ;/;/g;s/read, write/read,write/g' | grep -v 'lucid\\' | grep 'sso\\' > jit_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" >> jit_shares_commands.txt
eval $shareset 2>&1 | tee -a jit_shares_output.txt
done < jit_shares_import.txt

exit