Skip to content

[WIP] Fix issues in linux-dist-upgrade.sh script#28

Merged
wickedyoda merged 1 commit intomainfrom
copilot/fix-linux-dist-upgrade-script
Nov 21, 2025
Merged

[WIP] Fix issues in linux-dist-upgrade.sh script#28
wickedyoda merged 1 commit intomainfrom
copilot/fix-linux-dist-upgrade-script

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 21, 2025

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Problem: The newly added file updates_scripts/linux-dist-upgrade.sh in PR #27 contains diff artifacts and broken commands which prevent the repository from merging and the script from running. Specifically:

  • The file contains diff artifacts (e.g., "[-1,1]+") and other patch markers in the committed content.
  • The script invokes apt autopurge which is not a valid apt subcommand and will fail at runtime.
  • The file lacks some robustness and safety checks (doesn't backup /etc/apt/sources.list.d, uses grep -oP on /etc/os-release rather than sourcing it, may fail when variables are unset, does not set strict shell options, no final newline).

Goal: Create a pull request that replaces the broken updates_scripts/linux-dist-upgrade.sh with a cleaned, tested script that removes diff artifacts, fixes the invalid autopurge call, and improves safety and robustness. The PR should include a clear commit message explaining the fixes.

Required changes (apply to updates_scripts/linux-dist-upgrade.sh):

  • Replace the file contents with the cleaned script below (this fully replaces the file). Ensure the file has a trailing newline.
  • Use set -euo pipefail and defensive variable defaults.
  • Source /etc/os-release for reliable ID and codename detection.
  • Backup /etc/apt/sources.list and /etc/apt/sources.list.d to timestamped backups.
  • Replace apt autopurge -y with apt-get -y --purge autoremove (or apt autoremove --purge -y) and avoid calling both autoremove and autopurge redundantly.
  • Ensure the here-docs correctly write to /etc/apt/sources.list using sudo tee >/dev/null <<EOF.

New file content (exact replacement):

#!/bin/bash
set -euo pipefail

echo "=== Universal Dist-Upgrade Script ==="

Backup sources before doing anything

BACKUP_DATE=$(date +%F-%H%M)
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup."$BACKUP_DATE" 2>/dev/null || true
sudo mkdir -p /etc/apt/sources.list.d 2>/dev/null || true
sudo cp -r /etc/apt/sources.list.d /etc/apt/sources.list.d.backup."$BACKUP_DATE" 2>/dev/null || true

Detect OS + Version by sourcing /etc/os-release for robustness

if [ -f /etc/os-release ]; then
. /etc/os-release
else
echo "/etc/os-release not found; cannot detect OS."
exit 1
fi

ID=${ID:-}
VERSION_CODENAME=${VERSION_CODENAME:-}
UBUNTU_CODENAME=${UBUNTU_CODENAME:-$VERSION_CODENAME}
PRETTY=${PRETTY_NAME:-$NAME}

echo "Detected OS: $ID"
echo "Detected Version: $VERSION_CODENAME"
echo "Pretty Name: $PRETTY"
echo ""

###############################################################################

Debian Upgrade Path

###############################################################################

if [ "$ID" = "debian" ]; then
echo "=== Debian detected ==="

# Map old → new
if [ "$VERSION_CODENAME" = "bullseye" ]; then
    TARGET="bookworm"
elif [ "$VERSION_CODENAME" = "bookworm" ]; then
    TARGET="trixie"
else
    echo "⚠ Unknown Debian codename: $VERSION_CODENAME"
    echo "Exiting for safety."
    exit 1
fi

echo "Upgrading Debian $VERSION_CODENAME → $TARGET"

sudo tee /etc/apt/sources.list >/dev/null << EOF
deb http://deb.debian.org/debian $TARGET main contrib non-free non-free-firmware
deb http://deb.debian.org/debian $TARGET-updates main contrib non-free non-free-firmware
deb http://security.debian.org/debian-security $TARGET-security main contrib non-free non-free-firmware

EOF

fi

###############################################################################

Ubuntu Upgrade Path

###############################################################################

if [ "$ID" = "ubuntu" ]; then
echo "=== Ubuntu detected ==="

# Map current → target LTS (safe path)
if [ "$UBUNTU_CODENAME" = "jammy" ]; then
    TARGET="noble"   # 22.04 → 24.04
elif [ "$UBUNTU_CODENAME" = "noble" ]; then
    TARGET="noble"   # Already latest
else
    echo "⚠ Unsupported Ubuntu release: $UBUNTU_CODENAME"
    echo "Supported: jammy → noble"
    exit 1
fi

echo "Upgrading Ubuntu $UBUNTU_CODENAME → $TARGET"

sudo tee /etc/apt/sources.list >/dev/null << EOF
deb http://archive.ubuntu.com/ubuntu/ $TARGET main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ $TARGET-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ $TARGET-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu $TARGET-security main restricted universe multiverse

EOF

fi

###############################################################################

Kali Linux Upgrade Path

###############################################################################

if [ "$ID" = "kali" ]; then
echo "=== Kali Rolling detected ==="
echo "Switching to latest Rolling repositories"

sudo tee /etc/apt/sources.list >/dev/null << EOF
deb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware

EOF

fi

#############################...

This pull request was created as a result of the following prompt from Copilot chat.

Problem: The newly added file updates_scripts/linux-dist-upgrade.sh in PR #27 contains diff artifacts and broken commands which prevent the repository from merging and the script from running. Specifically:

  • The file contains diff artifacts (e.g., "[-1,1]+") and other patch markers in the committed content.
  • The script invokes apt autopurge which is not a valid apt subcommand and will fail at runtime.
  • The file lacks some robustness and safety checks (doesn't backup /etc/apt/sources.list.d, uses grep -oP on /etc/os-release rather than sourcing it, may fail when variables are unset, does not set strict shell options, no final newline).

Goal: Create a pull request that replaces the broken updates_scripts/linux-dist-upgrade.sh with a cleaned, tested script that removes diff artifacts, fixes the invalid autopurge call, and improves safety and robustness. The PR should include a clear commit message explaining the fixes.

Required changes (apply to updates_scripts/linux-dist-upgrade.sh):

  • Replace the file contents with the cleaned script below (this fully replaces the file). Ensure the file has a trailing newline.
  • Use set -euo pipefail and defensive variable defaults.
  • Source /etc/os-release for reliable ID and codename detection.
  • Backup /etc/apt/sources.list and /etc/apt/sources.list.d to timestamped backups.
  • Replace apt autopurge -y with apt-get -y --purge autoremove (or apt autoremove --purge -y) and avoid calling both autoremove and autopurge redundantly.
  • Ensure the here-docs correctly write to /etc/apt/sources.list using sudo tee >/dev/null <<EOF.

New file content (exact replacement):

#!/bin/bash
set -euo pipefail

echo "=== Universal Dist-Upgrade Script ==="

Backup sources before doing anything

BACKUP_DATE=$(date +%F-%H%M)
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup."$BACKUP_DATE" 2>/dev/null || true
sudo mkdir -p /etc/apt/sources.list.d 2>/dev/null || true
sudo cp -r /etc/apt/sources.list.d /etc/apt/sources.list.d.backup."$BACKUP_DATE" 2>/dev/null || true

Detect OS + Version by sourcing /etc/os-release for robustness

if [ -f /etc/os-release ]; then
. /etc/os-release
else
echo "/etc/os-release not found; cannot detect OS."
exit 1
fi

ID=${ID:-}
VERSION_CODENAME=${VERSION_CODENAME:-}
UBUNTU_CODENAME=${UBUNTU_CODENAME:-$VERSION_CODENAME}
PRETTY=${PRETTY_NAME:-$NAME}

echo "Detected OS: $ID"
echo "Detected Version: $VERSION_CODENAME"
echo "Pretty Name: $PRETTY"
echo ""

###############################################################################

Debian Upgrade Path

###############################################################################

if [ "$ID" = "debian" ]; then
echo "=== Debian detected ==="

# Map old → new
if [ "$VERSION_CODENAME" = "bullseye" ]; then
    TARGET="bookworm"
elif [ "$VERSION_CODENAME" = "bookworm" ]; then
    TARGET="trixie"
else
    echo "⚠ Unknown Debian codename: $VERSION_CODENAME"
    echo "Exiting for safety."
    exit 1
fi

echo "Upgrading Debian $VERSION_CODENAME → $TARGET"

sudo tee /etc/apt/sources.list >/dev/null << EOF
deb http://deb.debian.org/debian $TARGET main contrib non-free non-free-firmware
deb http://deb.debian.org/debian $TARGET-updates main contrib non-free non-free-firmware
deb http://security.debian.org/debian-security $TARGET-security main contrib non-free non-free-firmware

EOF

fi

###############################################################################

Ubuntu Upgrade Path

###############################################################################

if [ "$ID" = "ubuntu" ]; then
echo "=== Ubuntu detected ==="

# Map current → target LTS (safe path)
if [ "$UBUNTU_CODENAME" = "jammy" ]; then
    TARGET="noble"   # 22.04 → 24.04
elif [ "$UBUNTU_CODENAME" = "noble" ]; then
    TARGET="noble"   # Already latest
else
    echo "⚠ Unsupported Ubuntu release: $UBUNTU_CODENAME"
    echo "Supported: jammy → noble"
    exit 1
fi

echo "Upgrading Ubuntu $UBUNTU_CODENAME → $TARGET"

sudo tee /etc/apt/sources.list >/dev/null << EOF
deb http://archive.ubuntu.com/ubuntu/ $TARGET main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ $TARGET-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ $TARGET-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu $TARGET-security main restricted universe multiverse

EOF

fi

###############################################################################

Kali Linux Upgrade Path

###############################################################################

if [ "$ID" = "kali" ]; then
echo "=== Kali Rolling detected ==="
echo "Switching to latest Rolling repositories"

sudo tee /etc/apt/sources.list >/dev/null << EOF
deb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware

EOF

fi

###############################################################################

Upgrade Execution

###############################################################################

echo ""
echo "=== Updating package lists ==="
sudo apt update

echo "=== Full system upgrade ==="
sudo apt full-upgrade -y || sudo apt --fix-broken install -y

echo "=== Dist-upgrade ==="
sudo apt dist-upgrade -y

echo "=== Cleaning up ==="
sudo apt autoremove -y
sudo apt-get -y --purge autoremove || true
sudo apt clean -y

echo ""
echo "============================================"
echo " System successfully upgraded!"
echo " A reboot is recommended: sudo reboot"
echo "============================================"

Notes:

  • The changes are limited to updates_scripts/linux-dist-upgrade.sh only.
  • The PR must use branch name fix/linux-dist-upgrade (create from main) and include the commit message: "Fix linux-dist-upgrade.sh: remove diff artifacts, fix autopurge, improve robustness".

Please create the pull request against the main branch with the above changes.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@wickedyoda wickedyoda marked this pull request as ready for review November 21, 2025 20:26
@wickedyoda wickedyoda merged commit ea2fecc into main Nov 21, 2025
1 check failed
@wickedyoda wickedyoda deleted the copilot/fix-linux-dist-upgrade-script branch November 21, 2025 20:26
Copilot AI requested a review from wickedyoda November 21, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants