#!/usr/bin/env bash set -euo pipefail command_exists() { type "${1}" >/dev/null 2>&1 } ensure_tool() { local -r tool="${1}" if ! command_exists "${tool}"; then echo "missing required tool: ${tool}" exit 1 fi } setup_for_darwin() { ensure_tool brew echo 'cask "visual-studio-code"' | brew bundle --file=- } setup_for_debian() { ensure_tool curl ensure_tool dpkg local -r url="https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64" local -r filename="$(curl -fsSI "${url}" | grep -i "location:" | cut -d' ' -f2 | sed 's/.*\(code.*\.deb\)/\1/')" echo "Downloading..." curl --progress-bar --continue-at - --output "/tmp/${filename}" -L "${url}" echo echo "Installing..." sudo dpkg --install "/tmp/${filename}" echo echo "Done!" } case $OSTYPE in darwin*) setup_for_darwin;; linux*) if command_exists dpkg; then setup_for_debian fi ;; *) echo "Unknown OS!" exit 1;; esac