├── .gitignore ├── LICENSE.txt ├── README.md ├── config.sample ├── installer ├── nextcloud.png ├── shareLinkCreator ├── shareLinkCreator.nemo_action └── shareLinkCreator.thunar_action /.gitignore: -------------------------------------------------------------------------------- 1 | config 2 | *~ 3 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Bjoern Schiessle 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Share Link Creator 2 | ================== 3 | 4 | Provides the ability to upload a file to Nextcloud via a supported file manager 5 | and receive a link to the uploaded file which can then be emailed or shared in 6 | another way. 7 | 8 | This script can be integrated in the Thunar file manager as a "custom 9 | action". The program should also works with other file managers which provide 10 | similar possibilities to integrate shell scripts. I developed and used this 11 | script with Thunar only but I got some feedback that it also works nicely with 12 | Dolphin, Nautilus and Nemo. 13 | 14 | The program expects the absolute path to the files. Once the custom action is 15 | configured you can execute the program from the right-click context menu. The 16 | program works for all file types and also for directories. Once the script gets 17 | executed it will first upload the files/directories to your Nextcloud and 18 | afterwards it will generate a public link to access them. The link will be 19 | copied directly to your clipboard and a dialog will inform you about the 20 | URL. If you uploaded a single file or directory than the file/directory will be 21 | created directly below your "uploadTarget" as defined below. If you selected 22 | multiple files, than the programm will group them together in a directory named 23 | with the current timestamp. 24 | 25 | Requirements 26 | ------------ 27 | 28 | - curl 29 | - xclip 30 | - zenity 31 | 32 | Configuration 33 | ------------- 34 | 35 | Before you can use the program you need to adjust at least the "baseURL" at 36 | "config.sample" and rename the file to "config". If you keep "username" and/or 37 | "password" empty a dialog will show up and ask for the credentials. 38 | 39 | 40 | Installing with Thunar (Xfce) 41 | ----------------------------- 42 | 43 | Start Thunar and go to "Edit->Configure Custom Actions...". Here you can add a 44 | action to execute the shareLinkCreator. Make sure to pass the "%F" parameter 45 | (paths to all selected files) to the program. Under "Appearance Conditions" you 46 | can enable all file types. 47 | 48 | 49 | Installing with Nemo (Linux Mint / Cinnamon) 50 | -------------------------------------------- 51 | 52 | You will need to copy the shareLinkCreator.nemo_action to: 53 | 54 | ~/.local/share/nemo/actions/ 55 | 56 | Next edit the file, and replace 57 | 58 | Exec=/path/to/shareLinkCreator/shareLinkCreator %F 59 | 60 | With the full path to the shareLinkCreator file, and voila! Make sure you have 61 | configured the shareLinkCreator file as instructed above. 62 | -------------------------------------------------------------------------------- /config.sample: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # config parameters for the shareLinkCreator 3 | 4 | baseURL="https://localhost/nextcloud" 5 | uploadTarget="instant links" 6 | username="" 7 | password="" 8 | 9 | # if you use a self signed ssl cert you can specify here the path to your root 10 | # certificate 11 | cacert="" 12 | 13 | # Switch to 0 to use echo instead of zenity 14 | usezenity=1 15 | 16 | # Toggles use of notify-send (preferred over zenity for progress notifications) 17 | usenotify=1 18 | -------------------------------------------------------------------------------- /installer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # test for dependencies 4 | if command -v zenity >/dev/null 2>&1; 5 | then 6 | echo -e "Looking for zenity...OK.\n" 7 | else 8 | echo -e "Looking for zenity...MISSING.\nPlease install it and restart this installer.\n" 9 | exit; 10 | fi 11 | 12 | if command -v xclip >/dev/null 2>&1; 13 | then 14 | echo -e "Looking for xclip...OK.\n" 15 | else 16 | echo -e "Looking for xclip...MISSING.\nPlease install it and restart this installer.\n" 17 | exit; 18 | fi 19 | 20 | if command -v curl >/dev/null 2>&1; 21 | then 22 | echo -e "Looking for curl...OK.\n" 23 | else 24 | echo -e "Looking for curl...MISSING.\nPlease install it and restart this installer.\n" 25 | exit; 26 | fi 27 | 28 | if [ -f config ] 29 | then 30 | echo "config file exists..." 31 | else 32 | echo -e "config file...MISSING.\nPlease edit config.sample and copy it to config before running this installer.\n" 33 | exit; 34 | fi 35 | 36 | sleep 2 37 | 38 | ## nautilus specific 39 | if [ -f /usr/bin/nautilus ] 40 | then 41 | echo "Nautilus installed, copying to nautilus scripts..." 42 | cp shareLinkCreator ~/.local/share/nautilus/scripts/ 43 | cp config ~/.local/share/nautilus/scripts/ 44 | exit; 45 | else 46 | echo "Nautilus is not installed." 47 | fi 48 | 49 | # add icon 50 | echo "Installing Nextcloud icon to your homedir (/home/$(whoami)/.icons)..." 51 | if [ ! -d "~/.icons" ]; then 52 | mkdir ~/.icons 53 | fi 54 | cp nextcloud.png ~/.icons/ 55 | 56 | # place core bash script 57 | echo "Installing sharing script to your homedir (/home/$(whoami)/bin)..." 58 | if [ ! -d "~/bin" ]; then 59 | mkdir ~/bin 60 | fi 61 | cp shareLinkCreator ~/bin 62 | 63 | ## thunar specific 64 | if [ -f /usr/bin/thunar ] 65 | then 66 | echo "Thunar installed, processing custom actions file..." 67 | # backup original thunar actions file 68 | cp ~/.config/Thunar/uca.xml ~/.config/Thunar/uca.xml.sharelinkBAK 69 | 70 | # replace last line "" 71 | sed -i '$d' ~/.config/Thunar/uca.xml 72 | cat shareLinkCreator.thunar_action >> ~/.config/Thunar/uca.xml 73 | 74 | echo "Restarting Thunar." 75 | killall -9 thunar -u $(whoami) 76 | thunar 77 | else 78 | echo "Thunar is not installed." 79 | fi 80 | 81 | ## nemo specific 82 | if [ -f /usr/bin/nemo ] 83 | then 84 | echo "Nemo installed, copying custom action file..." 85 | cp shareLinkCreator.nemo.action ~/.local/share/nemo/actions/ 86 | else 87 | echo "Nemo is not installed." 88 | fi 89 | -------------------------------------------------------------------------------- /nextcloud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/schiessle/shareLinkCreator/1969ba6bc4540bb51f5c25e33a7ea4af811d25b2/nextcloud.png -------------------------------------------------------------------------------- /shareLinkCreator: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Public Link Creator Version 1.0 4 | # 5 | # (c) Copyright 2013 Bjoern Schiessle 6 | # 7 | # This program is free software released under the MIT License, for more details 8 | # see LICENSE.txt or http://opensource.org/licenses/MIT 9 | # 10 | # Description: 11 | # 12 | # The program was developed for the Thunar file manager but it should also 13 | # works with other file managers which provide similar possibilities to 14 | # integrate shell scripts. For example I got some feedback that it also works 15 | # nicely with Dolphin and Nautilus. 16 | # 17 | # This script can be integrated in the Thunar file manager as a "custom 18 | # action". If you configure the "custom action" in Thunar, make sure to pass 19 | # the paths of all selected files to the program using the "%F" parameter. The 20 | # program expects the absolute path to the files. Once the custom action is 21 | # configured you can execute the program from the right-click context menu. The 22 | # program works for all file types and also for directories. Once the script 23 | # gets executed it will first upload the files/directories to your Nextcloud and 24 | # afterwards it will generate a public link to access them. The link will be 25 | # copied directly to your clipboard and a dialog will inform you about the 26 | # URL. If you uploaded a single file or directory than the file/directory will 27 | # be created directly below your "uploadTarget" as defined below. If you 28 | # selected multiple files, than the programm will group them together in a 29 | # directory named with the current timestamp. 30 | # 31 | # Before you can use the program you need to adjust at least the "baseURL", 32 | # "username" and "password" config parameter below. If you keep "username" 33 | # and/or "password" empty a dialog will show up and ask for the credentials. 34 | # 35 | # Requirements: 36 | # 37 | # - curl 38 | # - xclip 39 | # - zenity 40 | 41 | # load config parameters 42 | . "$(dirname $0)/config" 43 | 44 | # constants 45 | TRUE=0 46 | FALSE=1 47 | 48 | webdavURL="$baseURL/remote.php/webdav" 49 | url=$(echo "$webdavURL/$uploadTarget" | sed 's/\ /%20/g') 50 | shareAPI="$baseURL/ocs/v1.php/apps/files_sharing/api/v1/shares" 51 | curlOpts="" 52 | if [ -n "$cacert" ]; then 53 | curlOpts="$curlOpts --cacert $cacert" 54 | fi 55 | 56 | # check if base dir for file upload exists 57 | baseDirExists() { 58 | if curl -u "$username":"$password" --output /dev/null $curlOpts --silent --head --fail "$url"; then 59 | return $FALSE 60 | fi 61 | return $TRUE 62 | } 63 | 64 | checkCredentials() { 65 | curl -u "$username":"$password" $curlOpts --output /dev/null --silent --fail "$webdavURL" 66 | if [ $? != 0 ]; then 67 | msg="Username or password does not match" 68 | if [ $usezenity -eq 1 ]; then 69 | zenity --error --title="Nextcloud Public Link Creator" --text="$msg" 70 | exit 1 71 | else 72 | echo "$msg" 73 | exit 1 74 | fi 75 | fi 76 | } 77 | 78 | # upload files, first parameter will be the upload target from the second 79 | # parameter on we have the list of files 80 | uploadFiles() { 81 | for filePath in "${@:2}" 82 | do 83 | basename=$(basename "$filePath") 84 | basename=$(echo "$basename" | sed 's/\ /%20/g') 85 | if [ -f "$filePath" ]; then 86 | curl -u "$username":"$password" $curlOpts -T "$filePath" "$1/$basename" 87 | count=$(($count+1)) 88 | if [ $usezenity -eq 1 ]; then 89 | echo $(($count*100/$numOfFiles)) >&3; 90 | fi 91 | else 92 | curl -u "$username":"$password" $curlOpts -X MKCOL "$1/$basename" 93 | uploadDirectory "$1/$basename" "$filePath" 94 | fi 95 | done 96 | return $TRUE 97 | } 98 | 99 | # upload a directory recursively, first parameter contains the upload target 100 | # and the second parameter contains the path to the local directory 101 | uploadDirectory() { 102 | while read filePath; do 103 | filePath=$(basename "$filePath") 104 | urlencodedFilePath=$(echo "$filePath" | sed 's/\ /%20/g') 105 | if [ -d "$2/$filePath" ]; then 106 | curl -u "$username":"$password" $curlOpts -X MKCOL "$1/$urlencodedFilePath" 107 | uploadDirectory "$1/$urlencodedFilePath" "$2/$filePath" 108 | else 109 | curl -u "$username":"$password" $curlOpts -T "$2/$filePath" "$1/$urlencodedFilePath" 110 | count=$(($count+1)) 111 | if [ $usezenity -eq 1 ]; then 112 | echo $(($count*100/$numOfFiles)) >&3; 113 | fi 114 | fi 115 | done < <(find "$2" -mindepth 1 -maxdepth 1) 116 | 117 | } 118 | 119 | # create public link share, first parameter contains the path of the shared file/folder 120 | createShare() { 121 | result=$(curl -u "$username":"$password" $curlOpts --silent "$shareAPI" -d path="$1" -d shareType=3 -H "OCS-APIRequest: true") 122 | shareLink=$(echo $result | sed -e 's/.*\(.*\)<\/url>.*/\1/') 123 | shareLink=$(echo $shareLink | sed 's/\&/\&/') 124 | echo -n $shareLink | xclip -sel clip 125 | return $TRUE 126 | 127 | } 128 | 129 | # if no password is set in the script we ask the user to enter them 130 | askForPassword() { 131 | ENTRY=`zenity --password --title="Nextcloud Public Link Creator"` 132 | 133 | case $? in 134 | 0) 135 | password=`echo $ENTRY | cut -d'|' -f1` 136 | ;; 137 | 1) 138 | exit 0;; 139 | -1) 140 | exit 1;; 141 | esac 142 | } 143 | 144 | # if no username/password is set in the script we ask the user to enter them 145 | askForUserPassword() { 146 | ENTRY=`zenity --password --username --title="Nextcloud Public Link Creator"` 147 | 148 | case $? in 149 | 0) 150 | username=`echo $ENTRY | cut -d'|' -f1` 151 | password=`echo $ENTRY | cut -d'|' -f2` 152 | ;; 153 | 1) 154 | exit 0;; 155 | -1) 156 | exit 1;; 157 | esac 158 | } 159 | 160 | askForUserPasswordNonZenity() { 161 | read -p "Username: " username 162 | read -s -p "Password: " password 163 | echo 164 | if [ -z $password ] || [ -z $username ]; then 165 | exit 1 166 | fi 167 | } 168 | 169 | askForPasswordNonZenity() { 170 | read -s -p "Password for $username: " password 171 | echo 172 | if [ -z $password ] || [ -z $username ]; then 173 | exit 1 174 | fi 175 | } 176 | 177 | 178 | 179 | if [ $# -lt 1 ]; then 180 | msg="no file was selected!" 181 | if [ $usezenity -eq 1 ]; then zenity --error --title="Nextcloud Public Link Creator" --text="$msg" 182 | else echo "$msg" 183 | fi 184 | exit 1 185 | fi 186 | 187 | if [ -z "$password" ] && [ -z "$username" ]; then 188 | # ask for both password and username 189 | if [ $usezenity -eq 1 ]; then askForUserPassword 190 | else askForUserPasswordNonZenity 191 | fi 192 | elif [ -z "$password" ]; then 193 | # ask for password only 194 | if [ $usezenity -eq 1 ]; then askForPassword 195 | else askForPasswordNonZenity 196 | fi 197 | fi 198 | 199 | checkCredentials 200 | 201 | msg="Uploading files and generating a public link" 202 | if [ $usenotify -eq 1 ]; then 203 | notify-send -c transfer "Nextcloud Public Link Creator" "$msg" 204 | elif [ $usezenity -eq 1 ]; then 205 | exec 3> >(zenity --progress --title="Nextcloud Public Link Creator" --text=$msg --auto-kill --auto-close --percentage=0 --width=400) 206 | else 207 | echo $msg 208 | fi 209 | 210 | 211 | numOfFiles=$(find "$@" -type f | wc -l) 212 | count=0 213 | 214 | if baseDirExists; then 215 | curl -u "$username":"$password" $curlOpts -X MKCOL "$url" 216 | fi 217 | 218 | # if we have more than one file selected we create a folder with 219 | # the current timestamp 220 | if [ $# -gt 1 ]; then 221 | share=$(date +%s) 222 | url="$url/$share" 223 | curl -u "$username":"$password" $curlOpts -X MKCOL "$url" 224 | elif [ $# -eq 1 ]; then 225 | share=$(basename "$1") 226 | else 227 | # Errors for this are already shown above. 228 | exit 1 229 | fi 230 | 231 | if uploadFiles $url "$@"; then 232 | createShare "/$uploadTarget/$share" 233 | fi 234 | 235 | output="File uploaded successfully. Following public link was generated and copied to your clipboard: $shareLink" 236 | if [ $usenotify -eq 1 ]; then 237 | # Lazy hack for xfce4-notifyd cutting off long text 238 | output="File uploaded successfully. Following public link was generated\nand copied to your clipboard:\n$shareLink" 239 | notify-send -c transfer.complete "Nextcloud Public Link Creator" "$output" 240 | elif [ $usezenity -eq 1 ]; then 241 | zenity --info --title="Nextcloud Public Link Creator" --text="$output" --no-markup 242 | else 243 | echo $output 244 | fi 245 | -------------------------------------------------------------------------------- /shareLinkCreator.nemo_action: -------------------------------------------------------------------------------- 1 | [Nemo Action] 2 | Active=true 3 | Name=Share Link 4 | Comment=Share file with a link to download from Nextcloud 5 | Exec=~/bin/shareLinkCreator %F 6 | Icon=nextcloud.png 7 | Selection=S 8 | Extensions=any; 9 | -------------------------------------------------------------------------------- /shareLinkCreator.thunar_action: -------------------------------------------------------------------------------- 1 | 2 | nextcloud.png 3 | Send to Nextcloud 4 | 1413987903893246-3 5 | ~/bin/shareLinkCreator %F 6 | Upload selected files to Nextcloud 7 | * 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------