-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-vscode-server.sh
executable file
·152 lines (132 loc) · 3.56 KB
/
install-vscode-server.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# Gettting arguments
MODE="INSTALL"
ENABLE_SERVICE="false"
TUNNEL_NAME="code-server"
while [[ $# -gt 0 ]]; do
case $1 in
-i)
MODE="INSTALL"
shift # past argument
;;
-u)
echo "Uninstalling Visual Studio Code"
MODE="UNINSTALL"
shift # past argument
;;
--enable-tunnel)
ENABLE_SERVICE="true"
shift # past argument
;;
--name)
TUNNEL_NAME=$2
shift # past argument
shift # past argument
;;
*)
echo "Invalid option $1" >&2
exit 1
;;
esac
done
function get_os {
case "$OSTYPE" in
linux*) echo "linux" ;;
darwin*) echo "mac" ;;
win*) echo "windows" ;;
msys*) echo "windows" ;;
cygwin*) echo "windows" ;;
bsd*) echo "bsd" ;;
solaris*) echo "solaris" ;;
*) echo "unknown" ;;
esac
}
function get_linux_distro {
DISTRO=$(lsb_release -si | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
echo "$DISTRO"
}
function get_linux_distro_version {
DISTRO_VERSION=$(lsb_release -sr | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
echo "$DISTRO_VERSION"
}
function get_linux_distro_codename {
DISTRO_CODENAME=$(lsb_release -sc | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
echo "$DISTRO_CODENAME"
}
install_service() {
code tunnel service install --accept-server-license-terms --name $TUNNEL_NAME
sudo loginctl enable-linger $USER
}
function install() {
echo "Installing Visual Studio Code"
if command -v code &>/dev/null; then
echo "Visual Studio Code is already installed, skipping installation"
return
fi
DEBIAN_FRONTEND=noninteractive sudo apt install curl gpg
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor --yes -o /usr/share/keyrings/packages.microsoft.gpg
sudo chmod a+r /usr/share/keyrings/packages.microsoft.gpg
echo \
"deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" |
sudo tee /etc/apt/sources.list.d/vscode.list >/dev/null
rm -f packages.microsoft.gpg
DEBIAN_FRONTEND=noninteractive sudo apt install -y apt-transport-https
sudo apt update
DEBIAN_FRONTEND=noninteractive sudo apt install -y code
DEBIAN_FRONTEND=noninteractive sudo apt autoremove -y
}
function login() {
code tunnel user login
}
function uninstall() {
echo "Uninstalling Visual Studio Code"
if command -v code &>/dev/null; then
code tunnel service uninstall
sudo apt remove -y code
sudo apt autoremove -y
fi
sudo rm -f /etc/apt/keyrings/packages.microsoft.gpg
sudo rm -f /etc/apt/sources.list.d/vscode.list
sudo rm -f /usr/share/keyrings/packages.microsoft.gpg
sudo rm -rf /home/$USER/.vscode
echo "Visual Studio Code has been uninstalled"
}
function install_devtunnel_cli() {
curl -sL https://aka.ms/DevTunnelCliInstall | bash
}
function check_for_vscode() {
if ! command -v code &>/dev/null; then
return 1
else
return 0
fi
}
OS=$(get_os)
if [ "$OS" != "linux" ]; then
echo "This script is only compatible with Linux, exiting"
exit 1
fi
if [ -z "$MODE" ]; then
echo "Choose either install or uninstall mode"
exit 1
fi
if [ "$MODE" == "INSTALL" ]; then
if ! check_for_vscode; then
echo "Visual Studio Code is not installed, installing"
install
install_devtunnel_cli
else
echo "Visual Studio Code is already installed, skipping installation"
fi
if [ "$ENABLE_SERVICE" = "true" ]; then
login
install_service
fi
fi
if [ "$MODE" == "UNINSTALL" ]; then
if check_for_vscode; then
uninstall
else
echo "Visual Studio Code is not installed, skipping uninstallation"
fi
fi