Created
July 16, 2021 16:18
-
-
Save sebastianha/71f295c19fbbdcd5695c344602a938b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Place in ~/.local/share/kservices5/ServiceMenus/uto.desktop, remove this line | |
[Desktop Action Edit] | |
Exec=$HOME/bin/uto "%U" | |
Icon=goa-account-owncloud | |
Name=Upload to Owncloud | |
[Desktop Entry] | |
Actions=Edit | |
Icon=goa-account-owncloud | |
ServiceTypes=all/allfiles | |
Type=Service | |
X-KDE-ServiceTypes=KonqPopupMenu/Plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: uto.sh <file> | |
OWNCLOUD_SERVER="<SERVER.DE>" # Insert Owncloud URL here | |
OWNCLOUD_DATA_DIR="/srv/owncloud/" # Insert Owncloud base dir here | |
OWNCLOUD_INST_DIR="/var/www/owncloud/" # Insert Owncloud install dir here | |
OWNCLOUD_WEB_PATH="/owncloud/" # Insert Owncloud web path here | |
OWNCLOUD_USERNAME="<USERNAME>" # Insert Owncloud username here | |
OWNCLOUD_PASSWORD="<PASSWORD>" # Insert Owncloud password here | |
OWNCLOUD_FOLDER="/upload" # Insert target Owncloud upload folder for user here, relative to user dir | |
FILENAME=`basename "$1"` | |
DATENOW=`date +%Y%m%d%H%M%S` | |
# Upload via rsync, server has to be accessible via SSH and SSH key | |
rsync -v --progress -s "$1" "${OWNCLOUD_SERVER}:${OWNCLOUD_DATA_DIR}/${OWNCLOUD_USERNAME}/files/${OWNCLOUD_FOLDER}/${DATENOW}_${FILENAME}" | |
# Fix permissions on owncloud server and refresh file list for user | |
ssh ${OWNCLOUD_SERVER} "chown www-data:www-data "${OWNCLOUD_DATA_DIR}/${OWNCLOUD_USERNAME}/files/${OWNCLOUD_FOLDER}/*"; cd ${OWNCLOUD_INST_DIR}; sudo -u www-data php7.3 occ files:scan ${OWNCLOUD_USERNAME} >/dev/null" | |
# Share uploaded file and get resulting URL | |
URL=`curl -s --user ${OWNCLOUD_USERNAME}:${OWNCLOUD_PASSWORD} https://${OWNCLOUD_SERVER}/${OWNCLOUD_WEB_PATH}/ocs/v1.php/apps/files_sharing/api/v1/shares --data "path=/${OWNCLOUD_FOLDER}/${DATENOW}_${FILENAME}&shareType=3&format=json" | jq -r .ocs.data.url` | |
# Copy url to clip board | |
echo $URL | xclip -selection c | |
# Show toast notification when upload has finished and URL is ready in clip board | |
/usr/bin/kdialog --title "Upload to Owncloud" --passivepopup "Upload of $FILENAME complete" "5" | |
# Echo URL when using via command line | |
echo "Link to share: ${URL}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment