Browse code

Add our first "prootie": iceweasel-wrapper.

iceweasel-wrapper is a quick and dirty wrapper around firefox/iceweasel. It was
initially meant as a convenience to deal with multiple Firefox sessions but
recently acquired a "launch with proot" feature.

Xavier G authored on 25/02/2016 23:32:02
Showing 2 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,14 @@
1
+            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+                    Version 2, December 2004
3
+
4
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
9
+
10
+            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
+
13
+  0. You just DO WHAT THE FUCK YOU WANT TO.
14
+
0 15
new file mode 100755
... ...
@@ -0,0 +1,71 @@
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 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
+function exit_with_message {
18
+	echo "${2}"
19
+	exit "${1}"
20
+}
21
+
22
+function mk_dir {
23
+	local path="${1}"
24
+	local mode="${2}"
25
+
26
+	mkdir -p "${path}" || \
27
+		exit_with_message 126 \
28
+			"Unable to create the following directory, aborting: ${path}"
29
+
30
+	chmod "${mode}" "${path}" || \
31
+		exit_with_message 125 \
32
+			"Unable to chmod the following directory, aborting: ${path}"
33
+}
34
+
35
+if [ -x "$(which proot)" ]; then
36
+	echo "proot is present and will be used to mask some directories"
37
+
38
+	# Directory to replace $HOME
39
+	home_dir="/run/user/$(id -u)/home.$$"
40
+	# Directory to replace /tmp
41
+	tmp_dir="/run/user/$(id -u)/tmp.$$"
42
+	# Directory for uploads
43
+	upload_dir="${HOME}/Uploads/${firefox_session}"
44
+	# Directory for downloads
45
+	download_dir="${HOME}/Downloads/${firefox_session}"
46
+
47
+	for directory in {home,tmp,{up,down}load}_dir; do
48
+		mk_dir "${!directory}" 0700
49
+	done
50
+
51
+	# Leverage proot to make iceweasel believe that:
52
+	#   - the home directory is almost empty
53
+	#   - its configuration directory is still there
54
+	#   - its cache directory is still there
55
+	#   - its download directory is still there (one per session)
56
+	#     (at least the one for English speakers)
57
+	#   - a ~/Uploads directory is present (one per session)
58
+	#   - /tmp is empty
59
+	#     (as in: do not even try to mess with the Unix sockets to ssh-agent)
60
+	proot \
61
+		-b "${home_dir}:${HOME}" \
62
+		-b "${HOME}/.mozilla/firefox:${HOME}/.mozilla/firefox" \
63
+		-b "${HOME}/.cache/mozilla/firefox:${HOME}/.cache/mozilla/firefox" \
64
+		-b "${download_dir}:${HOME}/Downloads" \
65
+		-b "${upload_dir}:${HOME}/Uploads" \
66
+		-b "${tmp_dir}:/tmp" \
67
+		-b "/dev/null:/sys" \
68
+		iceweasel -profile ~/.mozilla/firefox/*${firefox_session} "$@"
69
+else
70
+	iceweasel -profile ~/.mozilla/firefox/*${firefox_session} "$@"
71
+fi