@zappinginc/zm2 6.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/.claude/settings.local.json +8 -0
  2. package/.gitattributes +4 -0
  3. package/.mocharc.js +14 -0
  4. package/CHANGELOG.md +2416 -0
  5. package/CLAUDE.md +84 -0
  6. package/CONTRIBUTING.md +124 -0
  7. package/GNU-AGPL-3.0.txt +665 -0
  8. package/LICENSE +1 -0
  9. package/README.md +248 -0
  10. package/bin/zm2 +3 -0
  11. package/bin/zm2-dev +3 -0
  12. package/bin/zm2-docker +3 -0
  13. package/bin/zm2-runtime +3 -0
  14. package/bin/zm2-windows +3 -0
  15. package/bin/zm2.ps1 +3 -0
  16. package/bun.lock +421 -0
  17. package/constants.js +114 -0
  18. package/index.js +13 -0
  19. package/lib/API/Configuration.js +212 -0
  20. package/lib/API/Containerizer.js +335 -0
  21. package/lib/API/Dashboard.js +459 -0
  22. package/lib/API/Deploy.js +117 -0
  23. package/lib/API/Extra.js +775 -0
  24. package/lib/API/ExtraMgmt/Docker.js +30 -0
  25. package/lib/API/Log.js +315 -0
  26. package/lib/API/LogManagement.js +371 -0
  27. package/lib/API/Modules/LOCAL.js +122 -0
  28. package/lib/API/Modules/Modularizer.js +148 -0
  29. package/lib/API/Modules/NPM.js +445 -0
  30. package/lib/API/Modules/TAR.js +362 -0
  31. package/lib/API/Modules/flagExt.js +46 -0
  32. package/lib/API/Modules/index.js +120 -0
  33. package/lib/API/Monit.js +247 -0
  34. package/lib/API/Serve.js +343 -0
  35. package/lib/API/Startup.js +629 -0
  36. package/lib/API/UX/helpers.js +213 -0
  37. package/lib/API/UX/index.js +9 -0
  38. package/lib/API/UX/pm2-describe.js +193 -0
  39. package/lib/API/UX/pm2-ls-minimal.js +31 -0
  40. package/lib/API/UX/pm2-ls.js +483 -0
  41. package/lib/API/Version.js +382 -0
  42. package/lib/API/interpreter.json +12 -0
  43. package/lib/API/pm2-plus/PM2IO.js +372 -0
  44. package/lib/API/pm2-plus/auth-strategies/CliAuth.js +288 -0
  45. package/lib/API/pm2-plus/auth-strategies/WebAuth.js +187 -0
  46. package/lib/API/pm2-plus/helpers.js +97 -0
  47. package/lib/API/pm2-plus/link.js +126 -0
  48. package/lib/API/pm2-plus/pres/motd +16 -0
  49. package/lib/API/pm2-plus/pres/motd.update +26 -0
  50. package/lib/API/pm2-plus/pres/welcome +28 -0
  51. package/lib/API/pm2-plus/process-selector.js +52 -0
  52. package/lib/API/schema.json +379 -0
  53. package/lib/API.js +1931 -0
  54. package/lib/Client.js +776 -0
  55. package/lib/Common.js +911 -0
  56. package/lib/Configuration.js +304 -0
  57. package/lib/Daemon.js +456 -0
  58. package/lib/Event.js +37 -0
  59. package/lib/God/ActionMethods.js +909 -0
  60. package/lib/God/ClusterMode.js +97 -0
  61. package/lib/God/ForkMode.js +297 -0
  62. package/lib/God/Methods.js +265 -0
  63. package/lib/God/Reload.js +240 -0
  64. package/lib/God.js +632 -0
  65. package/lib/HttpInterface.js +76 -0
  66. package/lib/ProcessContainer.js +305 -0
  67. package/lib/ProcessContainerBun.js +360 -0
  68. package/lib/ProcessContainerFork.js +42 -0
  69. package/lib/ProcessContainerForkBun.js +33 -0
  70. package/lib/ProcessUtils.js +55 -0
  71. package/lib/TreeKill.js +118 -0
  72. package/lib/Utility.js +430 -0
  73. package/lib/VersionCheck.js +46 -0
  74. package/lib/Watcher.js +117 -0
  75. package/lib/Worker.js +169 -0
  76. package/lib/binaries/CLI.js +1041 -0
  77. package/lib/binaries/DevCLI.js +183 -0
  78. package/lib/binaries/Runtime.js +101 -0
  79. package/lib/binaries/Runtime4Docker.js +192 -0
  80. package/lib/completion.js +229 -0
  81. package/lib/completion.sh +40 -0
  82. package/lib/motd +36 -0
  83. package/lib/templates/Dockerfiles/Dockerfile-java.tpl +7 -0
  84. package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
  85. package/lib/templates/Dockerfiles/Dockerfile-ruby.tpl +7 -0
  86. package/lib/templates/ecosystem-es.tpl +24 -0
  87. package/lib/templates/ecosystem-simple-es.tpl +8 -0
  88. package/lib/templates/ecosystem-simple.tpl +6 -0
  89. package/lib/templates/ecosystem.tpl +22 -0
  90. package/lib/templates/init-scripts/launchd.tpl +35 -0
  91. package/lib/templates/init-scripts/openrc.tpl +52 -0
  92. package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
  93. package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
  94. package/lib/templates/init-scripts/rcd.tpl +44 -0
  95. package/lib/templates/init-scripts/smf.tpl +43 -0
  96. package/lib/templates/init-scripts/systemd-online.tpl +22 -0
  97. package/lib/templates/init-scripts/systemd.tpl +22 -0
  98. package/lib/templates/init-scripts/upstart.tpl +103 -0
  99. package/lib/templates/logrotate.d/pm2 +10 -0
  100. package/lib/templates/sample-apps/http-server/README.md +14 -0
  101. package/lib/templates/sample-apps/http-server/api.js +9 -0
  102. package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
  103. package/lib/templates/sample-apps/http-server/package.json +11 -0
  104. package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
  105. package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
  106. package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
  107. package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
  108. package/lib/templates/sample-apps/python-app/README.md +4 -0
  109. package/lib/templates/sample-apps/python-app/echo.py +7 -0
  110. package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
  111. package/lib/templates/sample-apps/python-app/package.json +11 -0
  112. package/lib/tools/Config.js +248 -0
  113. package/lib/tools/IsAbsolute.js +20 -0
  114. package/lib/tools/copydirSync.js +101 -0
  115. package/lib/tools/deleteFolderRecursive.js +19 -0
  116. package/lib/tools/find-package-json.js +74 -0
  117. package/lib/tools/fmt.js +72 -0
  118. package/lib/tools/isbinaryfile.js +94 -0
  119. package/lib/tools/json5.js +752 -0
  120. package/lib/tools/open.js +63 -0
  121. package/lib/tools/passwd.js +58 -0
  122. package/lib/tools/promise.min.js +1 -0
  123. package/lib/tools/sexec.js +55 -0
  124. package/lib/tools/treeify.js +113 -0
  125. package/lib/tools/which.js +120 -0
  126. package/lib/tools/xdg-open +861 -0
  127. package/package.json +219 -0
  128. package/paths.js +93 -0
  129. package/pm2 +11 -0
  130. package/preinstall.js +24 -0
  131. package/run.sh +9 -0
  132. package/types/index.d.ts +722 -0
  133. package/types/tsconfig.json +14 -0
