#!/bin/sh

# misc/firefox/policies.json hash:
# {{ include joinPath .chezmoi.homeDir ".dotfiles" "misc/firefox/policies.json" | sha256sum }}
# misc/firefox/search.json.mozlz4 hash:
# {{ include joinPath .chezmoi.homeDir ".dotfiles" "misc/firefox/search.json.mozlz4" | sha256sum }}

# Check if firefox is installed
if ! command -v firefox &> /dev/null; then
  echo "[WARNING] Firefox is not installed. Skip this script."
  exit 0
fi

src=~/.dotfiles/misc/firefox/search.json.mozlz4
dest=~/.mozilla/firefox/*.default/search.json.mozlz4
if ! cmp -s "$src" "$dest" 2>/dev/null; then
  echo "[INFO] search.json.mozlz4 is updated, copying..."
  cp "$src" "$dest"
fi

{{ if .wheel }}

src=~/.dotfiles/misc/firefox/policies.json
dest=/etc/firefox/policies/policies.json
if ! cmp -s "$src" "$dest" 2>/dev/null; then
  echo "[INFO] policies.json is updated, copying..."
  echo "[ACTION] elevation required"
  sudo cp "$src" "$dest" && exit 0
fi

{{ end }}
