|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
| 3 | +# Temporarily disable exit on error to run a robust cleanup process. |
| 4 | +set +e |
| 5 | + |
| 6 | +echo "--- Running VS Code Pre-installation Cleanup ---" |
| 7 | + |
| 8 | +# Find and remove ANY apt source file mentioning the conflicting repository. |
| 9 | +CONFLICTING_FILES=$(grep -lr "packages.microsoft.com/repos/code" /etc/apt/sources.list.d/ /etc/apt/sources.list 2>/dev/null) |
| 10 | +if [ -n "$CONFLICTING_FILES" ]; then |
| 11 | + echo "Found conflicting repository files. Removing them..." |
| 12 | + echo "$CONFLICTING_FILES" | sudo xargs -r rm -f |
| 13 | + echo "Removed: $CONFLICTING_FILES" |
| 14 | +fi |
| 15 | + |
| 16 | +# Remove both potential GPG keys if they exist. |
| 17 | +if [ -f "/usr/share/keyrings/microsoft.gpg" ]; then |
| 18 | + echo "Removing old GPG key..." |
| 19 | + sudo rm -f /usr/share/keyrings/microsoft.gpg |
| 20 | +fi |
| 21 | +if [ -f "/etc/apt/keyrings/packages.microsoft.gpg" ]; then |
| 22 | + echo "Removing new GPG key..." |
| 23 | + sudo rm -f /etc/apt/keyrings/packages.microsoft.gpg |
| 24 | +fi |
| 25 | + |
| 26 | +# Refresh apt lists and check if the conflict is resolved. |
| 27 | +echo "Refreshing package lists to verify the fix..." |
| 28 | +sudo apt-get update -y |
| 29 | +APT_EXIT_CODE=$? |
| 30 | + |
| 31 | +# Re-enable exit on error for the rest of the script. |
| 32 | +set -e |
| 33 | + |
| 34 | +if [ $APT_EXIT_CODE -ne 0 ]; then |
| 35 | + echo "--------------------------------------------------------------------" |
| 36 | + echo "FATAL: APT conflict could not be resolved automatically." |
| 37 | + echo "The installation of VS Code cannot proceed." |
| 38 | + echo "--------------------------------------------------------------------" |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | + |
| 42 | +echo "--- Cleanup Successful. Proceeding with VS Code installation. ---" |
| 43 | + |
| 44 | +# Now, proceed with a clean installation of the VS Code repository. |
3 | 45 | cd /tmp
|
4 |
| -wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor >packages.microsoft.gpg |
| 46 | +wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg |
5 | 47 | sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
|
6 |
| -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 |
| 48 | +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 |
7 | 49 | rm -f packages.microsoft.gpg
|
8 | 50 | cd -
|
9 | 51 |
|
10 |
| -sudo apt update -y |
11 |
| -sudo apt install -y code |
| 52 | +# Update package list again and install VS Code |
| 53 | +sudo apt-get update -y |
| 54 | +sudo apt-get install -y code |
12 | 55 |
|
| 56 | +# Configure VS Code |
13 | 57 | mkdir -p ~/.config/Code/User
|
14 | 58 | cp ~/.local/share/omakub/configs/vscode.json ~/.config/Code/User/settings.json
|
15 | 59 |
|
|
0 commit comments