#!/bin/sh

### Add Microsoft's extensions to VSCodium

# In the file resources/app/product.json change this :

# "extensionsGallery": {
# 	"serviceUrl": "https://open-vsx.org/vscode/gallery",
# 	"itemUrl": "https://open-vsx.org/vscode/item"
# },

# to this :

#  "extensionsGallery": {
# 	"serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery",
# 	"cacheUrl": "https://vscode.blob.core.windows.net/gallery/index",
# 	"itemUrl": "https://marketplace.visualstudio.com/items"
# },

apply(){
	FILE="$1"
	test -z "$FILE" && FILE=/opt/vscodium/resources/app/product.json
	SEP='  '
	OLD="$SEP\\\"extensionsGallery\": {\\n$SEP$SEP\\\"serviceUrl\\\": \\\"https://open-vsx.org/vscode/gallery\\\",\\n$SEP$SEP\\\"itemUrl\\\": \\\"https://open-vsx.org/vscode/item\\\"\\n$SEP},"
	NEW="$SEP\"extensionsGallery\": {\\n$SEP$SEP\"serviceUrl\": \"https://marketplace.visualstudio.com/_apis/public/gallery\",\\n$SEP$SEP\"cacheUrl\": \"https://vscode.blob.core.windows.net/gallery/index\",\\n$SEP$SEP\"itemUrl\": \"https://marketplace.visualstudio.com/items\"\\n$SEP},"

	sed -i ":a;N;\$!ba;s&$OLD&$NEW&g" "$FILE"
}

apply "$1"