This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
firejail-xdg-open
67 lines (58 loc) · 1.89 KB
/
firejail-xdg-open
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
#
## HTTP(S) URL handler for Firejail
#+ custom `xdg-open` wrapper
## IMPORTANT ##############################################
#+ install this file as /usr/local/bin/xdg-open to ensure the wrapper works as expected
#########################################################
# shellcheck disable=SC2154
### vars
## source common settings
_settings_file="firejail-handler-settings-http.inc"
if [ -f "${HOME}/.config/firejail/${_settings_file}" ]; then
#+ use settings defined by user
. "${HOME}/.config/firejail/${_settings_file}"
elif [ -f "/etc/firejail/${_settings_file}" ]; then
#+ use system-wide settings
. "/etc/firejail/${_settings_file}"
else
#+ fall back to hard-coded values
_browser_bin="/usr/bin/firefox"
_debug=0
if [ "$(which xdg-user-dir)" ]; then
_drop_dir="$(xdg-user-dir DOWNLOAD)"
else
_xdg_config_home="$(env | grep -c "XDG_CONFIG_HOME")"
if [ "$_xdg_config_home" = 1 ]; then
if [ -s "${XDG_CONFIG_HOME}/user-dirs.dirs" ]; then
_drop_dir="$(grep "^XDG_DOWNLOAD_DIR=" "${XDG_CONFIG_HOME}/user-dirs.dirs" | awk '{split($0,a,"="); print a[2]}' | sed 's/"//g')"
fi
elif [ -s "${HOME}/.config/user-dirs.dirs" ]; then
_drop_dir="$(grep "^XDG_DOWNLOAD_DIR=" "${HOME}/.config/user-dirs.dirs" | awk '{split($0,a,"="); print a[2]}' | sed 's/"//g')"
else
_drop_dir="${HOME}/Downloads"
fi
fi
_drop_dir="${_drop_dir}/.firejail-dropzone"
_drop_file="${_drop_dir}/firejail.drop"
_xdg_open_wrapper_bin="/usr/local/bin/xdg-open"
fi
_selfie="$(basename "$0")"
### logic
# debug
if [ "$_debug" = 1 ]; then
echo "$@" > "${_drop_dir}/${_selfie}.log"
exit 0
fi
## triage
case "$1" in
http://*|https://*)
#+ regular HTTP(S) traffic goes to running browser
"$_browser_bin" "$1" &
;;
*)
#+ all other traffic goes to system-wide xdg-open
/usr/bin/xdg-open "$@" &
;;
esac
exit 0