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.
This commit is contained in:
Oliver Smith 2021-12-04 18:01:46 +01:00
parent 445c1da339
commit 654616ab46
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -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"