install userChrome.css using autoconfig instead of schell scripts (MR 2)

Firefox can run an autoconfig Javascript on startup, which can be used to
install and update userChrome.css, both when creating a new profile and
using a pre-existing one.

This removes the need for a wrapper script and related complications
(changes to $PATH, different processing for new and pre-existing
profiles...)

Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
This commit is contained in:
Arnaud Ferraris 2020-08-20 13:20:42 +02:00
parent 08e2288138
commit 712b850c3b
5 changed files with 39 additions and 46 deletions

View file

@ -27,13 +27,11 @@ install: all
"$(DESTDIR)/etc/firefox/policies/policies.json"
install -Dm644 src/prefs.js \
"$(DESTDIR)/$(FIREFOX_DIR)/defaults/pref/mobile-config.js"
install -Dm644 src/mobile-config-autoconfig.js \
"$(DESTDIR)/$(FIREFOX_DIR)/mobile-config-autoconfig.js"
install -Dm644 "out/home.html" \
"$(DESTDIR)/usr/share/mobile-config-firefox/home.html"
install -Dm644 "out/userChrome.css" \
"$(DESTDIR)/etc/mobile-config-firefox/userChrome.css"
install -Dm755 "src/mobile-config-firefox.sh" \
"$(DESTDIR)/usr/mobile-config/bin/firefox"
install -Dm755 "src/mobile-config-path.sh" \
"$(DESTDIR)/etc/profile.d/mobile-config-path.sh"
.PHONY: all clean install

View file

@ -0,0 +1,33 @@
// Copyright 2020 Arnaud Ferraris, Oliver Smith
// SPDX-License-Identifier: GPL-3.0-or-later
// This is a Firefox autoconfig file:
// https://support.mozilla.org/en-US/kb/customizing-firefox-using-autoconfig
// Import custom userChrome.css on startup or new profile creation
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
// Create <profile>/chrome/ directory if not already present
var chromeDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
chromeDir.append("chrome");
if (!chromeDir.exists()) {
chromeDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
}
// Create nsIFile objects for userChrome.css in <profile>/chrome/ and in /etc/
var chromeFile = chromeDir.clone();
chromeFile.append("userChrome.css");
var defaultChrome = new FileUtils.File("/etc/mobile-config-firefox/userChrome.css");
// Remove the existing userChrome.css if older than the installed one
if (chromeFile.exists() && defaultChrome.exists() &&
chromeFile.lastModifiedTime < defaultChrome.lastModifiedTime) {
chromeFile.remove(false);
}
// Copy userChrome.css to <profile>/chrome/
if (!chromeFile.exists()) {
defaultChrome.copyTo(chromeDir, "userChrome.css");
}

View file

@ -1,39 +0,0 @@
#!/bin/sh
# Copyright 2020 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
# Create chrome/userChrome.css symlink in a firefox profile dir
# $1: path to profile dir, e.g. "/home/user/.mozilla/firefox/asdf.default"
prepare_profile() {
mkdir -p "$1/chrome"
if ! [ -e "$1/chrome/userChrome.css" ]; then
ln -sv /etc/mobile-config-firefox/userChrome.css \
"$1/chrome/userChrome.css"
fi
}
if [ -e ~/.mozilla/firefox/profiles.ini ]; then
# Firefox was started without this wrapper and created profiles.ini.
# Add the userChrome.css symlink to all existing profiles, then let
# firefox run with the default profile.
for profiledir in ~/.mozilla/firefox/*/; do
if ! [ -e "$profiledir/prefs.js" ]; then
continue
fi
prepare_profile "$profiledir"
done
exec /usr/bin/firefox "$@"
else
# Firefox was not started without this wrapper. Create a profile dir
# called "firefox.default" if it does not exist yet, and add the
# userChrome.css symlink. Let firefox use this profile. It will not
# create the profiles.ini file.
profiledir=~/.mozilla/firefox/firefox.default
prepare_profile "$profiledir"
exec /usr/bin/firefox --profile "$profiledir" "$@"
fi

View file

@ -1,3 +0,0 @@
#!/bin/sh
export PATH="/usr/local/bin:/usr/mobile-config/bin:$PATH"

View file

@ -1,6 +1,10 @@
// Copyright 2020 Oliver Smith, Martijn Braam
// SPDX-License-Identifier: GPL-3.0-or-later
// Set up autoconfig (we use it to copy/update userChrome.css into profile dir)
pref('general.config.filename', "mobile-config-autoconfig.js");
pref('general.config.obscure_value', 0);
// Select a mobile user agent for firefox (same as tor browser on android)
pref('general.useragent.override', 'Mozilla/5.0 (Android 6.0; Mobile; rv:68.0) Gecko/20100101 Firefox/68.0');