From 5334753b696a14202c937ee0e23bda7694f7c736 Mon Sep 17 00:00:00 2001 From: Niklas Date: Thu, 2 Jul 2020 18:19:14 +0200 Subject: [PATCH] added nextcloud scripts --- .local/share/scripts/nc-create-share.sh | 30 +++++++++++++++++++++++++ .local/share/scripts/nc-share-file.sh | 25 +++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100755 .local/share/scripts/nc-create-share.sh create mode 100755 .local/share/scripts/nc-share-file.sh diff --git a/.local/share/scripts/nc-create-share.sh b/.local/share/scripts/nc-create-share.sh new file mode 100755 index 0000000..6a8f89d --- /dev/null +++ b/.local/share/scripts/nc-create-share.sh @@ -0,0 +1,30 @@ +#!/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>/ && print $1' diff --git a/.local/share/scripts/nc-share-file.sh b/.local/share/scripts/nc-share-file.sh new file mode 100755 index 0000000..89d002d --- /dev/null +++ b/.local/share/scripts/nc-share-file.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env sh + +# requires rclone to be setup + +set -e + +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "$SCRIPT") + +source $XDG_CONFIG_HOME/nextcloud.config.sh + +if test -n "$1"; then + FILE_PATH=$1 +elif test ! -t 0; then + read -r FILE_PATH +else + >&2 echo "Provide a file" + exit 1 +fi + +FILENAME=$(basename $FILE_PATH) + +rclone copy "$FILE_PATH" "$NC_RCLONE_REMOTE:/$NC_SHARE_DIR" + +$SCRIPTPATH/nc-create-share.sh "$NC_SHARE_DIR/$FILENAME"