40 lines
1.8 KiB
Bash
Executable file
40 lines
1.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -e
|
|
if [ $(whoami) == "root" ]; then
|
|
echo "Run as a normal user, not root"
|
|
exit 1
|
|
fi
|
|
|
|
command_exists() { type "$1" &>/dev/null; }
|
|
|
|
if command_exists "apt-get"; then
|
|
sudo apt-get install wget gpg
|
|
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
|
|
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
|
|
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
|
|
rm -f packages.microsoft.gpg
|
|
sudo apt install apt-transport-https
|
|
sudo apt update
|
|
sudo apt install code
|
|
elif command_exists "yum"; then
|
|
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
|
|
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
|
|
yum check-update
|
|
sudo yum install code -y
|
|
elif command_exists "pacman"; then
|
|
yay -S visual-studio-code-bin --noconfirm --needed
|
|
elif command_exists "zypp"; then
|
|
# Untested
|
|
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
|
|
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ntype=rpm-md\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/zypp/repos.d/vscode.repo'
|
|
sudo zypper refresh
|
|
sudo zypper install code
|
|
elif command_exists "emerge"; then
|
|
echo Not yet supported, exiting...
|
|
exit
|
|
elif command_exists "apk"; then
|
|
echo Not yet supported, exiting...
|
|
exit
|
|
else
|
|
echo "Unsupported: unknown package manager and distro"
|
|
fi
|