mirror of
				https://codeberg.org/claui/mobile-config-firefox.git
				synced 2025-11-04 04:25:55 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									445c1da339
								
							
						
					
					
						commit
						654616ab46
					
				
					 1 changed files with 72 additions and 0 deletions
				
			
		
							
								
								
									
										72
									
								
								contrib/extract-search-engines.sh
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										72
									
								
								contrib/extract-search-engines.sh
									
										
									
									
									
										Executable 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"
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue