-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add VS Code installation script following spilled coffee principle #1275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,133 @@ | ||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||
| # VS Code Installation Utility | ||||||||||||||||||||||||||||||||||||||||
| # Automated installation following the spilled coffee principle | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Source common logging functions | ||||||||||||||||||||||||||||||||||||||||
| if [[ -n "${BASH_SOURCE[0]:-}" ]]; then | ||||||||||||||||||||||||||||||||||||||||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
| source "${SCRIPT_DIR}/logging.sh" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| install_vscode() { | ||||||||||||||||||||||||||||||||||||||||
| log_info "Setting up VS Code..." | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Check if VS Code is already installed | ||||||||||||||||||||||||||||||||||||||||
| if command -v code &> /dev/null; then | ||||||||||||||||||||||||||||||||||||||||
| CURRENT_VERSION=$(code --version 2>/dev/null | head -n1) | ||||||||||||||||||||||||||||||||||||||||
| log_success "Already installed: $CURRENT_VERSION" | ||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| log_info "Installing VS Code..." | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if [[ "$OSTYPE" == "darwin"* ]]; then | ||||||||||||||||||||||||||||||||||||||||
| # macOS installation via Homebrew | ||||||||||||||||||||||||||||||||||||||||
| if command -v brew &> /dev/null; then | ||||||||||||||||||||||||||||||||||||||||
| log_info "Using Homebrew..." | ||||||||||||||||||||||||||||||||||||||||
| if brew install --cask visual-studio-code; then | ||||||||||||||||||||||||||||||||||||||||
| log_success "Installed via Homebrew" | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| log_error "Homebrew install failed" | ||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| log_error "Homebrew not found" | ||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+35
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dependency installation should include error checking. If the package manager fails to install dependencies, the script continues without proper error handling.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wget command should include error handling to detect and handle download failures. This could lead to installation proceeding with an invalid or incomplete GPG key. |
||||||||||||||||||||||||||||||||||||||||
| # Linux installation using official Microsoft repository | ||||||||||||||||||||||||||||||||||||||||
| if command -v apt &> /dev/null; then | ||||||||||||||||||||||||||||||||||||||||
| # Ubuntu/Debian/Linux Mint | ||||||||||||||||||||||||||||||||||||||||
| log_info "Using apt with Microsoft repository..." | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Install dependencies | ||||||||||||||||||||||||||||||||||||||||
| sudo apt-get update | ||||||||||||||||||||||||||||||||||||||||
| sudo apt-get install -y wget gpg apt-transport-https | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛑 [Security Vulnerability]: The GPG key is downloaded and stored in an insecure manner. The temporary file is created in the current directory and could be tampered with before being installed1. Consider using a secure temporary directory with proper permissions.
Suggested change
Footnotes
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Add Microsoft GPG key | ||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Add VS Code repository | ||||||||||||||||||||||||||||||||||||||||
| echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" | \ | ||||||||||||||||||||||||||||||||||||||||
| sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Clean up temporary GPG file | ||||||||||||||||||||||||||||||||||||||||
| rm -f packages.microsoft.gpg | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Update and install VS Code | ||||||||||||||||||||||||||||||||||||||||
| sudo apt-get update | ||||||||||||||||||||||||||||||||||||||||
| if sudo apt-get install -y code; then | ||||||||||||||||||||||||||||||||||||||||
| log_success "Installed via apt" | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| log_error "apt install failed" | ||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| elif command -v pacman &> /dev/null; then | ||||||||||||||||||||||||||||||||||||||||
| # Arch Linux | ||||||||||||||||||||||||||||||||||||||||
| log_info "Using pacman..." | ||||||||||||||||||||||||||||||||||||||||
| if sudo pacman -S --noconfirm code; then | ||||||||||||||||||||||||||||||||||||||||
| log_success "Installed via pacman" | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| log_error "pacman install failed" | ||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| elif command -v dnf &> /dev/null; then | ||||||||||||||||||||||||||||||||||||||||
| # Fedora/RHEL | ||||||||||||||||||||||||||||||||||||||||
| log_info "Using dnf with Microsoft repository..." | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Import Microsoft GPG key | ||||||||||||||||||||||||||||||||||||||||
| sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Add VS Code repository | ||||||||||||||||||||||||||||||||||||||||
| 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" | \ | ||||||||||||||||||||||||||||||||||||||||
| sudo tee /etc/yum.repos.d/vscode.repo > /dev/null | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Install VS Code | ||||||||||||||||||||||||||||||||||||||||
| if sudo dnf install -y code; then | ||||||||||||||||||||||||||||||||||||||||
| log_success "Installed via dnf" | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| log_error "dnf install failed" | ||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| elif command -v snap &> /dev/null; then | ||||||||||||||||||||||||||||||||||||||||
| # Fallback to Snap if available | ||||||||||||||||||||||||||||||||||||||||
| log_info "Using snap..." | ||||||||||||||||||||||||||||||||||||||||
| if sudo snap install code --classic; then | ||||||||||||||||||||||||||||||||||||||||
| log_success "Installed via snap" | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| log_error "snap install failed" | ||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+108
to
+109
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The version verification could be more robust. Consider adding a minimum version check to ensure compatibility with the dotfiles setup.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| log_error "No supported package manager found" | ||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| log_error "Unsupported operating system: $OSTYPE" | ||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Verify installation | ||||||||||||||||||||||||||||||||||||||||
| if command -v code &> /dev/null; then | ||||||||||||||||||||||||||||||||||||||||
| NEW_VERSION=$(code --version 2>/dev/null | head -n1) | ||||||||||||||||||||||||||||||||||||||||
| log_success "VS Code installed successfully: $NEW_VERSION" | ||||||||||||||||||||||||||||||||||||||||
| log_info "You can now use 'code .' to open VS Code in the current directory" | ||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| log_error "Installation verification failed" | ||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Run installation if script is executed directly | ||||||||||||||||||||||||||||||||||||||||
| if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | ||||||||||||||||||||||||||||||||||||||||
| install_vscode | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a trap to handle script interruption and cleanup any temporary files. This ensures proper cleanup even if the script is interrupted.