dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | #--------------------------------------------- |
| 3 | # xdg-icon-resource |
| 4 | # |
| 5 | # Utility script to install icons on a Linux desktop. |
| 6 | # |
| 7 | # Refer to the usage() function below for usage. |
| 8 | # |
| 9 | # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at> |
| 10 | # Copyright 2006, Jeremy White <jwhite@codeweavers.com> |
| 11 | # |
| 12 | # LICENSE: |
| 13 | # |
| 14 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 15 | # copy of this software and associated documentation files (the "Software"), |
| 16 | # to deal in the Software without restriction, including without limitation |
| 17 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 18 | # and/or sell copies of the Software, and to permit persons to whom the |
| 19 | # Software is furnished to do so, subject to the following conditions: |
| 20 | # |
| 21 | # The above copyright notice and this permission notice shall be included |
| 22 | # in all copies or substantial portions of the Software. |
| 23 | # |
| 24 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 25 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 26 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 27 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 28 | # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 29 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 30 | # OTHER DEALINGS IN THE SOFTWARE. |
| 31 | # |
| 32 | #--------------------------------------------- |
| 33 | |
| 34 | manualpage() |
| 35 | { |
| 36 | cat << _MANUALPAGE |
| 37 | Name |
| 38 | |
| 39 | xdg-icon-resource - command line tool for (un)installing icon resources |
| 40 | |
| 41 | Synopsis |
| 42 | |
| 43 | xdg-icon-resource install [--noupdate] [--novendor] [--theme theme] [--context |
| 44 | context] [--mode mode] --size size icon-file [icon-name] |
| 45 | |
| 46 | xdg-icon-resource uninstall [--noupdate] [--theme theme] [--context context] |
| 47 | [--mode mode] --size size icon-name |
| 48 | |
| 49 | xdg-icon-resource forceupdate [--theme theme] [--mode mode] |
| 50 | |
| 51 | xdg-icon-resource { --help | --manual | --version } |
| 52 | |
| 53 | Description |
| 54 | |
| 55 | The xdg-icon-resource program can be used to install icon resources into the |
| 56 | desktop icon system in order to illustrate menu entries, to depict desktop |
| 57 | icons or to graphically represent file types. |
| 58 | |
| 59 | The desktop icon system identifies icons by name. Depending on the required |
| 60 | size, the choice of icon theme and the context in which the icon is used, the |
| 61 | desktop icon system locates an appropriate icon resource to depict an icon. |
| 62 | Icon resources can be XPM files or PNG files. |
| 63 | |
| 64 | The desktop icon system works according to the XDG Icon Theme Specification at |
| 65 | http://www.freedesktop.org/Standards/icon-theme-spec |
| 66 | |
| 67 | Commands |
| 68 | |
| 69 | install |
| 70 | Installs the icon file indicated by icon-file to the desktop icon system |
| 71 | under the name icon-name. Icon names do not have an extension. If icon-name |
| 72 | is not provided the name is derived from icon-file. The icon file must have |
| 73 | .png or .xpm as extension. If a corresponding .icon file exists in the same |
| 74 | location as icon-file it will be installed as well. |
| 75 | uninstall |
| 76 | Removes the icon indicated by icon-name from the desktop icon system. Note |
| 77 | that icon names do not have an extension. |
| 78 | forceupdate |
| 79 | Force an update of the desktop icon system. This is only useful if the last |
| 80 | call to xdg-icon-resource included the --noupdate option. |
| 81 | |
| 82 | Options |
| 83 | |
| 84 | --noupdate |
| 85 | Postpone updating the desktop icon system. If multiple icons are added in |
| 86 | sequence this flag can be used to indicate that additional changes will |
| 87 | follow and that it is not necassery to update the desktop icon system right |
| 88 | away. |
| 89 | --novendor |
| 90 | |
| 91 | Normally, xdg-icon-resource checks to ensure that an icon file to be |
| 92 | installed in the apps context has a proper vendor prefix. This option can |
| 93 | be used to disable that check. |
| 94 | |
| 95 | A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated |
| 96 | with a dash ("-"). Companies and organizations are encouraged to use a word |
| 97 | or phrase, preferably the organizations name, for which they hold a |
| 98 | trademark as their vendor prefix. The purpose of the vendor prefix is to |
| 99 | prevent name conflicts. |
| 100 | |
| 101 | --theme theme |
| 102 | Installs or removes the icon file as part of theme. If no theme is |
| 103 | specified the icons will be installed as part of the default hicolor theme. |
| 104 | Applications may install icons under multiple themes but should at least |
| 105 | install icons for the default hicolor theme. |
| 106 | --context context |
| 107 | Specifies the context for the icon. Icons to be used in the application |
| 108 | menu and as desktop icon should use apps as context which is the default |
| 109 | context. Icons to be used as file icons should use mimetypes as context. |
| 110 | Other common contexts are actions, devices, emblems, filesystems and stock. |
| 111 | --size size |
| 112 | Specifies the size of the icon. All icons must be square. Common sizes for |
| 113 | icons in the apps context are: 16, 22, 32, 48, 64 and 128. Common sizes for |
| 114 | icons in the mimetypes context are: 16, 22, 32, 48, 64 and 128 |
| 115 | --mode mode |
| 116 | |
| 117 | mode can be user or system. In user mode the file is (un)installed for the |
| 118 | current user only. In system mode the file is (un)installed for all users |
| 119 | on the system. Usually only root is allowed to install in system mode. |
| 120 | |
| 121 | The default is to use system mode when called by root and to use user mode |
| 122 | when called by a non-root user. |
| 123 | |
| 124 | --help |
| 125 | Show command synopsis. |
| 126 | --manual |
| 127 | Show this manualpage. |
| 128 | --version |
| 129 | Show the xdg-utils version information. |
| 130 | |
| 131 | Environment Variables |
| 132 | |
| 133 | xdg-icon-resource honours the following environment variables: |
| 134 | |
| 135 | XDG_UTILS_DEBUG_LEVEL |
| 136 | Setting this environment variable to a non-zero numerical value makes |
| 137 | xdg-icon-resource do more verbose reporting on stderr. Setting a higher |
| 138 | value increases the verbosity. |
| 139 | XDG_UTILS_INSTALL_MODE |
| 140 | This environment variable can be used by the user or administrator to |
| 141 | override the installation mode. Valid values are user and system. |
| 142 | |
| 143 | Exit Codes |
| 144 | |
| 145 | An exit code of 0 indicates success while a non-zero exit code indicates |
| 146 | failure. The following failure codes can be returned: |
| 147 | |
| 148 | 1 |
| 149 | Error in command line syntax. |
| 150 | 2 |
| 151 | One of the files passed on the command line did not exist. |
| 152 | 3 |
| 153 | A required tool could not be found. |
| 154 | 4 |
| 155 | The action failed. |
| 156 | 5 |
| 157 | No permission to read one of the files passed on the command line. |
| 158 | |
| 159 | See Also |
| 160 | |
| 161 | xdg-desktop-icon(1), xdg-desktop-menu(1), xdg-mime(1) |
| 162 | |
| 163 | Examples |
| 164 | |
| 165 | To install an icon resource to depict a launcher for the application myfoobar, |
| 166 | the company ShinyThings Inc. can use: |
| 167 | |
| 168 | xdg-icon-resource install --size 64 shinythings-myfoobar.png |
| 169 | |
| 170 | To install an icon for a new application/x-foobar file type one can use: |
| 171 | |
| 172 | xdg-icon-resource install --context mimetypes --size 48 ./mime-foobar-48.png application-x-foobar |
| 173 | xdg-icon-resource install --context mimetypes --size 64 ./mime-foobar-64.png application-x-foobar |
| 174 | |
| 175 | This will install two icons with the name application-x-foobar but with |
| 176 | different sizes. |
| 177 | |
| 178 | _MANUALPAGE |
| 179 | } |
| 180 | |
| 181 | usage() |
| 182 | { |
| 183 | cat << _USAGE |
| 184 | xdg-icon-resource - command line tool for (un)installing icon resources |
| 185 | |
| 186 | Synopsis |
| 187 | |
| 188 | xdg-icon-resource install [--noupdate] [--novendor] [--theme theme] [--context |
| 189 | context] [--mode mode] --size size icon-file [icon-name] |
| 190 | |
| 191 | xdg-icon-resource uninstall [--noupdate] [--theme theme] [--context context] |
| 192 | [--mode mode] --size size icon-name |
| 193 | |
| 194 | xdg-icon-resource forceupdate [--theme theme] [--mode mode] |
| 195 | |
| 196 | xdg-icon-resource { --help | --manual | --version } |
| 197 | |
| 198 | _USAGE |
| 199 | } |
| 200 | |
| 201 | #@xdg-utils-common@ |
| 202 | |
| 203 | #---------------------------------------------------------------------------- |
| 204 | # Common utility functions included in all XDG wrapper scripts |
| 205 | #---------------------------------------------------------------------------- |
| 206 | |
| 207 | DEBUG() |
| 208 | { |
| 209 | [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0; |
| 210 | [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0; |
| 211 | shift |
| 212 | echo "$@" >&2 |
| 213 | } |
| 214 | |
| 215 | #------------------------------------------------------------- |
| 216 | # Exit script on successfully completing the desired operation |
| 217 | |
| 218 | exit_success() |
| 219 | { |
| 220 | if [ $# -gt 0 ]; then |
| 221 | echo "$@" |
| 222 | echo |
| 223 | fi |
| 224 | |
| 225 | exit 0 |
| 226 | } |
| 227 | |
| 228 | |
| 229 | #----------------------------------------- |
| 230 | # Exit script on malformed arguments, not enough arguments |
| 231 | # or missing required option. |
| 232 | # prints usage information |
| 233 | |
| 234 | exit_failure_syntax() |
| 235 | { |
| 236 | if [ $# -gt 0 ]; then |
| 237 | echo "xdg-icon-resource: $@" >&2 |
| 238 | echo "Try 'xdg-icon-resource --help' for more information." >&2 |
| 239 | else |
| 240 | usage |
| 241 | echo "Use 'man xdg-icon-resource' or 'xdg-icon-resource --manual' for additional info." |
| 242 | fi |
| 243 | |
| 244 | exit 1 |
| 245 | } |
| 246 | |
| 247 | #------------------------------------------------------------- |
| 248 | # Exit script on missing file specified on command line |
| 249 | |
| 250 | exit_failure_file_missing() |
| 251 | { |
| 252 | if [ $# -gt 0 ]; then |
| 253 | echo "xdg-icon-resource: $@" >&2 |
| 254 | fi |
| 255 | |
| 256 | exit 2 |
| 257 | } |
| 258 | |
| 259 | #------------------------------------------------------------- |
| 260 | # Exit script on failure to locate necessary tool applications |
| 261 | |
| 262 | exit_failure_operation_impossible() |
| 263 | { |
| 264 | if [ $# -gt 0 ]; then |
| 265 | echo "xdg-icon-resource: $@" >&2 |
| 266 | fi |
| 267 | |
| 268 | exit 3 |
| 269 | } |
| 270 | |
| 271 | #------------------------------------------------------------- |
| 272 | # Exit script on failure returned by a tool application |
| 273 | |
| 274 | exit_failure_operation_failed() |
| 275 | { |
| 276 | if [ $# -gt 0 ]; then |
| 277 | echo "xdg-icon-resource: $@" >&2 |
| 278 | fi |
| 279 | |
| 280 | exit 4 |
| 281 | } |
| 282 | |
| 283 | #------------------------------------------------------------ |
| 284 | # Exit script on insufficient permission to read a specified file |
| 285 | |
| 286 | exit_failure_file_permission_read() |
| 287 | { |
| 288 | if [ $# -gt 0 ]; then |
| 289 | echo "xdg-icon-resource: $@" >&2 |
| 290 | fi |
| 291 | |
| 292 | exit 5 |
| 293 | } |
| 294 | |
| 295 | #------------------------------------------------------------ |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 296 | # Exit script on insufficient permission to write a specified file |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 297 | |
| 298 | exit_failure_file_permission_write() |
| 299 | { |
| 300 | if [ $# -gt 0 ]; then |
| 301 | echo "xdg-icon-resource: $@" >&2 |
| 302 | fi |
| 303 | |
| 304 | exit 6 |
| 305 | } |
| 306 | |
| 307 | check_input_file() |
| 308 | { |
| 309 | if [ ! -e "$1" ]; then |
| 310 | exit_failure_file_missing "file '$1' does not exist" |
| 311 | fi |
| 312 | if [ ! -r "$1" ]; then |
| 313 | exit_failure_file_permission_read "no permission to read file '$1'" |
| 314 | fi |
| 315 | } |
| 316 | |
| 317 | check_vendor_prefix() |
| 318 | { |
| 319 | file_label="$2" |
| 320 | [ -n "$file_label" ] || file_label="filename" |
| 321 | file=`basename "$1"` |
| 322 | case "$file" in |
| 323 | [a-zA-Z]*-*) |
| 324 | return |
| 325 | ;; |
| 326 | esac |
| 327 | |
| 328 | echo "xdg-icon-resource: $file_label '$file' does not have a proper vendor prefix" >&2 |
| 329 | echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2 |
| 330 | echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2 |
| 331 | echo "Use --novendor to override or 'xdg-icon-resource --manual' for additional info." >&2 |
| 332 | exit 1 |
| 333 | } |
| 334 | |
| 335 | check_output_file() |
| 336 | { |
| 337 | # if the file exists, check if it is writeable |
| 338 | # if it does not exists, check if we are allowed to write on the directory |
| 339 | if [ -e "$1" ]; then |
| 340 | if [ ! -w "$1" ]; then |
| 341 | exit_failure_file_permission_write "no permission to write to file '$1'" |
| 342 | fi |
| 343 | else |
| 344 | DIR=`dirname "$1"` |
| 345 | if [ ! -w "$DIR" -o ! -x "$DIR" ]; then |
| 346 | exit_failure_file_permission_write "no permission to create file '$1'" |
| 347 | fi |
| 348 | fi |
| 349 | } |
| 350 | |
| 351 | #---------------------------------------- |
| 352 | # Checks for shared commands, e.g. --help |
| 353 | |
| 354 | check_common_commands() |
| 355 | { |
| 356 | while [ $# -gt 0 ] ; do |
| 357 | parm="$1" |
| 358 | shift |
| 359 | |
| 360 | case "$parm" in |
| 361 | --help) |
| 362 | usage |
| 363 | echo "Use 'man xdg-icon-resource' or 'xdg-icon-resource --manual' for additional info." |
| 364 | exit_success |
| 365 | ;; |
| 366 | |
| 367 | --manual) |
| 368 | manualpage |
| 369 | exit_success |
| 370 | ;; |
| 371 | |
| 372 | --version) |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 373 | echo "xdg-icon-resource 1.0.2" |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 374 | exit_success |
| 375 | ;; |
| 376 | esac |
| 377 | done |
| 378 | } |
| 379 | |
| 380 | check_common_commands "$@" |
| 381 | |
| 382 | [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; |
| 383 | if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then |
| 384 | # Be silent |
| 385 | xdg_redirect_output=" > /dev/null 2> /dev/null" |
| 386 | else |
| 387 | # All output to stderr |
| 388 | xdg_redirect_output=" >&2" |
| 389 | fi |
| 390 | |
| 391 | #-------------------------------------- |
| 392 | # Checks for known desktop environments |
| 393 | # set variable DE to the desktop environments name, lowercase |
| 394 | |
| 395 | detectDE() |
| 396 | { |
| 397 | if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; |
| 398 | elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 399 | elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome; |
| 400 | elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce; |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 401 | fi |
| 402 | } |
| 403 | |
| 404 | #---------------------------------------------------------------------------- |
| 405 | # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 |
| 406 | # It also always returns 1 in KDE 3.4 and earlier |
| 407 | # Simply return 0 in such case |
| 408 | |
| 409 | kfmclient_fix_exit_code() |
| 410 | { |
| 411 | version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep KDE` |
| 412 | major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'` |
| 413 | minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'` |
| 414 | release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` |
| 415 | test "$major" -gt 3 && return $1 |
| 416 | test "$minor" -gt 5 && return $1 |
| 417 | test "$release" -gt 4 && return $1 |
| 418 | return 0 |
| 419 | } |
| 420 | |
| 421 | # Set GTK_UPDATE_ICON_CACHE to gtk-update-icon-cache executable path or |
| 422 | # to "-" if not found. |
| 423 | GTK_UPDATE_ICON_CACHE= |
| 424 | find_gtk_update_icon_cache() |
| 425 | { |
| 426 | [ -n "$GTK_UPDATE_ICON_CACHE" ] && return; |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 427 | |
| 428 | GTK_UPDATE_ICON_CACHE="-" |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 429 | for x in `echo "$PATH:/opt/gnome/bin" | sed 's/:/ /g'`; do |
| 430 | DEBUG 3 "Checking $x for gtk-update-icon-cache" |
| 431 | if [ -x "$x/gtk-update-icon-cache" ] ; then |
| 432 | DEBUG 1 "Found $x/gtk-update-icon-cache" |
| 433 | GTK_UPDATE_ICON_CACHE="$x/gtk-update-icon-cache" |
| 434 | return |
| 435 | fi |
| 436 | done |
| 437 | } |
| 438 | |
| 439 | # Start GNOME legacy workaround section |
| 440 | need_dot_icon_path() |
| 441 | { |
| 442 | # GTK < 2.6 uses ~/.icons but not XDG_DATA_HOME/icons |
| 443 | # The availability of gtk-update-icon-cache is used as indication |
| 444 | # of whether the system is using GTK 2.6 or later |
| 445 | find_gtk_update_icon_cache |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 446 | [ "$GTK_UPDATE_ICON_CACHE" != "-" ] && return 1; |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | update_icon_database() |
| 451 | { |
| 452 | # Touch me, I'm dirty |
| 453 | touch "$1/.xdg-icon-resource-dummy" |
| 454 | rm -f "$1/.xdg-icon-resource-dummy" |
| 455 | |
| 456 | # Don't create a cache if there wan't one already |
| 457 | if [ -f "$1/icon-theme.cache" ] ; then |
| 458 | find_gtk_update_icon_cache |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 459 | if [ "$GTK_UPDATE_ICON_CACHE" != "-" ] ; then |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 460 | DEBUG 1 "Running $GTK_UPDATE_ICON_CACHE -f -t \"$1\"" |
| 461 | eval '$GTK_UPDATE_ICON_CACHE -f -t "$1"'$xdg_redirect_output |
| 462 | return |
| 463 | fi |
| 464 | fi |
| 465 | } |
| 466 | |
| 467 | [ x"$1" != x"" ] || exit_failure_syntax |
| 468 | |
| 469 | mode= |
| 470 | action= |
| 471 | update=yes |
| 472 | size= |
| 473 | theme=hicolor |
| 474 | context=apps |
| 475 | icon_file= |
| 476 | icon_name= |
| 477 | |
| 478 | case $1 in |
| 479 | install) |
| 480 | action=install |
| 481 | ;; |
| 482 | |
| 483 | uninstall) |
| 484 | action=uninstall |
| 485 | ;; |
| 486 | |
| 487 | forceupdate) |
| 488 | action=forceupdate |
| 489 | ;; |
| 490 | |
| 491 | *) |
| 492 | exit_failure_syntax "unknown command '$1'" |
| 493 | ;; |
| 494 | esac |
| 495 | |
| 496 | shift |
| 497 | |
| 498 | vendor=true |
| 499 | while [ $# -gt 0 ] ; do |
| 500 | parm="$1" |
| 501 | shift |
| 502 | |
| 503 | case $parm in |
| 504 | --noupdate) |
| 505 | update=no |
| 506 | ;; |
| 507 | |
| 508 | --mode) |
| 509 | if [ -z "$1" ] ; then |
| 510 | exit_failure_syntax "mode argument missing for --mode" |
| 511 | fi |
| 512 | case "$1" in |
| 513 | user) |
| 514 | mode="user" |
| 515 | ;; |
| 516 | |
| 517 | system) |
| 518 | mode="system" |
| 519 | ;; |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 520 | |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 521 | *) |
| 522 | exit_failure_syntax "unknown mode '$1'" |
| 523 | ;; |
| 524 | esac |
| 525 | shift |
| 526 | ;; |
| 527 | |
| 528 | --theme) |
| 529 | if [ -z "$1" ] ; then |
| 530 | exit_failure_syntax "theme argument missing for --theme" |
| 531 | fi |
| 532 | theme="$1" |
| 533 | shift |
| 534 | ;; |
| 535 | |
| 536 | --size) |
| 537 | if [ -z "$1" ] ; then |
| 538 | exit_failure_syntax "size argument missing for --size" |
| 539 | fi |
| 540 | if echo "$1" | grep '[^0-9]' > /dev/null 2> /dev/null; then |
| 541 | exit_failure_syntax "size argument must be numeric" |
| 542 | fi |
| 543 | size="$1" |
| 544 | shift |
| 545 | ;; |
| 546 | |
| 547 | --context) |
| 548 | if [ -z "$1" ] ; then |
| 549 | exit_failure_syntax "context argument missing for --context" |
| 550 | fi |
| 551 | context="$1" |
| 552 | shift |
| 553 | ;; |
| 554 | |
| 555 | --novendor) |
| 556 | vendor=false |
| 557 | ;; |
| 558 | |
| 559 | -*) |
| 560 | exit_failure_syntax "unexpected option '$parm'" |
| 561 | ;; |
| 562 | |
| 563 | *) |
| 564 | if [ -n "$icon_name" ] ; then |
| 565 | exit_failure_syntax "unexpected argument '$parm'" |
| 566 | elif [ -n "$icon_file" ] ; then |
| 567 | icon_name="$parm" |
| 568 | else |
| 569 | if [ "$action" = "install" ] ; then |
| 570 | check_input_file "$parm" |
| 571 | fi |
| 572 | icon_file="$parm" |
| 573 | fi |
| 574 | ;; |
| 575 | esac |
| 576 | done |
| 577 | |
| 578 | # Shouldn't happen |
| 579 | if [ -z "$action" ] ; then |
| 580 | exit_failure_syntax "command argument missing" |
| 581 | fi |
| 582 | |
| 583 | # Shouldn't happen |
| 584 | if [ -z "$context" ] ; then |
| 585 | exit_failure_syntax "context argument missing" |
| 586 | fi |
| 587 | |
| 588 | if [ -n "$XDG_UTILS_INSTALL_MODE" ] ; then |
| 589 | if [ "$XDG_UTILS_INSTALL_MODE" = "system" ] ; then |
| 590 | mode="system" |
| 591 | elif [ "$XDG_UTILS_INSTALL_MODE" = "user" ] ; then |
| 592 | mode="user" |
| 593 | fi |
| 594 | fi |
| 595 | |
| 596 | if [ -z "$mode" ] ; then |
| 597 | if [ `whoami` = "root" ] ; then |
| 598 | mode="system" |
| 599 | else |
| 600 | mode="user" |
| 601 | fi |
| 602 | fi |
| 603 | |
| 604 | xdg_dir_name="icons/$theme" |
| 605 | |
| 606 | xdg_user_dir="$XDG_DATA_HOME" |
| 607 | [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" |
| 608 | xdg_user_prefix="$xdg_user_dir/icons" |
| 609 | xdg_user_dir="$xdg_user_dir/$xdg_dir_name" |
| 610 | |
| 611 | xdg_global_dir= |
| 612 | xdg_global_prefix= |
| 613 | xdg_system_dirs="$XDG_DATA_DIRS" |
| 614 | [ -n "$xdg_system_dirs" ] || xdg_system_dirs="/usr/local/share/:/usr/share/" |
| 615 | for x in `echo "$xdg_system_dirs" | sed 's/:/ /g'`; do |
| 616 | if [ -w $x/$xdg_dir_name ] ; then |
| 617 | xdg_global_prefix="$x/icons" |
| 618 | xdg_global_dir="$x/$xdg_dir_name" |
| 619 | break |
| 620 | fi |
| 621 | done |
| 622 | [ -w $xdg_global_dir ] || xdg_global_dir= |
| 623 | |
| 624 | dot_icon_dir= |
| 625 | dot_base_dir= |
| 626 | if [ x"$mode" = x"user" ] ; then |
| 627 | xdg_base_dir="$xdg_user_dir" |
| 628 | #Gnome 2.8 supports ~/.icons but not XDG_DATA_HOME |
| 629 | if need_dot_icon_path ; then |
| 630 | dot_icon_dir="$HOME/.icons" |
| 631 | dot_base_dir="$dot_icon_dir/$theme" |
| 632 | fi |
| 633 | else |
| 634 | xdg_base_dir="$xdg_global_dir" |
| 635 | if [ -z "$xdg_base_dir" ] ; then |
| 636 | exit_failure_operation_impossible "No writable system icon directory found." |
| 637 | fi |
| 638 | fi |
| 639 | |
| 640 | if [ x"$action" = x"forceupdate" ] ; then |
| 641 | if [ -n "$icon_file" ] ; then |
| 642 | exit_failure_syntax "unexpected argument '$icon_file'" |
| 643 | fi |
| 644 | update_icon_database $xdg_base_dir |
| 645 | if [ -n "$dot_icon_dir" ] ; then |
| 646 | if [ -d "$dot_icon_dir/" -a ! -L "$dot_icon_dir" ] ; then |
| 647 | update_icon_database $dot_base_dir |
| 648 | fi |
| 649 | fi |
| 650 | exit_success |
| 651 | fi |
| 652 | |
| 653 | if [ -z "$icon_file" ] ; then |
| 654 | if [ x"$action" = x"install" ] ; then |
| 655 | exit_failure_syntax "icon-file argument missing" |
| 656 | else |
| 657 | exit_failure_syntax "icon-name argument missing" |
| 658 | fi |
| 659 | fi |
| 660 | |
| 661 | xdg_size_name= |
| 662 | extension= |
| 663 | |
| 664 | if [ -z "$size" ] ; then |
| 665 | exit_failure_syntax "the icon size must be specified with --size" |
| 666 | fi |
| 667 | xdg_size_name="${size}x${size}" |
| 668 | |
| 669 | if [ x"$action" = x"install" ] ; then |
| 670 | case $icon_file in |
| 671 | *.xpm) |
| 672 | extension="xpm" |
| 673 | ;; |
| 674 | *.png) |
| 675 | extension="png" |
| 676 | ;; |
| 677 | *) |
| 678 | exit_failure_syntax "icon file to install must be a *.png or *.xpm file" |
| 679 | ;; |
| 680 | esac |
| 681 | fi |
| 682 | |
| 683 | if [ -n "$icon_name" ] ; then |
| 684 | case $icon_name in |
| 685 | *.png) |
| 686 | exit_failure_syntax "icon name should not include an extension" |
| 687 | ;; |
| 688 | *.xpm) |
| 689 | exit_failure_syntax "icon name should not include an extension" |
| 690 | ;; |
| 691 | esac |
| 692 | fi |
| 693 | |
| 694 | # Start KDE legacy workaround section |
| 695 | need_kde_icon_path() |
| 696 | { |
| 697 | local path |
| 698 | path=`readlink -f "$1" 2> /dev/null` # Normalize path |
| 699 | DEBUG 2 "need_kde_icon_path $path" |
| 700 | if [ -z "$path" ] ; then |
| 701 | DEBUG 2 "need_kde_icon_path RETURN 1 (not needed, no xdg icon dir)" |
| 702 | return 1; # Not needed |
| 703 | fi |
| 704 | |
| 705 | # if kde-config not found... return 0 |
| 706 | kde_icon_dirs=`kde${KDE_SESSION_VERSION}-config --path icon 2> /dev/null |sed 's/:/ /g'` |
| 707 | DEBUG 3 "kde_icon_dirs: $kde_icon_dirs" |
| 708 | if [ -z "$kde_icon_dirs" ] ; then |
| 709 | DEBUG 3 "no result from kde${KDE_SESSION_VERSION}-config --path icon" |
| 710 | DEBUG 2 "need_kde_icon_path RETURN 1 (not needed, no kde icon path)" |
| 711 | return 1; # Not needed |
| 712 | fi |
| 713 | needed=0 # Needed |
| 714 | for y in $kde_icon_dirs ; do |
| 715 | x=`readlink -f "$y"` # Normalize path |
| 716 | DEBUG 3 "Normalize $y --> $x" |
| 717 | if [ -n "$x" ] ; then |
| 718 | if [ "$x" = "$path" ] ; then |
| 719 | needed=1 # Not needed |
| 720 | fi |
| 721 | if [ -w "$x" ] ; then |
| 722 | kde_global_prefix="$x" |
| 723 | # Take last writable dir |
| 724 | fi |
| 725 | fi |
| 726 | done |
| 727 | DEBUG 2 "kde_global_prefix: $kde_global_prefix" |
| 728 | [ $needed -eq "1" ] && DEBUG 2 "need_kde_icon_path RETURN $needed (not needed)" |
| 729 | [ $needed -eq "0" ] && DEBUG 2 "need_kde_icon_path RETURN $needed (needed)" |
| 730 | return $needed |
| 731 | } |
| 732 | |
| 733 | kde_dir= |
| 734 | if [ x"$mode" = x"user" ] ; then |
| 735 | xdg_dir="$xdg_base_dir/$xdg_size_name/$context" |
| 736 | #KDE 3.x doesn't support XDG_DATA_HOME for icons |
| 737 | #Check if xdg_dir prefix is listed by kde-config --path icon |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 738 | #If not, install additional symlink to kdedir |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 739 | if need_kde_icon_path "$xdg_user_prefix" ; then |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 740 | kde_user_icon_dir=`kde${KDE_SESSION_VERSION}-config --path icon | cut -d ':' -f 1` |
| 741 | kde_user_dir="$kde_user_icon_dir/$theme" |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 742 | kde_dir="$kde_user_dir/$xdg_size_name/$context" |
| 743 | fi |
| 744 | #Gnome 2.8 supports ~/.icons but not XDG_DATA_HOME |
| 745 | if [ -n "$dot_icon_dir" ] ; then |
| 746 | if [ -L "$dot_icon_dir" ] ; then |
| 747 | # Don't do anything |
| 748 | dot_icon_dir= |
| 749 | elif [ ! -d "$dot_icon_dir/" ] ; then |
| 750 | # Symlink if it doesn't exist |
| 751 | eval 'ln -s ".local/share/icons" "$dot_icon_dir"'$xdg_redirect_output |
| 752 | dot_icon_dir= |
| 753 | else |
| 754 | dot_icon_dir="$dot_icon_dir/$theme/$xdg_size_name/$context" |
| 755 | fi |
| 756 | fi |
| 757 | my_umask=077 |
| 758 | else |
| 759 | xdg_dir="$xdg_base_dir/$xdg_size_name/$context" |
| 760 | #KDE 3.x doesn't support XDG_DATA_DIRS for icons |
| 761 | #Check if xdg_dir prefix is listed by kde-config --path icon |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 762 | #If not, install additional symlink to kdedir |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 763 | if need_kde_icon_path "$xdg_global_prefix" ; then |
| 764 | kde_global_dir="$kde_global_prefix/$theme" |
| 765 | kde_dir="$kde_global_dir/$xdg_size_name/$context" |
| 766 | fi |
| 767 | my_umask=022 |
| 768 | fi |
| 769 | # End KDE legacy workaround section |
| 770 | |
| 771 | # Start GNOME legacy workaround section |
| 772 | need_gnome_mime= |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 773 | [ $context = "mimetypes" ] && need_gnome_mime=true |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 774 | # End GNOME legacy workaround section |
| 775 | |
mdm@chromium.org | ad856b9 | 2009-07-27 21:50:25 +0000 | [diff] [blame] | 776 | [ -n "$icon_name" ] || icon_name=`basename "$icon_file" | sed 's/\.[a-z][a-z][a-z]$//'` |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 777 | |
| 778 | if [ "$vendor" = "true" -a "$action" = "install" -a "$context" = "apps" ] ; then |
| 779 | check_vendor_prefix "$icon_name" "icon name" |
| 780 | fi |
| 781 | |
| 782 | icon_icon_file=`echo "$icon_file" | sed 's/\.[a-z][a-z][a-z]$/.icon/'` |
| 783 | icon_icon_name="$icon_name.icon" |
| 784 | |
| 785 | DEBUG 1 "$action icon in $xdg_dir" |
| 786 | [ $action = "install" -a -f $icon_icon_file ] && DEBUG 1 "install $icon_icon_name meta file in $xdg_dir" |
| 787 | [ -n "$kde_dir" ] && DEBUG 1 "$action symlink in $kde_dir (KDE 3.x support)" |
| 788 | [ -n "$need_gnome_mime" ] && DEBUG 1 "$action gnome-mime-$icon_name symlink (GNOME 2.x support)" |
| 789 | [ $action = "install" -a -n "$dot_icon_dir" ] && DEBUG 1 "$action ~/.icons symlink (GNOME 2.8 support)" |
| 790 | |
| 791 | case $action in |
| 792 | install) |
| 793 | save_umask=`umask` |
| 794 | umask $my_umask |
| 795 | |
| 796 | for icon_dir in $xdg_dir $dot_icon_dir; do |
| 797 | mkdir -p $icon_dir |
| 798 | eval 'cp "$icon_file" "$icon_dir/$icon_name.$extension"'$xdg_redirect_output |
| 799 | if [ -f "$icon_icon_file" ] ; then |
| 800 | eval 'cp "$icon_icon_file" "$icon_dir/$icon_icon_name"'$xdg_redirect_output |
| 801 | fi |
| 802 | if [ -n "$need_gnome_mime" ] ; then |
| 803 | eval 'ln -s "$icon_name.$extension" "$icon_dir/gnome-mime-$icon_name.$extension"'$xdg_redirect_output |
| 804 | fi |
| 805 | done |
| 806 | if [ -n "$kde_dir" ] ; then |
| 807 | mkdir -p $kde_dir |
| 808 | eval 'ln -s "$xdg_dir/$icon_name.$extension" "$kde_dir/$icon_name.$extension"'$xdg_redirect_output |
| 809 | fi |
| 810 | |
| 811 | umask $save_umask |
| 812 | ;; |
| 813 | |
| 814 | uninstall) |
| 815 | for icon_dir in $xdg_dir $dot_icon_dir; do |
| 816 | rm -f "$icon_dir/$icon_name.xpm" "$icon_dir/$icon_name.png" |
| 817 | rm -f "$icon_dir/$icon_icon_name" |
| 818 | if [ -n "$need_gnome_mime" ] ; then |
mdm@chromium.org | 56df6d3 | 2010-08-31 18:16:49 +0000 | [diff] [blame^] | 819 | rm -f "$icon_dir/gnome-mime-$icon_name.xpm" |
| 820 | rm -f "$icon_dir/gnome-mime-$icon_name.png" |
dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame] | 821 | fi |
| 822 | done |
| 823 | if [ -n "$kde_dir" ] ; then |
| 824 | rm -f "$kde_dir/$icon_name.xpm" "$kde_dir/$icon_name.png" |
| 825 | fi |
| 826 | |
| 827 | ;; |
| 828 | esac |
| 829 | |
| 830 | if [ x"$update" = x"yes" ] ; then |
| 831 | update_icon_database "$xdg_base_dir" |
| 832 | if [ -n "$dot_icon_dir" ] ; then |
| 833 | if [ -d "$dot_icon_dir/" -a ! -L "$dot_icon_dir" ] ; then |
| 834 | update_icon_database $dot_base_dir |
| 835 | fi |
| 836 | fi |
| 837 | fi |
| 838 | |
| 839 | exit_success |