@@ -0,0 +1,861 @@
1
+ #!/bin/sh
2
+ #---------------------------------------------
3
+ # xdg-open
4
+ #
5
+ # Utility script to open a URL in the registered default application.
6
+ #
7
+ # Refer to the usage() function below for usage.
8
+ #
9
+ # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org>
10
+ # Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
11
+ # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
12
+ # Copyright 2006, Jeremy White <jwhite@codeweavers.com>
13
+ #
14
+ # LICENSE:
15
+ #
16
+ # Permission is hereby granted, free of charge, to any person obtaining a
17
+ # copy of this software and associated documentation files (the "Software"),
18
+ # to deal in the Software without restriction, including without limitation
19
+ # the rights to use, copy, modify, merge, publish, distribute, sublicense,
20
+ # and/or sell copies of the Software, and to permit persons to whom the
21
+ # Software is furnished to do so, subject to the following conditions:
22
+ #
23
+ # The above copyright notice and this permission notice shall be included
24
+ # in all copies or substantial portions of the Software.
25
+ #
26
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29
+ # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
30
+ # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
31
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32
+ # OTHER DEALINGS IN THE SOFTWARE.
33
+ #
34
+ #---------------------------------------------
35
+
36
+ manualpage()
37
+ {
38
+ cat << _MANUALPAGE
39
+ Name
40
+
41
+ xdg-open - opens a file or URL in the user's preferred
42
+ application
43
+
44
+ Synopsis
45
+
46
+ xdg-open { file | URL }
47
+
48
+ xdg-open { --help | --manual | --version }
49
+
50
+ Description
51
+
52
+ xdg-open opens a file or URL in the user's preferred
53
+ application. If a URL is provided the URL will be opened in the
54
+ user's preferred web browser. If a file is provided the file
55
+ will be opened in the preferred application for files of that
56
+ type. xdg-open supports file, ftp, http and https URLs.
57
+
58
+ xdg-open is for use inside a desktop session only. It is not
59
+ recommended to use xdg-open as root.
60
+
61
+ Options
62
+
63
+ --help
64
+ Show command synopsis.
65
+
66
+ --manual
67
+ Show this manual page.
68
+
69
+ --version
70
+ Show the xdg-utils version information.
71
+
72
+ Exit Codes
73
+
74
+ An exit code of 0 indicates success while a non-zero exit code
75
+ indicates failure. The following failure codes can be returned:
76
+
77
+ 1
78
+ Error in command line syntax.
79
+
80
+ 2
81
+ One of the files passed on the command line did not
82
+ exist.
83
+
84
+ 3
85
+ A required tool could not be found.
86
+
87
+ 4
88
+ The action failed.
89
+
90
+ Examples
91
+
92
+ xdg-open 'http://www.freedesktop.org/'
93
+
94
+ Opens the freedesktop.org website in the user's default
95
+ browser.
96
+
97
+ xdg-open /tmp/foobar.png
98
+
99
+ Opens the PNG image file /tmp/foobar.png in the user's default
100
+ image viewing application.
101
+ _MANUALPAGE
102
+ }
103
+
104
+ usage()
105
+ {
106
+ cat << _USAGE
107
+ xdg-open - opens a file or URL in the user's preferred
108
+ application
109
+
110
+ Synopsis
111
+
112
+ xdg-open { file | URL }
113
+
114
+ xdg-open { --help | --manual | --version }
115
+
116
+ _USAGE
117
+ }
118
+
119
+ #@xdg-utils-common@
120
+
121
+ #----------------------------------------------------------------------------
122
+ # Common utility functions included in all XDG wrapper scripts
123
+ #----------------------------------------------------------------------------
124
+
125
+ DEBUG()
126
+ {
127
+ [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
128
+ [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
129
+ shift
130
+ echo "$@" >&2
131
+ }
132
+
133
+ # This handles backslashes but not quote marks.
134
+ first_word()
135
+ {
136
+ read first rest
137
+ echo "$first"
138
+ }
139
+
140
+ #-------------------------------------------------------------
141
+ # map a binary to a .desktop file
142
+ binary_to_desktop_file()
143
+ {
144
+ search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
145
+ binary="`which "$1"`"
146
+ binary="`readlink -f "$binary"`"
147
+ base="`basename "$binary"`"
148
+ IFS=:
149
+ for dir in $search; do
150
+ unset IFS
151
+ [ "$dir" ] || continue
152
+ [ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
153
+ for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
154
+ [ -r "$file" ] || continue
155
+ # Check to make sure it's worth the processing.
156
+ grep -q "^Exec.*$base" "$file" || continue
157
+ # Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
158
+ grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
159
+ command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
160
+ command="`which "$command"`"
161
+ if [ x"`readlink -f "$command"`" = x"$binary" ]; then
162
+ # Fix any double slashes that got added path composition
163
+ echo "$file" | sed -e 's,//*,/,g'
164
+ return
165
+ fi
166
+ done
167
+ done
168
+ }
169
+
170
+ #-------------------------------------------------------------
171
+ # map a .desktop file to a binary
172
+ ## FIXME: handle vendor dir case
173
+ desktop_file_to_binary()
174
+ {
175
+ search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
176
+ desktop="`basename "$1"`"
177
+ IFS=:
178
+ for dir in $search; do
179
+ unset IFS
180
+ [ "$dir" ] && [ -d "$dir/applications" ] || continue
181
+ file="$dir/applications/$desktop"
182
+ [ -r "$file" ] || continue
183
+ # Remove any arguments (%F, %f, %U, %u, etc.).
184
+ command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
185
+ command="`which "$command"`"
186
+ readlink -f "$command"
187
+ return
188
+ done
189
+ }
190
+
191
+ #-------------------------------------------------------------
192
+ # Exit script on successfully completing the desired operation
193
+
194
+ exit_success()
195
+ {
196
+ if [ $# -gt 0 ]; then
197
+ echo "$@"
198
+ echo
199
+ fi
200
+
201
+ exit 0
202
+ }
203
+
204
+
205
+ #-----------------------------------------
206
+ # Exit script on malformed arguments, not enough arguments
207
+ # or missing required option.
208
+ # prints usage information
209
+
210
+ exit_failure_syntax()
211
+ {
212
+ if [ $# -gt 0 ]; then
213
+ echo "xdg-open: $@" >&2
214
+ echo "Try 'xdg-open --help' for more information." >&2
215
+ else
216
+ usage
217
+ echo "Use 'man xdg-open' or 'xdg-open --manual' for additional info."
218
+ fi
219
+
220
+ exit 1
221
+ }
222
+
223
+ #-------------------------------------------------------------
224
+ # Exit script on missing file specified on command line
225
+
226
+ exit_failure_file_missing()
227
+ {
228
+ if [ $# -gt 0 ]; then
229
+ echo "xdg-open: $@" >&2
230
+ fi
231
+
232
+ exit 2
233
+ }
234
+
235
+ #-------------------------------------------------------------
236
+ # Exit script on failure to locate necessary tool applications
237
+
238
+ exit_failure_operation_impossible()
239
+ {
240
+ if [ $# -gt 0 ]; then
241
+ echo "xdg-open: $@" >&2
242
+ fi
243
+
244
+ exit 3
245
+ }
246
+
247
+ #-------------------------------------------------------------
248
+ # Exit script on failure returned by a tool application
249
+
250
+ exit_failure_operation_failed()
251
+ {
252
+ if [ $# -gt 0 ]; then
253
+ echo "xdg-open: $@" >&2
254
+ fi
255
+
256
+ exit 4
257
+ }
258
+
259
+ #------------------------------------------------------------
260
+ # Exit script on insufficient permission to read a specified file
261
+
262
+ exit_failure_file_permission_read()
263
+ {
264
+ if [ $# -gt 0 ]; then
265
+ echo "xdg-open: $@" >&2
266
+ fi
267
+
268
+ exit 5
269
+ }
270
+
271
+ #------------------------------------------------------------
272
+ # Exit script on insufficient permission to write a specified file
273
+
274
+ exit_failure_file_permission_write()
275
+ {
276
+ if [ $# -gt 0 ]; then
277
+ echo "xdg-open: $@" >&2
278
+ fi
279
+
280
+ exit 6
281
+ }
282
+
283
+ check_input_file()
284
+ {
285
+ if [ ! -e "$1" ]; then
286
+ exit_failure_file_missing "file '$1' does not exist"
287
+ fi
288
+ if [ ! -r "$1" ]; then
289
+ exit_failure_file_permission_read "no permission to read file '$1'"
290
+ fi
291
+ }
292
+
293
+ check_vendor_prefix()
294
+ {
295
+ file_label="$2"
296
+ [ -n "$file_label" ] || file_label="filename"
297
+ file=`basename "$1"`
298
+ case "$file" in
299
+ [[:alpha:]]*-*)
300
+ return
301
+ ;;
302
+ esac
303
+
304
+ echo "xdg-open: $file_label '$file' does not have a proper vendor prefix" >&2
305
+ echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2
306
+ echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2
307
+ echo "Use --novendor to override or 'xdg-open --manual' for additional info." >&2
308
+ exit 1
309
+ }
310
+
311
+ check_output_file()
312
+ {
313
+ # if the file exists, check if it is writeable
314
+ # if it does not exist, check if we are allowed to write on the directory
315
+ if [ -e "$1" ]; then
316
+ if [ ! -w "$1" ]; then
317
+ exit_failure_file_permission_write "no permission to write to file '$1'"
318
+ fi
319
+ else
320
+ DIR=`dirname "$1"`
321
+ if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
322
+ exit_failure_file_permission_write "no permission to create file '$1'"
323
+ fi
324
+ fi
325
+ }
326
+
327
+ #----------------------------------------
328
+ # Checks for shared commands, e.g. --help
329
+
330
+ check_common_commands()
331
+ {
332
+ while [ $# -gt 0 ] ; do
333
+ parm="$1"
334
+ shift
335
+
336
+ case "$parm" in
337
+ --help)
338
+ usage
339
+ echo "Use 'man xdg-open' or 'xdg-open --manual' for additional info."
340
+ exit_success
341
+ ;;
342
+
343
+ --manual)
344
+ manualpage
345
+ exit_success
346
+ ;;
347
+
348
+ --version)
349
+ echo "xdg-open 1.1.0 rc3"
350
+ exit_success
351
+ ;;
352
+ esac
353
+ done
354
+ }
355
+
356
+ check_common_commands "$@"
357
+
358
+ [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
359
+ if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
360
+ # Be silent
361
+ xdg_redirect_output=" > /dev/null 2> /dev/null"
362
+ else
363
+ # All output to stderr
364
+ xdg_redirect_output=" >&2"
365
+ fi
366
+
367
+ #--------------------------------------
368
+ # Checks for known desktop environments
369
+ # set variable DE to the desktop environments name, lowercase
370
+
371
+ detectDE()
372
+ {
373
+ # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
374
+ unset GREP_OPTIONS
375
+
376
+ if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
377
+ case "${XDG_CURRENT_DESKTOP}" in
378
+ ENLIGHTENMENT)
379
+ DE=enlightenment;
380
+ ;;
381
+ GNOME)
382
+ DE=gnome;
383
+ ;;
384
+ KDE)
385
+ DE=kde;
386
+ ;;
387
+ LXDE)
388
+ DE=lxde;
389
+ ;;
390
+ MATE)
391
+ DE=mate;
392
+ ;;
393
+ XFCE)
394
+ DE=xfce
395
+ ;;
396
+ esac
397
+ fi
398
+
399
+ if [ x"$DE" = x"" ]; then
400
+ # classic fallbacks
401
+ if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
402
+ elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
403
+ elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
404
+ 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;
405
+ elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
406
+ elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
407
+ elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
408
+ fi
409
+ fi
410
+
411
+ if [ x"$DE" = x"" ]; then
412
+ # fallback to checking $DESKTOP_SESSION
413
+ case "$DESKTOP_SESSION" in
414
+ gnome)
415
+ DE=gnome;
416
+ ;;
417
+ LXDE|Lubuntu)
418
+ DE=lxde;
419
+ ;;
420
+ MATE)
421
+ DE=mate;
422
+ ;;
423
+ xfce|xfce4|'Xfce Session')
424
+ DE=xfce;
425
+ ;;
426
+ esac
427
+ fi
428
+
429
+ if [ x"$DE" = x"" ]; then
430
+ # fallback to uname output for other platforms
431
+ case "$(uname 2>/dev/null)" in
432
+ Darwin)
433
+ DE=darwin;
434
+ ;;
435
+ esac
436
+ fi
437
+
438
+ if [ x"$DE" = x"gnome" ]; then
439
+ # gnome-default-applications-properties is only available in GNOME 2.x
440
+ # but not in GNOME 3.x
441
+ which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
442
+ fi
443
+ }
444
+
445
+ #----------------------------------------------------------------------------
446
+ # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4
447
+ # It also always returns 1 in KDE 3.4 and earlier
448
+ # Simply return 0 in such case
449
+
450
+ kfmclient_fix_exit_code()
451
+ {
452
+ version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
453
+ major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
454
+ minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
455
+ release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
456
+ test "$major" -gt 3 && return $1
457
+ test "$minor" -gt 5 && return $1
458
+ test "$release" -gt 4 && return $1
459
+ return 0
460
+ }
461
+
462
+ # This handles backslashes but not quote marks.
463
+ last_word()
464
+ {
465
+ read first rest
466
+ echo "$rest"
467
+ }
468
+
469
+ # Get the value of a key in a desktop file's Desktop Entry group.
470
+ # Example: Use get_key foo.desktop Exec
471
+ # to get the values of the Exec= key for the Desktop Entry group.
472
+ get_key()
473
+ {
474
+ local file="${1}"
475
+ local key="${2}"
476
+ local desktop_entry=""
477
+
478
+ IFS_="${IFS}"
479
+ IFS=""
480
+ while read line
481
+ do
482
+ case "$line" in
483
+ "[Desktop Entry]")
484
+ desktop_entry="y"
485
+ ;;
486
+ # Reset match flag for other groups
487
+ "["*)
488
+ desktop_entry=""
489
+ ;;
490
+ "${key}="*)
491
+ # Only match Desktop Entry group
492
+ if [ -n "${desktop_entry}" ]
493
+ then
494
+ echo "${line}" | cut -d= -f 2-
495
+ fi
496
+ esac
497
+ done < "${file}"
498
+ IFS="${IFS_}"
499
+ }
500
+
501
+ open_darwin()
502
+ {
503
+ open "$1"
504
+
505
+ if [ $? -eq 0 ]; then
506
+ exit_success
507
+ else
508
+ exit_failure_operation_failed
509
+ fi
510
+ }
511
+
512
+ open_kde()
513
+ {
514
+ if [ -n "${KDE_SESSION_VERSION}" ]; then
515
+ case "${KDE_SESSION_VERSION}" in
516
+ 4)
517
+ kde-open "$1"
518
+ ;;
519
+ 5)
520
+ kde-open${KDE_SESSION_VERSION} "$1"
521
+ ;;
522
+ esac
523
+ else
524
+ kfmclient exec "$1"
525
+ kfmclient_fix_exit_code $?
526
+ fi
527
+
528
+ if [ $? -eq 0 ]; then
529
+ exit_success
530
+ else
531
+ exit_failure_operation_failed
532
+ fi
533
+ }
534
+
535
+ open_gnome()
536
+ {
537
+ if gvfs-open --help 2>/dev/null 1>&2; then
538
+ gvfs-open "$1"
539
+ else
540
+ gnome-open "$1"
541
+ fi
542
+
543
+ if [ $? -eq 0 ]; then
544
+ exit_success
545
+ else
546
+ exit_failure_operation_failed
547
+ fi
548
+ }
549
+
550
+ open_mate()
551
+ {
552
+ if gvfs-open --help 2>/dev/null 1>&2; then
553
+ gvfs-open "$1"
554
+ else
555
+ mate-open "$1"
556
+ fi
557
+
558
+ if [ $? -eq 0 ]; then
559
+ exit_success
560
+ else
561
+ exit_failure_operation_failed
562
+ fi
563
+ }
564
+
565
+ open_xfce()
566
+ {
567
+ exo-open "$1"
568
+
569
+ if [ $? -eq 0 ]; then
570
+ exit_success
571
+ else
572
+ exit_failure_operation_failed
573
+ fi
574
+ }
575
+
576
+ open_enlightenment()
577
+ {
578
+ enlightenment_open "$1"
579
+
580
+ if [ $? -eq 0 ]; then
581
+ exit_success
582
+ else
583
+ exit_failure_operation_failed
584
+ fi
585
+ }
586
+
587
+ #-----------------------------------------
588
+ # Recursively search .desktop file
589
+
590
+ search_desktop_file()
591
+ {
592
+ local default="$1"
593
+ local dir="$2"
594
+ local target="$3"
595
+
596
+ local file=""
597
+ # look for both vendor-app.desktop, vendor/app.desktop
598
+ if [ -r "$dir/$default" ]; then
599
+ file="$dir/$default"
600
+ elif [ -r "$dir/`echo $default | sed -e 's|-|/|'`" ]; then
601
+ file="$dir/`echo $default | sed -e 's|-|/|'`"
602
+ fi
603
+
604
+ if [ -r "$file" ] ; then
605
+ command="$(get_key "${file}" "Exec" | first_word)"
606
+ command_exec=`which $command 2>/dev/null`
607
+ icon="$(get_key "${file}" "Icon")"
608
+ # FIXME: Actually LC_MESSAGES should be used as described in
609
+ # http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html
610
+ localised_name="$(get_key "${file}" "Name")"
611
+ set -- $(get_key "${file}" "Exec" | last_word)
612
+ # We need to replace any occurrence of "%f", "%F" and
613
+ # the like by the target file. We examine each
614
+ # argument and append the modified argument to the
615
+ # end then shift.
616
+ local args=$#
617
+ local replaced=0
618
+ while [ $args -gt 0 ]; do
619
+ case $1 in
620
+ %[c])
621
+ replaced=1
622
+ arg="${localised_name}"
623
+ shift
624
+ set -- "$@" "$arg"
625
+ ;;
626
+ %[fFuU])
627
+ replaced=1
628
+ arg="$target"
629
+ shift
630
+ set -- "$@" "$arg"
631
+ ;;
632
+ %[i])
633
+ replaced=1
634
+ shift
635
+ set -- "$@" "--icon" "$icon"
636
+ ;;
637
+ *)
638
+ arg="$1"
639
+ shift
640
+ set -- "$@" "$arg"
641
+ ;;
642
+ esac
643
+ args=$(( $args - 1 ))
644
+ done
645
+ [ $replaced -eq 1 ] || set -- "$@" "$target"
646
+ "$command_exec" "$@"
647
+
648
+ if [ $? -eq 0 ]; then
649
+ exit_success
650
+ fi
651
+ fi
652
+
653
+ for d in $dir/*/; do
654
+ [ -d "$d" ] && search_desktop_file "$default" "$d" "$target"
655
+ done
656
+ }
657
+
658
+
659
+ open_generic_xdg_mime()
660
+ {
661
+ filetype="$2"
662
+ default=`xdg-mime query default "$filetype"`
663
+ if [ -n "$default" ] ; then
664
+ xdg_user_dir="$XDG_DATA_HOME"
665
+ [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
666
+
667
+ xdg_system_dirs="$XDG_DATA_DIRS"
668
+ [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
669
+
670
+ DEBUG 3 "$xdg_user_dir:$xdg_system_dirs"
671
+ for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
672
+ search_desktop_file "$default" "$x/applications/" "$1"
673
+ done
674
+ fi
675
+ }
676
+
677
+ open_generic_xdg_file_mime()
678
+ {
679
+ filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"`
680
+ open_generic_xdg_mime "$1" "$filetype"
681
+ }
682
+
683
+ open_generic_xdg_x_scheme_handler()
684
+ {
685
+ scheme="`echo $1 | sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p'`"
686
+ if [ -n $scheme ]; then
687
+ filetype="x-scheme-handler/$scheme"
688
+ open_generic_xdg_mime "$1" "$filetype"
689
+ fi
690
+ }
691
+
692
+ open_generic()
693
+ {
694
+ # Paths or file:// URLs
695
+ if (echo "$1" | grep -q '^file://' ||
696
+ ! echo "$1" | egrep -q '^[[:alpha:]+\.\-]+:'); then
697
+
698
+ local file="$1"
699
+
700
+ # Decode URLs
701
+ if echo "$file" | grep -q '^file:///'; then
702
+ file=${file#file://}
703
+ file="$(printf "$(echo "$file" | sed -e 's@%\([a-f0-9A-F]\{2\}\)@\\x\1@g')")"
704
+ fi
705
+ file_check=${file%%#*}
706
+ file_check=${file_check%%\?*}
707
+ check_input_file "$file_check"
708
+
709
+ filetype=`xdg-mime query filetype "$file_check" | sed "s/;.*//"`
710
+ open_generic_xdg_mime "$file" "$filetype"
711
+
712
+ if which run-mailcap 2>/dev/null 1>&2; then
713
+ run-mailcap --action=view "$file"
714
+ if [ $? -eq 0 ]; then
715
+ exit_success
716
+ fi
717
+ fi
718
+
719
+ if mimeopen -v 2>/dev/null 1>&2; then
720
+ mimeopen -L -n "$file"
721
+ if [ $? -eq 0 ]; then
722
+ exit_success
723
+ fi
724
+ fi
725
+ fi
726
+
727
+ open_generic_xdg_x_scheme_handler "$1"
728
+
729
+ IFS=":"
730
+ for browser in $BROWSER; do
731
+ if [ x"$browser" != x"" ]; then
732
+
733
+ browser_with_arg=`printf "$browser" "$1" 2>/dev/null`
734
+ if [ $? -ne 0 ]; then
735
+ browser_with_arg=$browser;
736
+ fi
737
+
738
+ if [ x"$browser_with_arg" = x"$browser" ]; then
739
+ eval '$browser "$1"'$xdg_redirect_output;
740
+ else eval '$browser_with_arg'$xdg_redirect_output;
741
+ fi
742
+
743
+ if [ $? -eq 0 ]; then
744
+ exit_success;
745
+ fi
746
+ fi
747
+ done
748
+
749
+ exit_failure_operation_impossible "no method available for opening '$1'"
750
+ }
751
+
752
+ open_lxde()
753
+ {
754
+ # pcmanfm only knows how to handle file:// urls and filepaths, it seems.
755
+ if (echo "$1" | grep -q '^file://' ||
756
+ ! echo "$1" | egrep -q '^[[:alpha:]+\.\-]+:')
757
+ then
758
+ local file="$1"
759
+
760
+ # handle relative paths
761
+ if ! echo "$file" | egrep -q '^(file://)?/'; then
762
+ file="$(pwd)/$file"
763
+ fi
764
+
765
+ pcmanfm "$file"
766
+
767
+ else
768
+ open_generic "$1"
769
+ fi
770
+
771
+ if [ $? -eq 0 ]; then
772
+ exit_success
773
+ else
774
+ exit_failure_operation_failed
775
+ fi
776
+ }
777
+
778
+ [ x"$1" != x"" ] || exit_failure_syntax
779
+
780
+ url=
781
+ while [ $# -gt 0 ] ; do
782
+ parm="$1"
783
+ shift
784
+
785
+ case "$parm" in
786
+ -*)
787
+ exit_failure_syntax "unexpected option '$parm'"
788
+ ;;
789
+
790
+ *)
791
+ if [ -n "$url" ] ; then
792
+ exit_failure_syntax "unexpected argument '$parm'"
793
+ fi
794
+ url="$parm"
795
+ ;;
796
+ esac
797
+ done
798
+
799
+ if [ -z "${url}" ] ; then
800
+ exit_failure_syntax "file or URL argument missing"
801
+ fi
802
+
803
+ detectDE
804
+
805
+ if [ x"$DE" = x"" ]; then
806
+ DE=generic
807
+ fi
808
+
809
+ DEBUG 2 "Selected DE $DE"
810
+
811
+ # sanitize BROWSER (avoid caling ourselves in particular)
812
+ case "${BROWSER}" in
813
+ *:"xdg-open"|"xdg-open":*)
814
+ BROWSER=$(echo $BROWSER | sed -e 's|:xdg-open||g' -e 's|xdg-open:||g')
815
+ ;;
816
+ "xdg-open")
817
+ BROWSER=
818
+ ;;
819
+ esac
820
+
821
+ # if BROWSER variable is not set, check some well known browsers instead
822
+ if [ x"$BROWSER" = x"" ]; then
823
+ BROWSER=links2:elinks:links:lynx:w3m
824
+ if [ -n "$DISPLAY" ]; then
825
+ BROWSER=x-www-browser:firefox:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
826
+ fi
827
+ fi
828
+
829
+ case "$DE" in
830
+ kde)
831
+ open_kde "$url"
832
+ ;;
833
+
834
+ gnome*)
835
+ open_gnome "$url"
836
+ ;;
837
+
838
+ mate)
839
+ open_mate "$url"
840
+ ;;
841
+
842
+ xfce)
843
+ open_xfce "$url"
844
+ ;;
845
+
846
+ lxde)
847
+ open_lxde "$url"
848
+ ;;
849
+
850
+ enlightenment)
851
+ open_enlightenment "$url"
852
+ ;;
853
+
854
+ generic)
855
+ open_generic "$url"
856
+ ;;
857
+
858
+ *)
859
+ exit_failure_operation_impossible "no method available for opening '$url'"
860
+ ;;
861
+ esac