dotfiles-remastered/.local/share/scripts/nc-create-share.sh

31 lines
606 B
Bash
Raw Normal View History

2020-07-02 16:19:14 +00:00
#!/usr/bin/env sh
set -e
# get login cred and endpoint from config script
source $XDG_CONFIG_HOME/nextcloud.config.sh
# Exported vars from config script
#NC_ENDPOINT
#NC_USERNAME
#NC_PASSWORD
# get input
if test -n "$1"; then
REMOTE_PATH=$1
elif test ! -t 0; then
read -r REMOTE_PATH
else
>&2 echo "Provide a remote file"
exit 1
fi
# make request
curl -u "$NC_USERNAME:$NC_PASSWORD" \
-s \
-H "OCS-APIRequest: true" \
-d path="$REMOTE_PATH" \
-d shareType=3 \
-X POST \
"https://$NC_ENDPOINT/ocs/v2.php/apps/files_sharing/api/v1/shares" \
| perl -n -e'/<url>(.+)<\/url>/ && print $1'