Browse code

Move the session-related stuff from iceweasel-wrapper to a separate wrapper.

Xavier G authored on 26/02/2016 11:54:35
Showing 2 changed files

1 1
new file mode 100755
... ...
@@ -0,0 +1,41 @@
1
+#!/bin/bash
2
+# Copyright (c) 2016 Xavier G. <xavier.prooties@kindwolf.org>
3
+# This work is free. You can redistribute it and/or modify it under the
4
+# terms of the Do What The Fuck You Want To Public License, Version 2,
5
+# as published by Sam Hocevar. See the COPYING file for more details.
6
+
7
+# This wrapper takes care of running Firefox/Iceweasel with:
8
+#   - the adequate LOGNAME environment variable
9
+#   - the adequate -profile argument
10
+# All of this session crap is explained on 
11
+# http://superuser.com/questions/119014/how-to-remotely-open-an-url-in-firefox-in-a-specific-profile
12
+
13
+# This script is intended to be invoked with a custom name, typically via a
14
+# symlink or a hardlink named firefox-<profile>, iceweasel-<profile>,
15
+# icecat-<profile> or even KlaatuBaradaNikto-<profile> -- we are not really
16
+# picky and will simply take whatever comes after the first dot (.) or dash
17
+# (-) character.
18
+invoked_name="$(basename "${0}")"
19
+firefox_session="$(echo "${invoked_name}" | perl -nle 'print $1 if m#^(?:[^\.-]+)[\.-](.+)$#')"
20
+echo "Asked to deal with session ${firefox_session}"
21
+
22
+# Apply the "LOGNAME trick".
23
+export LOGNAME="$(whoami).${firefox_session}"
24
+
25
+# We are now ready to launch Firefox -- but wait, what should we invoke exactly?
26
+# By default, invoke "firefox":
27
+firefox_path='firefox'
28
+
29
+# Let users override this through "configuration files":
30
+generic_config_path="${HOME}/.config/fx-profile-wrapper/main.conf"
31
+[ -f "${generic_config_path}" ] && source "${generic_config_path}"
32
+specific_config_path="${HOME}/.config/fx-profile-wrapper/${invoked_name}.conf"
33
+[ -f "${specific_config_path}" ] && source "${specific_config_path}"
34
+
35
+# Let users override this again through an environment variable:
36
+[ -n "${FIREFOX_PATH}" ] && firefox_path="${FIREFOX_PATH}"
37
+
38
+# At least, launch that damn thing:
39
+"${firefox_path}" ${firefox_extra_args} -profile ~/.mozilla/firefox/*${firefox_session} "$@"
40
+# Users may also leverage firefox_extra_args to add arbitrary arguments, e.g.
41
+# --please-dont-use-100-percent-CPU.
... ...
@@ -4,16 +4,6 @@
4 4
 # terms of the Do What The Fuck You Want To Public License, Version 2,
5 5
 # as published by Sam Hocevar. See the COPYING file for more details.
6 6
 
7
-# This wrapper takes care of running iceweasel with:
8
-#   - the adequate LOGNAME environment variable
9
-#   - the adequate -profile argument
10
-# All of this session crap is explained on 
11
-# http://superuser.com/questions/119014/how-to-remotely-open-an-url-in-firefox-in-a-specific-profile
12
-invoked_name="$(basename "${0}")"
13
-firefox_session="$(echo "${invoked_name}" | perl -nle 'print $1 if m#^(?:firefox|iceweasel)[\.-](.+)$#')"
14
-echo "Asked to deal with session ${firefox_session}"
15
-export LOGNAME="$(whoami).${firefox_session}"
16
-
17 7
 function exit_with_message {
18 8
 	echo "${2}"
19 9
 	exit "${1}"
... ...
@@ -65,7 +55,8 @@ if [ -x "$(which proot)" ]; then
65 55
 		-b "${upload_dir}:${HOME}/Uploads" \
66 56
 		-b "${tmp_dir}:/tmp" \
67 57
 		-b "/dev/null:/sys" \
68
-		iceweasel -profile ~/.mozilla/firefox/*${firefox_session} "$@"
58
+		iceweasel "$@"
69 59
 else
70
-	iceweasel -profile ~/.mozilla/firefox/*${firefox_session} "$@"
60
+	echo "proot is missing; the browser will NOT be launched"
61
+	exit 127
71 62
 fi