From ba2f9c7c5e2a8350d7fd0ef51b83f55b1939d2af Mon Sep 17 00:00:00 2001
From: Lilac <lilac@noreply.bgme.me>
Date: Mon, 15 May 2023 06:23:33 +0000
Subject: [PATCH] code-marketplace: auto updated to 1.78.0-1

---
 repo/code-marketplace/PKGBUILD                | 20 +++++++++
 repo/code-marketplace/code-marketplace.hook   | 10 +++++
 .../code-marketplace/code-marketplace.install | 15 +++++++
 repo/code-marketplace/patch.sh                | 41 +++++++++++++++++++
 4 files changed, 86 insertions(+)
 create mode 100644 repo/code-marketplace/PKGBUILD
 create mode 100644 repo/code-marketplace/code-marketplace.hook
 create mode 100644 repo/code-marketplace/code-marketplace.install
 create mode 100755 repo/code-marketplace/patch.sh

diff --git a/repo/code-marketplace/PKGBUILD b/repo/code-marketplace/PKGBUILD
new file mode 100644
index 0000000..6736c9d
--- /dev/null
+++ b/repo/code-marketplace/PKGBUILD
@@ -0,0 +1,20 @@
+# Maintainer: Sainnhe Park <sainnhe@gmail.com>
+pkgname=code-marketplace
+pkgver=1.78.0
+pkgrel=1
+pkgdesc='Enable vscode marketplace in Code OSS'
+arch=('any')
+url='https://marketplace.visualstudio.com/vscode'
+license=('unknown')
+depends=('code' 'sed' 'grep')
+optdepends=('code-features: unblock some extensions specific to the official build')
+install="${pkgname}.install"
+source=('code-marketplace.hook'
+        'patch.sh')
+md5sums=('2f5ebcc1795bb5eac95162059a9a496e'
+         'bdbc94a53d8cbdabac97054b0a2ad92b')
+
+package() {
+  install -Dm 644 "${srcdir}"/code-marketplace.hook "${pkgdir}"/usr/share/libalpm/hooks/code-marketplace.hook
+  install -Dm 755 "${srcdir}"/patch.sh "${pkgdir}"/usr/share/code-marketplace/patch.sh
+}
diff --git a/repo/code-marketplace/code-marketplace.hook b/repo/code-marketplace/code-marketplace.hook
new file mode 100644
index 0000000..a720f0a
--- /dev/null
+++ b/repo/code-marketplace/code-marketplace.hook
@@ -0,0 +1,10 @@
+[Trigger]
+Operation = Install
+Operation = Upgrade
+Type = Path
+Target = usr/lib/code/product.json
+
+[Action]
+Description = [code-marketplace] Patching product.json...
+Exec = /usr/share/code-marketplace/patch.sh
+When = PostTransaction
diff --git a/repo/code-marketplace/code-marketplace.install b/repo/code-marketplace/code-marketplace.install
new file mode 100644
index 0000000..4f43e28
--- /dev/null
+++ b/repo/code-marketplace/code-marketplace.install
@@ -0,0 +1,15 @@
+post_install() {
+  /usr/share/code-marketplace/patch.sh
+}
+
+pre_upgrade() {
+  /usr/share/code-marketplace/patch.sh -R
+}
+
+post_upgrade() {
+  /usr/share/code-marketplace/patch.sh
+}
+
+pre_remove() {
+  /usr/share/code-marketplace/patch.sh -R
+}
diff --git a/repo/code-marketplace/patch.sh b/repo/code-marketplace/patch.sh
new file mode 100755
index 0000000..75141c3
--- /dev/null
+++ b/repo/code-marketplace/patch.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env sh
+
+product_json_path="/usr/lib/code/product.json"
+
+_patch() {
+  # Patch "extensionsGallery"
+
+  # Remove original "extensionsGallery" key.
+  sed -i -z -e 's/\t"extensionsGallery.*item"\n\t},\n//' \
+    "${1}"
+
+  # Add new "extensionsGallery" key
+  # Use vim to open product.json in official release and visual select the lines of "extensionsGallery"
+  # Execute :'<,'>join
+  # Select joined line and execute :'<,'>s/\//\\\//g
+  sed -i -e '/^\t"quality/a\\t"extensionsGallery": { "nlsBaseUrl": "https:\/\/www.vscode-unpkg.net\/_lp\/", "serviceUrl": "https:\/\/marketplace.visualstudio.com\/_apis\/public\/gallery", "cacheUrl": "https:\/\/vscode.blob.core.windows.net\/gallery\/index", "itemUrl": "https:\/\/marketplace.visualstudio.com\/items", "publisherUrl": "https:\/\/marketplace.visualstudio.com\/publishers", "resourceUrlTemplate": "https:\/\/{publisher}.vscode-unpkg.net\/{publisher}\/{name}\/{version}\/{path}", "controlUrl": "https:\/\/az764295.vo.msecnd.net\/extensions\/marketplace.json" },' \
+    "${1}"
+
+
+
+  # Patch "linkProtectionTrustedDomains"
+
+  # Use vim to open product.json in official release and visual select the line of "linkProtectionTrustedDomains"
+  # Execute :'<,'>s/\//\\\//g
+  sed -i -e 's/^\t"linkProtectionTrustedDomains.*/\t"linkProtectionTrustedDomains": ["https:\/\/*.visualstudio.com", "https:\/\/*.microsoft.com", "https:\/\/aka.ms", "https:\/\/*.gallerycdn.vsassets.io", "https:\/\/*.github.com", "https:\/\/login.microsoftonline.com", "https:\/\/*.vscode.dev", "https:\/\/*.github.dev", "https:\/\/gh.io"],/' \
+    "${1}"
+}
+
+_restore() {
+  sed -i -e 's/^\t"extensionsGallery.*/\t"extensionsGallery": {\n\t\t"serviceUrl": "https:\/\/open-vsx.org\/vscode\/gallery",\n\t\t"itemUrl": "https:\/\/open-vsx.org\/vscode\/item"\n\t},/' \
+    -e 's/^\t"linkProtectionTrustedDomains.*/\t"linkProtectionTrustedDomains": ["https:\/\/open-vsx.org"],/' \
+    -e '/^\t"extensionTips/d' \
+    "${1}"
+}
+
+# Use grep -q to detect if product.json has already been patched.
+if grep -q "open-vsx" "${product_json_path}" & [ "$1" = '' ]; then
+  _patch "${product_json_path}"
+elif ! grep -q "open-vsx" "${product_json_path}" & [ "$1" = '-R' ]; then
+  _restore "${product_json_path}"
+fi