diff --git a/Makefile b/Makefile index 090fca3..c112679 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/mobile-config-autoconfig.js b/src/mobile-config-autoconfig.js new file mode 100644 index 0000000..07e3194 --- /dev/null +++ b/src/mobile-config-autoconfig.js @@ -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 /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 /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 /chrome/ +if (!chromeFile.exists()) { + defaultChrome.copyTo(chromeDir, "userChrome.css"); +} diff --git a/src/mobile-config-firefox.sh b/src/mobile-config-firefox.sh deleted file mode 100644 index 842395c..0000000 --- a/src/mobile-config-firefox.sh +++ /dev/null @@ -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 diff --git a/src/mobile-config-path.sh b/src/mobile-config-path.sh deleted file mode 100644 index d33dbb6..0000000 --- a/src/mobile-config-path.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -export PATH="/usr/local/bin:/usr/mobile-config/bin:$PATH" diff --git a/src/prefs.js b/src/prefs.js index b8e9b79..12113cf 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -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');