From b08cf3d2009eab993576d72e0206026e30e1ca7d Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Wed, 5 Apr 2023 09:55:48 +0200
Subject: [PATCH] Automatically remove duplicate extensions

---
 scripts/Common/Config/Chromium/install-extension.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/scripts/Common/Config/Chromium/install-extension.sh b/scripts/Common/Config/Chromium/install-extension.sh
index b0894bdb..fb1516d3 100755
--- a/scripts/Common/Config/Chromium/install-extension.sh
+++ b/scripts/Common/Config/Chromium/install-extension.sh
@@ -39,6 +39,17 @@ else
     chmod -R a+rx "$EXTENSION_DIR";
     chmod -R u+w "$EXTENSION_DIR";
     mkdir -p "$EXTENSION_POLICY_DIR";
+    crxProperty="external_crx";
+
+    find "$EXTENSION_POLICY_DIR" -name "*.json" -print0 |
+        while IFS= read -r -d "" file
+        do
+            if [ "$(cat "$file" | jq -r ".$crxProperty")" == "$destination" ]
+            then
+                rm "$file";
+            fi;
+        done;
+
     {
         echo "{";
         echo '    "external_crx": "'"$destination"'",';