Merge ~nteodosio/thunderbird:beta into ~desktop-snappers/thunderbird/+git/snap:beta

Proposed by Nathan Teodosio
Status: Merged
Merge reported by: Sebastien Bacher
Merged at revision: bc98fc1b9834f8e8e202428beb8a253d54cbeba2
Proposed branch: ~nteodosio/thunderbird:beta
Merge into: ~desktop-snappers/thunderbird/+git/snap:beta
Diff against target: 165 lines (+130/-1)
3 files modified
patch-default-profile.py (+76/-0)
snapcraft.yaml (+9/-1)
thunderbird.launcher (+45/-0)
Reviewer Review Type Date Requested Status
Sebastien Bacher Approve
Review via email: mp+426200@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/patch-default-profile.py b/patch-default-profile.py
2new file mode 100755
3index 0000000..7516281
4--- /dev/null
5+++ b/patch-default-profile.py
6@@ -0,0 +1,76 @@
7+#!/usr/bin/python3
8+
9+import configparser
10+import os.path
11+import sys
12+
13+
14+# Mozilla products, when not packaged as a snap, use dedicated profiles per
15+# installation by default, unless instructed otherwise (legacy mode). See
16+# https://support.mozilla.org/en-US/kb/understanding-depth-profile-installation
17+# for details.
18+# We want to import existing profiles from a package of Firefox typically
19+# installed in a well-known location. The following is a list of hashes for
20+# such well-known locations, in descending order of popularity/likeliness
21+# on distributions compatible with snaps:
22+KNOWN_INSTALL_HASHES = [
23+ 'FDC34C9F024745EB', # /usr/lib/thunderbird (Debian, Ubuntu, Arch)
24+ '3DDF446CE6CB1A45', # /usr/lib64/thunderbird (Fedora)
25+ '9238613B8C3D2579', # /opt/thunderbird (Gentoo thunderbird-bin)
26+]
27+
28+
29+def _patch_imported_profiles(profiles_file):
30+ profiles = configparser.RawConfigParser()
31+ profiles.optionxform = lambda option: option
32+ profiles.read(profiles_file)
33+
34+ known_install = False
35+ for known_hash in KNOWN_INSTALL_HASHES:
36+ install_section = 'Install{}'.format(known_hash)
37+ if install_section in profiles:
38+ known_install = True
39+ break
40+ if not known_install:
41+ return
42+
43+ try:
44+ profile_path = profiles.get(install_section, 'Default')
45+ except configparser.NoOptionError:
46+ return
47+ if not profile_path:
48+ return
49+ print('Found default profile: {}'.format(profile_path))
50+
51+ for section in profiles:
52+ if section.startswith('Profile'):
53+ try:
54+ path = profiles.get(section, 'Path')
55+ except configparser.NoOptionError:
56+ continue
57+ else:
58+ if path == profile_path:
59+ # We found the section for the default profile,
60+ # explicitly mark it as such …
61+ profiles.set(section, 'Default', '1')
62+ # … and remove the default marker from any other profile
63+ # that might have had it.
64+ for other_section in profiles:
65+ if other_section.startswith('Profile') and \
66+ other_section != section:
67+ profiles.remove_option(other_section, 'Default')
68+ # Delete the Install section as it is meaningless
69+ # (and unused) in legacy mode.
70+ profiles.remove_section(install_section)
71+ # Write back the modified profiles.ini
72+ with open(profiles_file, 'w') as profiles_fd:
73+ profiles.write(profiles_fd, False)
74+ return
75+
76+
77+if __name__ == '__main__':
78+ if len(sys.argv) != 2 or not os.path.isfile(sys.argv[1]):
79+ expected_arg = '/path/to/profiles_dir/profiles.ini'
80+ print('Usage: {} {}'.format(sys.argv[0], expected_arg))
81+ sys.exit(1)
82+ _patch_imported_profiles(sys.argv[1])
83diff --git a/snapcraft.yaml b/snapcraft.yaml
84index 3dfffd3..5623fb7 100644
85--- a/snapcraft.yaml
86+++ b/snapcraft.yaml
87@@ -10,7 +10,7 @@ compression: lzo
88 apps:
89 thunderbird:
90 command-chain: [ bin/gpg-shim, bin/tmpdir ]
91- command: thunderbird-bin
92+ command: thunderbird.launcher
93 extensions: [ gnome-3-38 ]
94 environment:
95 DISABLE_WAYLAND: 1
96@@ -38,6 +38,9 @@ plugs:
97 etc-thunderbird-policies:
98 interface: system-files
99 read: [/etc/thunderbird/policies]
100+ dot-thunderbird:
101+ interface: personal-files
102+ read: [$HOME/.thunderbird]
103
104 parts:
105 thunderbird:
106@@ -96,3 +99,8 @@ parts:
107 cd "/snap/$snap/current" && find . -type f,l -exec rm -f "$SNAPCRAFT_PRIME/{}" \;
108 done
109
110+ launcher:
111+ plugin: nil
112+ override-prime: |
113+ cp "$SNAPCRAFT_PROJECT_DIR/thunderbird.launcher" "$SNAPCRAFT_PRIME/"
114+ cp "$SNAPCRAFT_PROJECT_DIR/patch-default-profile.py" "$SNAPCRAFT_PRIME/"
115diff --git a/thunderbird.launcher b/thunderbird.launcher
116new file mode 100755
117index 0000000..5782eac
118--- /dev/null
119+++ b/thunderbird.launcher
120@@ -0,0 +1,45 @@
121+#!/bin/sh
122+
123+REALHOME=$(getent passwd $(id -u) | cut -d ':' -f 6)
124+
125+# When running the snap for the first time, try and locate an existing
126+# thunderbird config in $HOME/.thunderbird and import it.
127+# This requires the personal-files plug to be connected.
128+# This is a stopgap measure until proper profile migration is implemented
129+# in thunderbird.
130+SNAPDOT="$SNAP_USER_COMMON/.thunderbird"
131+if [ ! -d "$SNAPDOT" ]; then
132+ HOMEDOT="$REALHOME/.thunderbird"
133+ if [ -r "$HOMEDOT/profiles.ini" ]; then
134+ SIZE=$(du -sb "$HOMEDOT" | cut -f 1)
135+ AVAILABLE_BLOCKS=$(stat -f -c %a "$SNAP_USER_COMMON")
136+ BLOCK_SIZE=$(stat -f -c %s "$SNAP_USER_COMMON")
137+ AVAILABLE_SIZE=$(($AVAILABLE_BLOCKS * $BLOCK_SIZE))
138+ if [ "$AVAILABLE_SIZE" -gt "$SIZE" ]; then
139+ printf '%s\n' "Importing existing thunderbird profiles from $HOMEDOT"
140+ TS1=$(date +%s.%3N)
141+ mkdir -p "$SNAPDOT"
142+ cp -R "$HOMEDOT"/* "$SNAPDOT/"
143+ # Search and replace absolute file paths in plain-text config files.
144+ find "$SNAPDOT" \( -name "pkcs11.txt" -o -name "extensions.json" \) \
145+ -exec sed -i "s#$HOMEDOT#$SNAPDOT#g" {} \;
146+ # Patch the imported profiles to set the default one for use by the snap
147+ # (legacy mode, no dedicated profiles).
148+ $SNAP/patch-default-profile.py "$SNAPDOT/profiles.ini"
149+ TS2=$(date +%s.%3N)
150+ T=$(printf '%s' "$TS1 $TS2" | awk '{printf "%.3f",$2-$1}')
151+ printf '%s\n' "Import done in $T s"
152+ else
153+ printf '%s\n' "Not importing existing firefox profiles from $HOMEDOT "
154+ "because there is not enough available space in $SNAP_USER_COMMON "
155+ "(required: $SIZE bytes / available: $AVAILABLE_SIZE bytes)"
156+ fi
157+ fi
158+fi
159+
160+# Default to XWayland until native Wayland support is properly tested
161+# (see https://bugzilla.mozilla.org/show_bug.cgi?id=1725245)
162+[ -z "$MOZ_ENABLE_WAYLAND" ] && export MOZ_ENABLE_WAYLAND=0
163+unset GDK_BACKEND
164+
165+exec "$SNAP/thunderbird-bin" "$@"

Subscribers

People subscribed via source and target branches