#!/bin/bash
# Elevate script
if [ ! "$UID" -eq 0 ]
then
    sudo bash "$BASH_SOURCE"
else
    apt install -y wget gpg
    keyFile=$(mktemp)

    wget -qO- https://packages.microsoft.com/keys/microsoft.asc \
        | gpg --dearmor > $keyFile

    install -D -o root -g root -m 644 $keyFile /etc/apt/keyrings/packages.microsoft.gpg

    echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" \
        | tee /etc/apt/sources.list.d/vscode.list

    rm -f $keyFile

    apt update
    apt install -y code
fi