From 654616ab46e45e31ec490e8a4a55f076211e88df Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sat, 4 Dec 2021 18:01:46 +0100 Subject: [PATCH] contrib/extract-search-engines.sh: new file (MR 19) Add a script that allows extracting the list of search engines enabled in the current firefox build. There is no way to simply disable all built-in search engines, so we need a list like this. Note that the search engines can only be removed in the ESR version. I've briefly tried to find such a list in the source code, but didn't find it without spending too much effort. Besides, I'm guessing that in the source code it's stored in almost the same format found in the "omni.ja" zip archive. --- contrib/extract-search-engines.sh | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 contrib/extract-search-engines.sh diff --git a/contrib/extract-search-engines.sh b/contrib/extract-search-engines.sh new file mode 100755 index 0000000..47cd2a0 --- /dev/null +++ b/contrib/extract-search-engines.sh @@ -0,0 +1,72 @@ +#!/bin/sh -e +# Copyright 2021 Oliver Smith +# SPDX-License-Identifier: GPL-3.0-or-later +# +# Extract the search engine names found in your current Firefox installation, +# and create a list suitable for policies.json that removes all of them except +# for what's in remove_allowed_dirs(). Note that SearchEngines can only be +# configured via policies.json in the ESR version of firefox. +# Related: https://github.com/mozilla/policy-templates/blob/master/README.md + +remove_allowed_dirs() { + rm -rf \ + ddg \ + wikipedia +} + +get_names() { + grep \ + '"name":' \ + */manifest.json \ + | cut -d '"' -f 4 \ + | grep -v '__MSG_extensionName__' \ + | grep -v '^form$' +} + +get_names_localized() { + grep \ + -A1 \ + '"extensionName":' \ + */_locales/*/messages.json \ + | grep '"message":' \ + | cut -d '"' -f 4 +} + +get_names_all_sorted() { + (get_names; get_names_localized) | sort -u +} + +print_json() { + local first=1 + + echo ' "SearchEngines": {' + echo ' "Default": "DuckDuckGo",' + echo ' "Remove": [' + + get_names_all_sorted | while IFS= read -r i; do + if [ "$first" -eq 1 ]; then + first=0 + else + echo "," + fi + printf " \"$i\"" + done + + echo '' + echo ' ]' + echo ' },' +} + + +OMNI="/usr/lib/firefox/browser/omni.ja" +TMPDIR="$(mktemp -d "/tmp/extract-search-engines-XXXXXX")" +cd "$TMPDIR" + +unzip -q "$OMNI" +cd "chrome/browser/search-extensions" + +remove_allowed_dirs +print_json + +cd ~ +rm -r "$TMPDIR"