Skip to content

Commit 0f45569

Browse files
committed
Enhance installation script and README for Visual Studio Code; add command-line options for custom installation paths, extensions, and minimal installs, while improving error handling and installation methods.
1 parent e0f85d9 commit 0f45569

File tree

2 files changed

+99
-21
lines changed

2 files changed

+99
-21
lines changed

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ chmod +x install_vscode.sh
3939
```
4040

4141
## Update VS Code 🔄
42-
To update VS Code and extensions:
42+
There are several ways to update VS Code and its components:
43+
44+
### Via Snap (Recommended)
4345
```bash
4446
sudo snap refresh code
4547
code --install-extension @outdated --force
@@ -88,8 +90,10 @@ code --install-extension <extension-id> --force
8890

8991
## Advanced Installation Options 🛠️
9092

93+
The script supports several command-line arguments for customized installation:
94+
9195
### Custom Installation Path
92-
Install VS Code in a specific location:
96+
Specify a custom installation directory:
9397
```bash
9498
sudo bash install_vscode.sh --install-path /custom/path
9599
```
@@ -105,6 +109,11 @@ Install specific extensions during setup:
105109
```bash
106110
sudo bash install_vscode.sh --extensions "ms-python.python ms-vscode.cpptools"
107111
```
112+
### Component Selection
113+
Control which components to install by combining flags:
114+
```bash
115+
sudo bash install_vscode.sh --no-snap --no-build --minimal
116+
```
108117

109118
### Debug Mode
110119
Run the script in debug mode:

install_vscode.sh

+88-19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,49 @@
22
# Claire Guerin 2021-2024
33
# run as root / admin
44

5+
# Default values
6+
INSTALL_PATH=""
7+
NON_INTERACTIVE=false
8+
CUSTOM_EXTENSIONS=""
9+
SKIP_SNAP=false
10+
SKIP_BUILD=false
11+
MINIMAL_INSTALL=false
12+
13+
# Parse command line arguments
14+
while [ $# -gt 0 ]; do
15+
case "$1" in
16+
--install-path)
17+
INSTALL_PATH="$2"
18+
shift 2
19+
;;
20+
--yes)
21+
NON_INTERACTIVE=true
22+
shift
23+
;;
24+
--extensions)
25+
CUSTOM_EXTENSIONS="$2"
26+
shift 2
27+
;;
28+
--no-snap)
29+
SKIP_SNAP=true
30+
shift
31+
;;
32+
--no-build)
33+
SKIP_BUILD=true
34+
shift
35+
;;
36+
--minimal)
37+
MINIMAL_INSTALL=true
38+
SKIP_BUILD=true
39+
shift
40+
;;
41+
*)
42+
echo "❌ Unknown option: $1"
43+
exit 1
44+
;;
45+
esac
46+
done
47+
548
# Enable debug mode if needed
649
if [ "$DEBUG" = "true" ]; then
750
set -x
@@ -55,16 +98,21 @@ detect_distro
5598
# Install prerequisites
5699
echo "🔍 Detecting system: $DISTRO $VERSION"
57100
sudo apt update || { echo "❌ apt update failed"; exit 1; }
58-
sudo apt install -y build-essential curl wget || { echo "❌ Failed to install prerequisites"; exit 1; }
59-
60-
# Install snapd if not present
61-
if ! command_exists snap; then
62-
echo "📦 Installing snapd..."
63-
sudo apt install -y snapd || { echo "❌ Failed to install snapd"; exit 1; }
64-
sudo systemctl enable snapd || true
65-
sudo systemctl start snapd || true
66-
# Wait for snapd service to be ready
67-
sleep 2
101+
if [ "$SKIP_BUILD" = "false" ]; then
102+
sudo apt install -y build-essential curl wget || { echo "❌ Failed to install prerequisites"; exit 1; }
103+
else
104+
sudo apt install -y curl wget || { echo "❌ Failed to install prerequisites"; exit 1; }
105+
fi
106+
107+
# Install snapd if needed
108+
if [ "$SKIP_SNAP" = "false" ]; then
109+
if ! command_exists snap; then
110+
echo "📦 Installing snapd..."
111+
sudo apt install -y snapd || { echo "❌ Failed to install snapd"; exit 1; }
112+
sudo systemctl enable snapd || true
113+
sudo systemctl start snapd || true
114+
sleep 2
115+
fi
68116
fi
69117

70118
# Special handling for different distributions
@@ -85,11 +133,8 @@ case "$DISTRO" in
85133
;;
86134
esac
87135

88-
# Install VS Code
89-
echo "📥 Installing Visual Studio Code..."
90-
sudo snap install --classic code || {
91-
echo "❌ Failed to install VS Code via snap. Trying alternative method..."
92-
# Fallback to .deb package
136+
# Function to use .deb package for VS Code installation
137+
use_deb_package() {
93138
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
94139
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
95140
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
@@ -98,15 +143,39 @@ sudo snap install --classic code || {
98143
rm packages.microsoft.gpg
99144
}
100145

146+
# Install VS Code
147+
echo "📥 Installing Visual Studio Code..."
148+
if [ "$SKIP_SNAP" = "false" ]; then
149+
sudo snap install --classic code || use_deb_package
150+
else
151+
use_deb_package
152+
fi
153+
101154
# Verify VS Code installation
102155
if ! command_exists code; then
103156
echo "❌ VS Code installation failed"
104157
exit 1
105158
fi
106159

107-
# Install GitHub Copilot extensions
108-
echo "🤖 Installing GitHub Copilot extensions..."
109-
code --install-extension GitHub.copilot || echo "⚠️ Failed to install GitHub Copilot extension"
110-
code --install-extension GitHub.copilot-chat || echo "⚠️ Failed to install GitHub Copilot Chat extension"
160+
# Install extensions
161+
if [ -n "$CUSTOM_EXTENSIONS" ]; then
162+
echo "🔧 Installing custom extensions..."
163+
for ext in $CUSTOM_EXTENSIONS; do
164+
code --install-extension "$ext" || echo "⚠️ Failed to install extension: $ext"
165+
done
166+
else
167+
echo "🤖 Installing GitHub Copilot extensions..."
168+
code --install-extension GitHub.copilot || echo "⚠️ Failed to install GitHub Copilot extension"
169+
code --install-extension GitHub.copilot-chat || echo "⚠️ Failed to install GitHub Copilot Chat extension"
170+
fi
171+
172+
# Add custom installation path handling if specified
173+
if [ -n "$INSTALL_PATH" ]; then
174+
echo "📁 Setting custom installation path: $INSTALL_PATH"
175+
mkdir -p "$INSTALL_PATH"
176+
if [ -d "/usr/share/code" ]; then
177+
cp -r /usr/share/code/* "$INSTALL_PATH/"
178+
fi
179+
fi
111180

112181
echo "✅ Installation complete! Please log out and log back in for all changes to take effect."

0 commit comments

Comments
 (0)