Last active
August 14, 2023 00:39
-
-
Save adamlacombe/102d223df7a3d659b5055fd3e0c85c4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check for jq and install if needed | |
if ! command -v jq &> /dev/null; then | |
echo "jq not found! Installing..." | |
sudo apt update && sudo apt install -y jq | |
echo "jq installed successfully!" | |
fi | |
DEFAULT_CONFIG_FILE="extensions.json" | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
--extensions=*) | |
CONFIG_FILE="${1#*=}" | |
shift | |
;; | |
*) | |
echo "Unknown parameter passed: $1" | |
exit 1 | |
;; | |
esac | |
done | |
CONFIG_FILE="${CONFIG_FILE:-$DEFAULT_CONFIG_FILE}" | |
if [[ ! -f $CONFIG_FILE ]]; then | |
echo "Configuration file $CONFIG_FILE not found!" | |
exit 1 | |
fi | |
DEFAULT_VERSION="latest" | |
install_extension(){ | |
publisher="$1" | |
extension_name="$2" | |
version="${3:-$DEFAULT_VERSION}" | |
marketplace="${4:-default}" | |
if [[ "$marketplace" == "default" ]]; then | |
echo "Installing $extension_name from default marketplace..." | |
/tmp/code-server/bin/code-server --install-extension "$publisher.$extension_name" | |
elif [[ "$marketplace" == "vsmarketplace" ]]; then | |
download_url="https://${publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${publisher}/extension/${extension_name}/${version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage" | |
echo "Installing $extension_name from VS Marketplace..." | |
if wget "$download_url" -O "${extension_name}.VSIX"; then | |
/tmp/code-server/bin/code-server --install-extension "${extension_name}.VSIX" && rm "${extension_name}.VSIX" | |
echo "$extension_name installed successfully from VS Marketplace!" | |
else | |
echo "Error downloading $extension_name from VS Marketplace." | |
fi | |
else | |
echo "Unknown marketplace: $marketplace" | |
fi | |
} | |
length=$(jq '. | length' "$CONFIG_FILE") | |
for (( i=0; i<$length; i++ )); do | |
publisher=$(jq -r ".[$i].publisher" "$CONFIG_FILE") | |
extension_name=$(jq -r ".[$i].extension_name" "$CONFIG_FILE") | |
version=$(jq -r ".[$i].version" "$CONFIG_FILE") | |
marketplace=$(jq -r ".[$i].marketplace" "$CONFIG_FILE") | |
install_extension "$publisher" "$extension_name" "$version" "$marketplace" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment