diff options
author | Andrew Cady <d@jerkface.net> | 2020-06-19 12:16:02 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2020-06-19 12:23:24 -0400 |
commit | eb3c5e878c4a7d3439501d939c3010324d59e08c (patch) | |
tree | 4c407e17f4e63955dff0933e393d9419c8e785f3 | |
parent | 1506abc995479ad6b3ce8e0ba5201fa2639bf13c (diff) |
sideloader implementation begins
-rw-r--r-- | firefox-sideloader/functions.sh | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/firefox-sideloader/functions.sh b/firefox-sideloader/functions.sh new file mode 100644 index 0000000..7b144df --- /dev/null +++ b/firefox-sideloader/functions.sh | |||
@@ -0,0 +1,107 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | profiles_ini=~/.mozilla/firefox/profiles.ini | ||
4 | |||
5 | get_default_firefox_profile_basename() | ||
6 | { | ||
7 | < "$profiles_ini" \ | ||
8 | perl -ne 'BEGIN { $/ = "" } | ||
9 | /^Default=1$/m || next; | ||
10 | /^Path=(.+)$/m || die; | ||
11 | print "$1\n"; | ||
12 | $printed = 1; | ||
13 | last; | ||
14 | |||
15 | END { die unless $printed }' | ||
16 | } | ||
17 | |||
18 | get_default_firefox_profile_dir() | ||
19 | { | ||
20 | local prof | ||
21 | prof=$(get_default_firefox_profile_basename) || return | ||
22 | printf '%s/%s\n' "${profiles_ini%/*}" "$prof" | ||
23 | } | ||
24 | |||
25 | get_basename_from_profile_name() | ||
26 | { | ||
27 | < "$profiles_ini" \ | ||
28 | ARG="$1" \ | ||
29 | perl -ne 'BEGIN { $/ = "" } | ||
30 | /^Name=(.+)$/m || next; | ||
31 | $1 eq $ENV{ARG} || next; | ||
32 | /^Path=(.+)$/m || next; | ||
33 | print "$1"; | ||
34 | $printed = 1; | ||
35 | last; | ||
36 | |||
37 | END { die unless $printed }' | ||
38 | } | ||
39 | get_profile_dir_from_profile_name() | ||
40 | { | ||
41 | local prof | ||
42 | prof=$(get_basename_from_profile_name "$1") || return | ||
43 | printf '%s/%s\n' "${profiles_ini%/*}" "$prof" | ||
44 | } | ||
45 | |||
46 | get_profile_dir() | ||
47 | { | ||
48 | if [ "$1" ] | ||
49 | then get_profile_dir_from_profile_name "$1" | ||
50 | else get_default_firefox_profile_dir | ||
51 | fi | ||
52 | } | ||
53 | |||
54 | illustrate_leak() | ||
55 | { | ||
56 | local prof | ||
57 | which jq >/dev/null || sudo apt-get install jq | ||
58 | prof=$(get_default_firefox_profile_dir) && jq . < "$prof"/extensions.json | grep "$HOME" | ||
59 | } | ||
60 | |||
61 | copy_extensions_json() | ||
62 | { | ||
63 | local new="$1" old="$2" f='extensions.json' filter_json | ||
64 | filter_json="s/${old//\//\\/}/${new//\//\\/}/g" | ||
65 | [ -d "$old" -a -d "$new" ] || return | ||
66 | sed -e "$filter_json" > "$new"/"$f" < "$old"/"$f" | ||
67 | } | ||
68 | |||
69 | clone_profile_raw() | ||
70 | { | ||
71 | local old_profile_dir="$1" new_profile_name="$2" | ||
72 | [ -d "$old_profile_dir" ] || return | ||
73 | [ -d "$old_profile_dir"/extensions ] || return | ||
74 | |||
75 | firefox -createProfile "$new_profile_name" || return | ||
76 | new_profile_dir=$(get_profile_dir "$new_profile_name") || return | ||
77 | [ "$new_profile_dir" ] || return | ||
78 | [ "$new_profile_dir" != "$old_profile_dir" ] || return | ||
79 | |||
80 | cp -r --preserve=mode,timestamps -t "$new_profile_dir" -- "$old_profile_dir"/extensions/ || return | ||
81 | |||
82 | copy_extensions_json "$new_profile_dir" "$old_profile_dir" | ||
83 | } | ||
84 | |||
85 | clone_profile() | ||
86 | { | ||
87 | local old_profile_name="$1" old_profile_dir | ||
88 | shift | ||
89 | old_profile_dir=$(get_profile_dir "$old_profile_name") || return | ||
90 | clone_profile_raw "$old_profile_dir" "$@" | ||
91 | } | ||
92 | |||
93 | clone_default_profile() | ||
94 | { | ||
95 | new_name=$1 | ||
96 | [ "$new_name" ] || return | ||
97 | old_dir=$(get_default_firefox_profile_dir) || return | ||
98 | [ "$old_dir" ] || return | ||
99 | clone_profile_raw "$old_dir" "$new_name" | ||
100 | } | ||
101 | |||
102 | runtest() | ||
103 | { | ||
104 | . functions.sh | ||
105 | clone_default_profile "test.$(date -I)" | ||
106 | echo r=$? | ||
107 | } | ||