OLD | NEW |
(Empty) | |
| 1 #!/bin/sh |
| 2 #--------------------------------------------- |
| 3 # xdg-copy |
| 4 # |
| 5 # Utility script to copy files specified by URLs, including |
| 6 # downloading and uploading from/to remote sites. |
| 7 # |
| 8 # Refer to the usage() function below for usage. |
| 9 # |
| 10 # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> |
| 11 # Copyright 2006, Jeremy White <jwhite@codeweavers.com> |
| 12 # |
| 13 # LICENSE: |
| 14 # |
| 15 # Permission is hereby granted, free of charge, to any person obtaining a |
| 16 # copy of this software and associated documentation files (the "Software"), |
| 17 # to deal in the Software without restriction, including without limitation |
| 18 # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 19 # and/or sell copies of the Software, and to permit persons to whom the |
| 20 # Software is furnished to do so, subject to the following conditions: |
| 21 # |
| 22 # The above copyright notice and this permission notice shall be included |
| 23 # in all copies or substantial portions of the Software. |
| 24 # |
| 25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 26 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 27 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 28 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 29 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 30 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 31 # OTHER DEALINGS IN THE SOFTWARE. |
| 32 # |
| 33 #--------------------------------------------- |
| 34 |
| 35 manualpage() |
| 36 { |
| 37 cat << _MANUALPAGE |
| 38 Name |
| 39 |
| 40 xdg-copy -- command line tool for copying files between desktop URIs |
| 41 |
| 42 Synopsis |
| 43 |
| 44 xdg-copy source destination |
| 45 |
| 46 xdg-copy { --help | --manual | --version } |
| 47 |
| 48 Description |
| 49 |
| 50 xdg-copy copies source to destination and provides visual feedback to the |
| 51 user during the operation. Both source and destination can either be a |
| 52 file or URL. Supported URL types are file, ftp, http and https. Additional |
| 53 URL types may be supported depending on the desktop environment. |
| 54 |
| 55 xdg-copy is for use inside a desktop session only. It is not recommended |
| 56 to use xdg-copy as root. |
| 57 |
| 58 Options |
| 59 |
| 60 --help |
| 61 Show command synopsis. |
| 62 |
| 63 --manual |
| 64 Show this manualpage. |
| 65 |
| 66 --version |
| 67 Show the xdg-utils version information. |
| 68 |
| 69 Exit Codes |
| 70 |
| 71 An exit code of 0 indicates success while a non-zero exit code indicates |
| 72 failure. The following failure codes can be returned: |
| 73 |
| 74 1 |
| 75 Error in command line syntax. |
| 76 |
| 77 2 |
| 78 One of the files passed on the command line did not exist. |
| 79 |
| 80 3 |
| 81 A required tool could not be found. |
| 82 |
| 83 4 |
| 84 The action failed. |
| 85 |
| 86 Examples |
| 87 |
| 88 xdg-copy "http://portland.freedesktop.org/png/freedesktop-logo.png" . |
| 89 |
| 90 xdg-copy "/tmp/foobar.png" "/home/user/foobar-copy.png" |
| 91 _MANUALPAGE |
| 92 } |
| 93 |
| 94 usage() |
| 95 { |
| 96 cat << _USAGE |
| 97 xdg-copy -- command line tool for copying files between desktop URIs |
| 98 |
| 99 Synopsis |
| 100 |
| 101 xdg-copy source destination |
| 102 |
| 103 xdg-copy { --help | --manual | --version } |
| 104 |
| 105 _USAGE |
| 106 } |
| 107 |
| 108 #@xdg-utils-common@ |
| 109 |
| 110 #---------------------------------------------------------------------------- |
| 111 # Common utility functions included in all XDG wrapper scripts |
| 112 #---------------------------------------------------------------------------- |
| 113 |
| 114 #------------------------------------------------------------- |
| 115 # Exit script on successfully completing the desired operation |
| 116 |
| 117 exit_success() |
| 118 { |
| 119 if [ $# -gt 0 ]; then |
| 120 echo "$@" |
| 121 echo |
| 122 fi |
| 123 |
| 124 exit 0 |
| 125 } |
| 126 |
| 127 |
| 128 #----------------------------------------- |
| 129 # Exit script on malformed arguments, not enough arguments |
| 130 # or missing required option. |
| 131 # prints usage information |
| 132 |
| 133 exit_failure_syntax() |
| 134 { |
| 135 if [ $# -gt 0 ]; then |
| 136 echo "xdg-copy: $@" >&2 |
| 137 echo "Try 'xdg-copy --help' for more information." >&2 |
| 138 else |
| 139 usage |
| 140 echo "Use 'man xdg-copy' or 'xdg-copy --manual' for additional info." |
| 141 fi |
| 142 |
| 143 exit 1 |
| 144 } |
| 145 |
| 146 #------------------------------------------------------------- |
| 147 # Exit script on missing file specified on command line |
| 148 |
| 149 exit_failure_file_missing() |
| 150 { |
| 151 if [ $# -gt 0 ]; then |
| 152 echo "xdg-copy: $@" >&2 |
| 153 fi |
| 154 |
| 155 exit 2 |
| 156 } |
| 157 |
| 158 #------------------------------------------------------------- |
| 159 # Exit script on failure to locate necessary tool applications |
| 160 |
| 161 exit_failure_operation_impossible() |
| 162 { |
| 163 if [ $# -gt 0 ]; then |
| 164 echo "xdg-copy: $@" >&2 |
| 165 fi |
| 166 |
| 167 exit 3 |
| 168 } |
| 169 |
| 170 #------------------------------------------------------------- |
| 171 # Exit script on failure returned by a tool application |
| 172 |
| 173 exit_failure_operation_failed() |
| 174 { |
| 175 if [ $# -gt 0 ]; then |
| 176 echo "xdg-copy: $@" >&2 |
| 177 fi |
| 178 |
| 179 exit 4 |
| 180 } |
| 181 |
| 182 |
| 183 #---------------------------------------- |
| 184 # Checks for shared commands, e.g. --help |
| 185 |
| 186 check_common_commands() |
| 187 { |
| 188 while [ $# -gt 0 ] ; do |
| 189 parm=$1 |
| 190 shift |
| 191 |
| 192 case $parm in |
| 193 --help) |
| 194 usage |
| 195 echo "Use 'man xdg-copy' or 'xdg-copy --manual' for additional info.
" |
| 196 exit_success |
| 197 ;; |
| 198 |
| 199 --manual) |
| 200 manualpage |
| 201 exit_success |
| 202 ;; |
| 203 |
| 204 --version) |
| 205 echo "xdg-copy 1.0beta1" |
| 206 exit_success |
| 207 ;; |
| 208 esac |
| 209 done |
| 210 } |
| 211 |
| 212 check_common_commands "$@" |
| 213 |
| 214 #-------------------------------------- |
| 215 # Checks for known desktop environments |
| 216 # set variable DE to the desktop environments name, lowercase |
| 217 |
| 218 detectDE() |
| 219 { |
| 220 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; |
| 221 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; |
| 222 elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then
DE=xfce; |
| 223 fi |
| 224 } |
| 225 |
| 226 #---------------------------------------------------------------------------- |
| 227 |
| 228 |
| 229 |
| 230 copy_kde() |
| 231 { |
| 232 kfmclient copy "$1" "$2" |
| 233 |
| 234 if [ $? -eq 0 ]; then |
| 235 exit_success |
| 236 else |
| 237 exit_failure_operation_failed |
| 238 fi |
| 239 } |
| 240 |
| 241 copy_gnome() |
| 242 { |
| 243 gnomevfs-copy "$1" "$2" |
| 244 |
| 245 if [ $? -eq 0 ]; then |
| 246 exit_success |
| 247 else |
| 248 exit_failure_operation_failed |
| 249 fi |
| 250 } |
| 251 |
| 252 [ x"$1" != x"" ] || exit_failure_syntax |
| 253 |
| 254 source= |
| 255 dest= |
| 256 while [ $# -gt 0 ] ; do |
| 257 parm=$1 |
| 258 shift |
| 259 |
| 260 case $parm in |
| 261 -*) |
| 262 exit_failure_syntax "unexpected option '$parm'" |
| 263 ;; |
| 264 |
| 265 *) |
| 266 if [ -n "$dest" ] ; then |
| 267 exit_failure_syntax "unexpected argument '$parm'" |
| 268 fi |
| 269 if [ -n "$source" ] ; then |
| 270 dest=$parm |
| 271 else |
| 272 source=$parm |
| 273 fi |
| 274 ;; |
| 275 esac |
| 276 done |
| 277 |
| 278 if [ -z "${source}" ] ; then |
| 279 exit_failure_syntax "source argument missing" |
| 280 fi |
| 281 if [ -z "${dest}" ] ; then |
| 282 exit_failure_syntax "destination argument missing" |
| 283 fi |
| 284 |
| 285 detectDE |
| 286 |
| 287 case "$DE" in |
| 288 kde) |
| 289 copy_kde "$source" "$dest" |
| 290 ;; |
| 291 |
| 292 gnome) |
| 293 copy_gnome "$source" "$dest" |
| 294 ;; |
| 295 |
| 296 *) |
| 297 exit_failure_operation_impossible "no method available for copying '$source'
to '$dest'" |
| 298 ;; |
| 299 esac |
OLD | NEW |