From 15afed2381caac4617e63080aafe0b50f4262921 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sat, 20 Jun 2020 16:09:19 -0400 Subject: Beautify json output with jq Also, keep around an uncompressed copy when creating a *lz4 file. --- firefox-sideloader/functions.sh | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'firefox-sideloader/functions.sh') diff --git a/firefox-sideloader/functions.sh b/firefox-sideloader/functions.sh index 62a8624..2934c09 100644 --- a/firefox-sideloader/functions.sh +++ b/firefox-sideloader/functions.sh @@ -58,17 +58,38 @@ illustrate_leak() prof=$(get_default_firefox_profile_dir) && jq . < "$prof"/extensions.json | grep "$HOME" } -copy_file_with_filter() +filter() { + if which jq >/dev/null + then jq . + else cat + fi | sed -e "$filter_json" +} + +copy_json_file_with_filter() +{ + which mozlz4 >/dev/null || PATH=$HOME/.cargo/bin:$PATH + which mozlz4 >/dev/null || exit 1 local new="$1" old="$2" f="$3" filter_json filter_json="s/${old//\//\\/}/${new//\//\\/}/g" [ -d "$old" -a -d "$new" ] || return touch --reference="$old"/"$f" "$new"/"$f" || return chmod --reference="$old"/"$f" "$new"/"$f" || return case "$f" in - *lz4) mozlz4 - < "$old"/"$f" | sed -e "$filter_json" | mozlz4 -z - > "$new"/"$f" ;; - *) sed -e "$filter_json" < "$old"/"$f" > "$new"/"$f" ;; + *lz4) mozlz4 - | filter | mozlz4 -z - ;; + *) filter + esac < "$old"/"$f" > "$new"/"$f" + + # Keep an uncompressed copy for inspection + local keep + case "$f" in + *.lz4) keep=$new/${f%lz4}unused ;; + *lz4) keep=$new/${f%lz4}.unused ;; + *) keep= ;; esac + if [ "$keep" ] + then mozlz4 - < "$new"/"$f" > "$keep" + fi } keep_prefs() @@ -92,7 +113,7 @@ prefs() { if [ "$COPY_ALL_PREFS" ] then - copy_file_with_filter "$new_profile_dir" "$old_profile_dir" 'prefs.js' + copy_json_file_with_filter "$new_profile_dir" "$old_profile_dir" 'prefs.js' else egrep "^user_pref.\"($(printf "%s" $(keep_prefs)))\"" "$old_profile_dir"/prefs.js > "$new_profile_dir"/prefs.js printf '%s\n' 'user_pref("browser.startup.homepage_override.mstone", "ignore");' >> "$new_profile_dir"/prefs.js @@ -112,8 +133,8 @@ clone_profile_raw() cp -r --preserve=mode,timestamps -t "$new_profile_dir" -- "$old_profile_dir"/{extensions/,extension-{setting,preference}s.json} || return - copy_file_with_filter "$new_profile_dir" "$old_profile_dir" 'extensions.json' - copy_file_with_filter "$new_profile_dir" "$old_profile_dir" 'addonStartup.json.lz4' + copy_json_file_with_filter "$new_profile_dir" "$old_profile_dir" 'extensions.json' + copy_json_file_with_filter "$new_profile_dir" "$old_profile_dir" 'addonStartup.json.lz4' prefs } @@ -135,6 +156,12 @@ clone_default_profile() clone_profile_raw "$old_dir" "$new_name" } +list_extensions() +{ + [ "$firefox_profile" ] || firefox_profile=$(get_default_firefox_profile_dir) + jq -c '.addons[] | {id:.id, name:.locales[0].name}' < "$firefox_profile"/extensions.json +} + runtest() { . functions.sh -- cgit v1.2.3