﻿#!/bin/bash

if [ "$UID" -ne "0" ]
then
  echo "You are NOT root"
else
  apt update && apt upgrade -y && apt install -y curl
  curl https://packages.microsoft.com/keys/microsoft.asc |\
    gpg --dearmor > microsoft.gpg
  install -o root -g root -m 644 microsoft.gpg\
    /usr/share/keyrings/microsoft.gpg
  # Download a key formatted for PGP and convert it 
  # into an apt compatible format with a .gpg file 
  # extension. Do this by running "gpg --dearmor"
  sh -c \
  'echo "deb [arch=amd64 \
signed-by=/usr/share/keyrings/microsoft.gpg]" \
"https://packages.microsoft.com/repos/vscode stable main">\
/etc/apt/sources.list.d/vscode.list'
  # Keys are not in keyring, so 
  #   gpg --list-keys doesn't change
  rm -f microsoft.gpg
  apt update
  apt install -y code
fi
