mirror of
https://github.com/fscotto/infra.git
synced 2026-11-26 21:59:50 +00:00
Preserve Thunderbird profiles and add OpenCode Mobile support
This commit is contained in:
@@ -117,7 +117,7 @@ Ansible-driven personal infrastructure repo for Fedora and Void desktops, Fedora
|
||||
- `dotfiles/desktop/.config/niri/config.kdl` and `session-env` deployed via `desktop_niri_dotfiles` (Niri / Wayland)
|
||||
- Void Niri lives in `profile_desktop_niri`, gated on `'niri' in desktop_sessions_enabled`; it installs the `emptty` `niri.desktop` session, the `/usr/local/bin/start-niri` launcher, and the xdg-desktop-portal config, mirroring `profile_desktop_sway`.
|
||||
- Fedora GNOME (`desktop_gnome`) assumes GNOME comes from the Fedora Workstation base install; Ansible deploys shared desktop dotfiles and git/GPG config for `ikaros` and `nymph`, not GNOME settings.
|
||||
- `profile_desktop_gnome` also seeds a Thunderbird profile for `ikaros` and `nymph` with the iCloud IMAP/SMTP account, one CalDAV calendar and one CardDAV address book. Account defaults are rendered into a managed `user.js` because Thunderbird rewrites `prefs.js`; `profiles.ini` is only seeded when absent. The address comes from `vault_icloud_email` and the app-specific password is never stored.
|
||||
- `profile_desktop_gnome` first discovers configured Thunderbird accounts in both `~/.thunderbird` and `~/.config/thunderbird` and selects an existing profile without changing its account settings. Only if no account exists does it seed a new iCloud IMAP/SMTP profile with CalDAV and CardDAV through a non-overwriting `user.js`. Registry changes preserve other profiles and create backups; Thunderbird must be closed. The bootstrap address comes from `vault_icloud_email` and the app-specific password is never stored by Ansible.
|
||||
- Do not switch or restart the display manager during a playbook run from an active graphical session.
|
||||
- `nymph` is the Fedora/GNOME laptop target; keep GNOME settings unmanaged for now and add host-specific tuning only after real use.
|
||||
|
||||
|
||||
23
README.md
23
README.md
@@ -596,6 +596,13 @@ instructions, credentials, and user data. Installation and removal are mutually
|
||||
exclusive per agent: the playbook fails before making changes when both flags are
|
||||
true for the same agent. Servers set `ai_agents: {}` and therefore manage none.
|
||||
|
||||
OpenCode Mobile (`opencode-mobile`) is installed globally through the same npm
|
||||
lifecycle on Fedora, Void desktops, and WSL. Its plugin declaration and `/mobile`
|
||||
command are deployed with the OpenCode dotfiles, so its `deploy_enabled` stays
|
||||
false. The playbook does not run the interactive installer, configure tunnel
|
||||
providers, or register phone push tokens. Pairing and connectivity remain manual;
|
||||
see the [upstream instructions](https://github.com/doza62/opencode-mobile#readme).
|
||||
|
||||
Run a focused dry run with:
|
||||
|
||||
```bash
|
||||
@@ -646,10 +653,18 @@ iCloud account is already declared: IMAP `imap.mail.me.com:993` over SSL/TLS, SM
|
||||
`smtp.mail.me.com:587` over STARTTLS, the identity and folder mapping, one CalDAV
|
||||
calendar (`caldav.icloud.com`) and one CardDAV address book (`contacts.icloud.com`).
|
||||
|
||||
The account defaults live in a managed `user.js`, not in `prefs.js`: Thunderbird
|
||||
rewrites `prefs.js` on exit, while `user.js` is re-applied at every start.
|
||||
`profiles.ini` is only seeded when absent, so a profile list Thunderbird already
|
||||
owns is never replaced.
|
||||
Before provisioning, the role checks both `~/.thunderbird` and
|
||||
`~/.config/thunderbird`, including registered absolute profile paths. If a profile
|
||||
already has a configured mail account, it selects that profile without modifying
|
||||
its account preferences, passwords, calendars or address books. Registered default
|
||||
profiles take priority over other discovered profiles. The active registry keeps
|
||||
its other profiles and is backed up before changes, including installation defaults.
|
||||
|
||||
Only when no configured account exists does the role create the iCloud profile
|
||||
and seed `user.js` without overwriting an existing file. Thunderbird must be closed
|
||||
before applying this tag; the playbook never stops it automatically. No profile or
|
||||
mail data is deleted or copied. A fresh installation uses `~/.config/thunderbird`;
|
||||
an existing legacy `~/.thunderbird` directory is retained.
|
||||
|
||||
The address comes from `vault_icloud_email` and the display name from
|
||||
`vault_personal_full_name`. The password is deliberately not stored: iCloud mail
|
||||
|
||||
@@ -108,6 +108,11 @@ ai_agents:
|
||||
install_enabled: true
|
||||
deploy_enabled: true
|
||||
uninstall_enabled: false
|
||||
opencode_mobile:
|
||||
npm_package: opencode-mobile
|
||||
install_enabled: true
|
||||
deploy_enabled: false
|
||||
uninstall_enabled: false
|
||||
claude_code:
|
||||
npm_package: "@anthropic-ai/claude-code"
|
||||
install_enabled: "{{ claude_code_install_enabled }}"
|
||||
|
||||
@@ -103,8 +103,8 @@ desktop_gnome_dotfiles:
|
||||
mode: "0644"
|
||||
|
||||
# Thunderbird is provisioned from a seeded profile plus a managed user.js:
|
||||
# Thunderbird rewrites prefs.js on exit, so the declared account, calendar and
|
||||
# address book defaults are re-applied at every start from user.js instead.
|
||||
# Existing Thunderbird accounts are reused without changing their preferences.
|
||||
# Only a new profile receives account, calendar and address book defaults in user.js.
|
||||
# The address comes from Vault; the app-specific password is never stored here
|
||||
# and is requested by Thunderbird on first use.
|
||||
thunderbird_icloud_enabled: true
|
||||
|
||||
144
ansible/roles/profile_desktop_gnome/files/thunderbird_profile.py
Normal file
144
ansible/roles/profile_desktop_gnome/files/thunderbird_profile.py
Normal file
@@ -0,0 +1,144 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only discovery and registry plan; never read stored login credentials."""
|
||||
|
||||
import configparser
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def read_ini(path):
|
||||
result = configparser.RawConfigParser()
|
||||
result.optionxform = str
|
||||
if path.exists():
|
||||
with path.open() as source:
|
||||
result.read_file(source)
|
||||
return result
|
||||
|
||||
|
||||
def preferences(path):
|
||||
if not path.exists():
|
||||
return {}
|
||||
result = {}
|
||||
for key, value in re.findall(
|
||||
r'^\s*user_pref\("([^"\n]+)",\s*(.*?)\);',
|
||||
path.read_text(), re.MULTILINE,
|
||||
):
|
||||
try:
|
||||
result[key] = json.loads(value)
|
||||
except ValueError:
|
||||
continue
|
||||
return result
|
||||
|
||||
|
||||
def has_account(path):
|
||||
# user.js alone is only a bootstrap, not an account used by Thunderbird.
|
||||
prefs = preferences(path / 'prefs.js')
|
||||
for account in str(prefs.get('mail.accountmanager.accounts', '')).split(','):
|
||||
server = prefs.get('mail.account.' + account.strip() + '.server')
|
||||
prefix = 'mail.server.' + str(server) + '.'
|
||||
if (prefs.get(prefix + 'type') in ('imap', 'pop3', 'nntp')
|
||||
and prefs.get(prefix + 'hostname')):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def profile_path(root, registry, section):
|
||||
value = registry.get(section, 'Path')
|
||||
return (root / value if registry.get(section, 'IsRelative', fallback='1') == '1'
|
||||
else Path(value)).resolve()
|
||||
|
||||
|
||||
def render(registry):
|
||||
output = io.StringIO()
|
||||
registry.write(output, space_around_delimiters=False)
|
||||
return output.getvalue()
|
||||
|
||||
|
||||
def plan(home, profile_dir, profile_name):
|
||||
home = Path(home)
|
||||
# A legacy directory takes precedence over the XDG registry on this build.
|
||||
roots = [home / '.thunderbird', home / '.config/thunderbird']
|
||||
root = next((p for p in roots if p.exists()), roots[1])
|
||||
registries = {p: read_ini(p / 'profiles.ini') for p in roots}
|
||||
candidates = []
|
||||
install_ids = set()
|
||||
for base, registry in registries.items():
|
||||
installs = read_ini(base / 'installs.ini')
|
||||
defaults = {registry.get(s, 'Default', fallback='')
|
||||
for s in registry.sections() if s.startswith('Install')}
|
||||
defaults.update(installs.get(s, 'Default', fallback='')
|
||||
for s in installs.sections())
|
||||
for section in registry.sections():
|
||||
if not re.fullmatch(r'Profile\d+', section):
|
||||
continue
|
||||
path = profile_path(base, registry, section)
|
||||
if has_account(path):
|
||||
candidates.append((registry.get(section, 'Path') not in defaults,
|
||||
base != root, str(path), path))
|
||||
# Reuse installation associations, including those in the other root.
|
||||
install_ids.update(s[7:] for s in registry.sections() if s.startswith('Install'))
|
||||
install_ids.update(installs.sections())
|
||||
# Also find unregistered profiles, without following arbitrary subtrees.
|
||||
if base.exists():
|
||||
for child in sorted(base.iterdir()):
|
||||
if child.is_dir() and has_account(child):
|
||||
candidates.append((True, base != root, str(child.resolve()), child.resolve()))
|
||||
existing = bool(candidates)
|
||||
selected = min(candidates)[3] if existing else root / profile_dir
|
||||
if not existing:
|
||||
number = 0
|
||||
while selected.exists():
|
||||
bootstrap = selected / 'user.js'
|
||||
if (not (selected / 'prefs.js').exists() and bootstrap.exists()
|
||||
and bootstrap.read_text().startswith('// Managed by Ansible from profile_desktop_gnome')):
|
||||
break
|
||||
number += 1
|
||||
selected = root / (profile_dir + '-' + str(number))
|
||||
registry = registries[root]
|
||||
section = next((s for s in registry.sections()
|
||||
if re.fullmatch(r'Profile\d+', s)
|
||||
and profile_path(root, registry, s) == selected), None)
|
||||
if section is None:
|
||||
number = 0
|
||||
while registry.has_section('Profile' + str(number)):
|
||||
number += 1
|
||||
section = 'Profile' + str(number)
|
||||
registry.add_section(section)
|
||||
registry.set(section, 'Name', profile_name if not existing else selected.name)
|
||||
registry.set(section, 'IsRelative', '0')
|
||||
registry.set(section, 'Path', str(selected))
|
||||
for other in registry.sections():
|
||||
if re.fullmatch(r'Profile\d+', other):
|
||||
registry.remove_option(other, 'Default')
|
||||
registry.set(section, 'Default', '1')
|
||||
if not registry.has_section('General'):
|
||||
registry.add_section('General')
|
||||
registry.set('General', 'StartWithLastProfile', '1')
|
||||
registry.set('General', 'Version', '2')
|
||||
value = registry.get(section, 'Path')
|
||||
installs = read_ini(root / 'installs.ini')
|
||||
for install in sorted(install_ids):
|
||||
# Do not redirect a separate installation with another configured account.
|
||||
defaults = []
|
||||
for base, source in registries.items():
|
||||
default = source.get('Install' + install, 'Default', fallback='')
|
||||
if not default:
|
||||
default = read_ini(base / 'installs.ini').get(install, 'Default', fallback='')
|
||||
if default:
|
||||
defaults.append((base / default).resolve())
|
||||
if any(p != selected and has_account(p) for p in defaults):
|
||||
continue
|
||||
for target, name in ((registry, 'Install' + install), (installs, install)):
|
||||
if not target.has_section(name):
|
||||
target.add_section(name)
|
||||
target.set(name, 'Default', value)
|
||||
target.set(name, 'Locked', '1')
|
||||
return dict(root=str(root), profile=str(selected), existing_account=existing,
|
||||
profiles_ini=render(registry), installs_ini=render(installs))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(json.dumps(plan(*sys.argv[1:])))
|
||||
@@ -1,52 +1,126 @@
|
||||
---
|
||||
- name: Require the iCloud address for the managed Thunderbird profile
|
||||
- name: Inspect existing Thunderbird profiles without changing them
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- "{{ ansible_facts.python.executable }}"
|
||||
- -c
|
||||
- "{{ lookup('ansible.builtin.file', role_path + '/files/thunderbird_profile.py') }}"
|
||||
- "{{ user_home }}"
|
||||
- "{{ thunderbird_profile_dir }}"
|
||||
- "{{ thunderbird_profile_name }}"
|
||||
become: true
|
||||
become_user: "{{ username }}"
|
||||
register: thunderbird_profile_probe
|
||||
changed_when: false
|
||||
check_mode: false
|
||||
|
||||
- name: Select an existing account or plan an iCloud bootstrap
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.set_fact:
|
||||
thunderbird_selected: "{{ thunderbird_profile_probe.stdout | from_json }}"
|
||||
|
||||
- name: Require the iCloud address only when no configured account exists
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- vault_icloud_email is defined
|
||||
- vault_icloud_email | length > 0
|
||||
- vault_icloud_email != 'REPLACE_ME'
|
||||
- vault_icloud_email is match('^[^@\s]+@[^@\s]+$')
|
||||
- vault_icloud_email is match('^[^@\\s]+@[^@\\s]+$')
|
||||
fail_msg: >-
|
||||
vault_icloud_email must hold the iCloud mail address before the
|
||||
vault_icloud_email must hold the iCloud mail address before a new
|
||||
Thunderbird profile can be provisioned.
|
||||
quiet: true
|
||||
when: not thunderbird_selected.existing_account
|
||||
|
||||
- name: Create the Thunderbird configuration directory
|
||||
- name: Check whether Thunderbird is running
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.command:
|
||||
argv: [pgrep, -u, "{{ username }}", -x, thunderbird]
|
||||
register: thunderbird_running
|
||||
changed_when: false
|
||||
failed_when: thunderbird_running.rc not in [0, 1]
|
||||
check_mode: false
|
||||
|
||||
- name: Require Thunderbird to be closed before selecting its profile
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.assert:
|
||||
that: thunderbird_running.rc == 1
|
||||
fail_msg: Close Thunderbird before running the thunderbird tag; it is never stopped automatically.
|
||||
|
||||
- name: Create the selected Thunderbird registry directory
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.file:
|
||||
path: "{{ user_home }}/.thunderbird"
|
||||
path: "{{ thunderbird_selected.root }}"
|
||||
state: directory
|
||||
owner: "{{ username }}"
|
||||
group: "{{ user_group }}"
|
||||
mode: "0700"
|
||||
|
||||
- name: Create the managed Thunderbird profile directory
|
||||
- name: Create a new profile only when no configured account exists
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.file:
|
||||
path: "{{ user_home }}/.thunderbird/{{ thunderbird_profile_dir }}"
|
||||
path: "{{ thunderbird_selected.profile }}"
|
||||
state: directory
|
||||
owner: "{{ username }}"
|
||||
group: "{{ user_group }}"
|
||||
mode: "0700"
|
||||
when: not thunderbird_selected.existing_account
|
||||
|
||||
- name: Seed the Thunderbird profile registry when absent
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.template:
|
||||
src: thunderbird/profiles.ini.j2
|
||||
dest: "{{ user_home }}/.thunderbird/profiles.ini"
|
||||
owner: "{{ username }}"
|
||||
group: "{{ user_group }}"
|
||||
mode: "0600"
|
||||
# Never rewrite a profile list Thunderbird has already taken over.
|
||||
force: false
|
||||
|
||||
- name: Render the managed Thunderbird account defaults
|
||||
- name: Seed iCloud defaults only in a profile without a configured account
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.template:
|
||||
src: thunderbird/user.js.j2
|
||||
dest: "{{ user_home }}/.thunderbird/{{ thunderbird_profile_dir }}/user.js"
|
||||
dest: "{{ thunderbird_selected.profile }}/user.js"
|
||||
owner: "{{ username }}"
|
||||
group: "{{ user_group }}"
|
||||
mode: "0600"
|
||||
force: false
|
||||
no_log: true
|
||||
when: not thunderbird_selected.existing_account
|
||||
|
||||
- name: Discover the Thunderbird installation directory for first-start profile adoption
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.stat:
|
||||
path: "{{ item }}/application.ini"
|
||||
loop: [/usr/lib64/thunderbird, /usr/lib/thunderbird]
|
||||
register: thunderbird_installation
|
||||
when: not thunderbird_selected.existing_account
|
||||
|
||||
- name: Seed compatibility information so Thunderbird adopts the new default profile
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
[Compatibility]
|
||||
LastPlatformDir={{ item.item }}
|
||||
LastAppDir={{ item.item }}
|
||||
dest: "{{ thunderbird_selected.profile }}/compatibility.ini"
|
||||
owner: "{{ username }}"
|
||||
group: "{{ user_group }}"
|
||||
mode: "0600"
|
||||
force: false
|
||||
loop: "{{ thunderbird_installation.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item }}"
|
||||
when:
|
||||
- not thunderbird_selected.existing_account
|
||||
- item.stat.exists | default(false)
|
||||
|
||||
- name: Select the profile while preserving other registered profiles
|
||||
tags: [thunderbird]
|
||||
ansible.builtin.copy:
|
||||
content: "{{ item.content }}"
|
||||
dest: "{{ thunderbird_selected.root }}/{{ item.name }}"
|
||||
owner: "{{ username }}"
|
||||
group: "{{ user_group }}"
|
||||
mode: "0600"
|
||||
backup: true
|
||||
loop:
|
||||
- name: profiles.ini
|
||||
content: "{{ thunderbird_selected.profiles_ini }}"
|
||||
- name: installs.ini
|
||||
content: "{{ thunderbird_selected.installs_ini }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
when: item.content | length > 0
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
[Profile0]
|
||||
Name={{ thunderbird_profile_name }}
|
||||
IsRelative=1
|
||||
Path={{ thunderbird_profile_dir }}
|
||||
Default=1
|
||||
|
||||
[General]
|
||||
StartWithLastProfile=1
|
||||
Version=2
|
||||
@@ -1,6 +1,7 @@
|
||||
// Managed by Ansible from profile_desktop_gnome (tag: thunderbird).
|
||||
// Thunderbird rewrites prefs.js on exit, so the declared defaults live here
|
||||
// and are re-applied at every start. Do not edit this file by hand.
|
||||
// and are re-applied at every start. Seeded only when no account exists;
|
||||
// Ansible does not overwrite this file or configure an existing account.
|
||||
//
|
||||
// The account password is intentionally absent: iCloud mail requires an
|
||||
// app-specific password, which Thunderbird prompts for and stores in its own
|
||||
@@ -20,7 +21,7 @@ user_pref("mail.server.server1.authMethod", 3);
|
||||
user_pref("mail.server.server1.userName", "{{ thunderbird_icloud_email }}");
|
||||
user_pref("mail.server.server1.name", "{{ thunderbird_icloud_account_name }}");
|
||||
user_pref("mail.server.server1.directory-rel", "[ProfD]ImapMail/{{ thunderbird_icloud_imap_host }}");
|
||||
user_pref("mail.server.server1.directory", "{{ user_home }}/.thunderbird/{{ thunderbird_profile_dir }}/ImapMail/{{ thunderbird_icloud_imap_host }}");
|
||||
user_pref("mail.server.server1.directory", "{{ thunderbird_selected.profile }}/ImapMail/{{ thunderbird_icloud_imap_host }}");
|
||||
user_pref("mail.server.server1.max_cached_connections", 5);
|
||||
user_pref("mail.server.server1.check_new_mail", true);
|
||||
user_pref("mail.server.server1.check_time", 10);
|
||||
|
||||
27
dotfiles/common/.config/opencode/commands/mobile.md
Normal file
27
dotfiles/common/.config/opencode/commands/mobile.md
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
description: OpenCode Mobile (QR + push token)
|
||||
---
|
||||
Call the `mobile` tool.
|
||||
|
||||
Command arguments: $ARGUMENTS
|
||||
|
||||
- If $ARGUMENTS is non-empty, call the tool with { token: "$ARGUMENTS" }.
|
||||
- If $ARGUMENTS is empty, call the tool with no args to print the QR.
|
||||
|
||||
Token format:
|
||||
- `ExponentPushToken[xxxxxxxxxxxxxx]` - Register push token only
|
||||
- `ExponentPushToken[xxx] ServerUrl[http://...]` - Register with custom server URL
|
||||
|
||||
When to use ServerUrl:
|
||||
- Use when the mobile app is connected directly to a local server
|
||||
- The serverUrl will be used for notification deep links instead of tunnel
|
||||
- Omit when using tunnel connection (default behavior)
|
||||
|
||||
Important:
|
||||
- Do not output analysis/thoughts.
|
||||
- Only call the tool; return no extra text.
|
||||
|
||||
Examples:
|
||||
- `/mobile` - Show QR code for tunnel connection
|
||||
- `/mobile ExponentPushToken[xxxxxxxxxxxxxx]` - Register token
|
||||
- `/mobile ExponentPushToken[xxx] ServerUrl[http://192.168.1.100:4096]` - Register with custom URL
|
||||
@@ -3,5 +3,8 @@
|
||||
"instructions": [
|
||||
"~/.config/ai/bootstrap.md",
|
||||
"~/.config/ai/rules/safety.md"
|
||||
],
|
||||
"plugin": [
|
||||
"opencode-mobile@latest"
|
||||
]
|
||||
}
|
||||
|
||||
113
tests/test_thunderbird_profile.py
Normal file
113
tests/test_thunderbird_profile.py
Normal file
@@ -0,0 +1,113 @@
|
||||
"""Offline profile-selection regression tests; no real credentials or application."""
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
path = Path(__file__).resolve().parents[1] / 'ansible/roles/profile_desktop_gnome/files/thunderbird_profile.py'
|
||||
spec = importlib.util.spec_from_file_location('profile', path)
|
||||
profile = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(profile)
|
||||
|
||||
|
||||
class ProfileTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
self.home = Path(self.temp.name)
|
||||
|
||||
def seed(self, root, directory, account=True, install='TEST'):
|
||||
base = self.home / root
|
||||
target = base / directory
|
||||
target.mkdir(parents=True)
|
||||
(base / 'profiles.ini').write_text(
|
||||
f'[Profile0]\nName=original\nPath={directory}\nIsRelative=1\nDefault=1\n'
|
||||
f'[Install{install}]\nDefault={directory}\nLocked=1\n')
|
||||
if account:
|
||||
prefs = {'mail.accountmanager.accounts': 'account7',
|
||||
'mail.account.account7.server': 'server8',
|
||||
'mail.server.server8.type': 'imap',
|
||||
'mail.server.server8.hostname': 'imap.example.test'}
|
||||
(target / 'prefs.js').write_text('\n'.join(
|
||||
f'user_pref({json.dumps(k)}, {json.dumps(v)});' for k, v in prefs.items()))
|
||||
return target
|
||||
|
||||
def plan(self):
|
||||
return profile.plan(self.home, 'managed.default-release', 'managed')
|
||||
|
||||
def test_fresh_install(self):
|
||||
result = self.plan()
|
||||
self.assertFalse(result['existing_account'])
|
||||
self.assertEqual(result['root'], str(self.home / '.config/thunderbird'))
|
||||
self.assertIn('Default=1', result['profiles_ini'])
|
||||
self.assertEqual(list(self.home.iterdir()), []) # Discovery is read-only.
|
||||
|
||||
def test_xdg_account_wins_over_empty_legacy(self):
|
||||
old = self.seed('.config/thunderbird', 'original')
|
||||
self.seed('.thunderbird', 'empty', account=False)
|
||||
result = self.plan()
|
||||
self.assertTrue(result['existing_account'])
|
||||
self.assertEqual(result['profile'], str(old))
|
||||
self.assertIn('Path=empty', result['profiles_ini'])
|
||||
self.assertIn('Default=' + str(old), result['installs_ini'])
|
||||
|
||||
def test_existing_legacy_account_is_untouched(self):
|
||||
old = self.seed('.thunderbird', 'original')
|
||||
before = (old / 'prefs.js').read_bytes()
|
||||
result = self.plan()
|
||||
self.assertEqual(result['profile'], str(old))
|
||||
self.assertEqual((old / 'prefs.js').read_bytes(), before)
|
||||
|
||||
def test_user_js_is_not_evidence_of_an_existing_account(self):
|
||||
old = self.seed('.thunderbird', 'unused', account=False)
|
||||
(old / 'user.js').write_text('user_pref("mail.accountmanager.accounts", "account1");')
|
||||
self.assertFalse(self.plan()['existing_account'])
|
||||
|
||||
def test_absolute_profile_path(self):
|
||||
old = self.seed('.config/thunderbird', 'original')
|
||||
registry = old.parent / 'profiles.ini'
|
||||
registry.write_text(registry.read_text().replace('IsRelative=1', 'IsRelative=0')
|
||||
.replace('Path=original', 'Path=' + str(old)))
|
||||
self.assertEqual(self.plan()['profile'], str(old))
|
||||
|
||||
def test_second_run_is_idempotent(self):
|
||||
self.seed('.config/thunderbird', 'original')
|
||||
self.seed('.thunderbird', 'empty', account=False)
|
||||
first = self.plan()
|
||||
root = Path(first['root'])
|
||||
(root / 'profiles.ini').write_text(first['profiles_ini'])
|
||||
(root / 'installs.ini').write_text(first['installs_ini'])
|
||||
second = self.plan()
|
||||
self.assertEqual(first, second)
|
||||
|
||||
def test_registered_default_wins_over_unregistered_account(self):
|
||||
old = self.seed('.config/thunderbird', 'original')
|
||||
extra = old.parent / 'aaa-other'
|
||||
extra.mkdir()
|
||||
(extra / 'prefs.js').write_bytes((old / 'prefs.js').read_bytes())
|
||||
self.assertEqual(self.plan()['profile'], str(old))
|
||||
|
||||
def test_new_profile_does_not_overwrite_an_unconfigured_profile(self):
|
||||
old = self.seed('.thunderbird', 'managed.default-release', account=False)
|
||||
(old / 'prefs.js').write_text('// Existing local preferences, no mail account.\n')
|
||||
self.assertEqual(self.plan()['profile'], str(old) + '-1')
|
||||
|
||||
def test_pending_managed_bootstrap_is_reused(self):
|
||||
old = self.seed('.thunderbird', 'managed.default-release', account=False)
|
||||
(old / 'user.js').write_text('// Managed by Ansible from profile_desktop_gnome\n')
|
||||
self.assertEqual(self.plan()['profile'], str(old))
|
||||
|
||||
def test_other_installation_with_its_own_account_is_preserved(self):
|
||||
old = self.seed('.thunderbird', 'original')
|
||||
other = old.parent / 'beta'
|
||||
other.mkdir()
|
||||
(other / 'prefs.js').write_bytes((old / 'prefs.js').read_bytes())
|
||||
registry = old.parent / 'profiles.ini'
|
||||
registry.write_text(registry.read_text() + '[InstallBETA]\nDefault=beta\nLocked=1\n')
|
||||
result = self.plan()
|
||||
self.assertIn('[InstallBETA]\nDefault=beta\nLocked=1', result['profiles_ini'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user