Skip to content

Instantly share code, notes, and snippets.

@Taurolyon
Created August 13, 2025 15:02
Show Gist options
  • Select an option

  • Save Taurolyon/2ae2a766fc2bc4c5e9ced86557652d1d to your computer and use it in GitHub Desktop.

Select an option

Save Taurolyon/2ae2a766fc2bc4c5e9ced86557652d1d to your computer and use it in GitHub Desktop.
#!/bin/bash
# bring current packages up to date
apt update && apt upgrade -y
# update sources to 'trixie'
sed -i 's/bookworm/trixie/g' /etc/apt/sources.list
sed -i 's/bookworm/trixie/g' /etc/apt/sources.list.d/*.list
apt update
# commence update
apt dist-upgrade -y
#cleanup and reboot
apt autoremove -y
reboot
@Taurolyon
Copy link
Author

#!/bin/bash

# Function to check the exit status of the previous command
check_error() {
  if [ $? -ne 0 ]; then
    echo "Error: $1 failed. Exiting script."
    exit 1
  fi
}

# STAGE 1: Bring current packages up to date
echo "STAGE 1: Updating package lists and upgrading current packages..."
apt update && apt upgrade -y
check_error "apt update and upgrade"

# STAGE 2: Update sources to 'trixie'
echo "STAGE 2: Updating sources to 'trixie'..."
sed -i 's/bookworm/trixie/g' /etc/apt/sources.list
check_error "updating /etc/apt/sources.list"

sed -i 's/bookworm/trixie/g' /etc/apt/sources.list.d/*.list 2>/dev/null
check_error "updating /etc/apt/sources.list.d/*.list"

# STAGE 3: Update package lists again after sources change
echo "STAGE 3: Updating package lists after changing sources..."
apt update
check_error "apt update"

# STAGE 4: Commence distribution upgrade
echo "STAGE 4: Upgrading distribution to 'trixie'..."
apt dist-upgrade -y
check_error "apt dist-upgrade"

# STAGE 5: Cleanup
echo "STAGE 5: Cleaning up unnecessary packages..."
apt autoremove -y
check_error "apt autoremove"

# STAGE 6: Reboot with timer and cancel option
echo "STAGE 6: Preparing to reboot the system..."
echo "The system will reboot in 30 seconds. Press Ctrl+C to cancel the reboot."
sleep 30

# Final reboot
echo "Rebooting now..."
reboot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment