wget -O upgrade.sh 'https://gist.github.com/Bonveio/bb40b778b33ef06868c14c0240f25967/raw/upgrade.sh'
- Debian 10 to 11
bash upgrade.sh 11 - Debian 11 to 12
bash upgrade.sh 12 - Debian 12 to 13
bash upgrade.sh 13
| #!/bin/bash | |
| # shellcheck disable=SC1091,SC2086 | |
| ## Intended only for Cybree cloud instance usage | |
| ## to use "bash upgrade.sh 11" | |
| ## another example: "./upgrade.sh 11" | |
| APT_CONF='/etc/apt/sources.list' | |
| ## init first occurence | |
| [[ ! -f /root/.IS_FIRST_RUN ]] && echo 1 > /root/.IS_FIRST_RUN; | |
| RepoList(){ | |
| [[ ! -f ${APT_CONF}.bckup ]] && mv ${APT_CONF} ${APT_CONF}.bckup; | |
| local o="${1}" | |
| case ${o} in | |
| 10|buster) | |
| cat <<'EOF'> ${APT_CONF} | |
| deb http://deb.debian.org/debian buster main | |
| deb-src http://deb.debian.org/debian buster main | |
| deb http://security.debian.org/debian-security buster-security main | |
| deb-src http://security.debian.org/debian-security buster-security main | |
| deb http://deb.debian.org/debian buster-updates main | |
| deb-src http://deb.debian.org/debian buster-updates main | |
| deb http://deb.debian.org/debian buster-backports main | |
| deb-src http://deb.debian.org/debian buster-backports main | |
| EOF | |
| ;; | |
| 11|bullseye) | |
| cat <<'EOF'> ${APT_CONF} | |
| deb http://deb.debian.org/debian bullseye main contrib | |
| deb-src http://deb.debian.org/debian bullseye main contrib | |
| deb http://deb.debian.org/debian-security/ bullseye-security main contrib | |
| deb-src http://deb.debian.org/debian-security/ bullseye-security main contrib | |
| deb http://deb.debian.org/debian bullseye-updates main contrib | |
| deb-src http://deb.debian.org/debian bullseye-updates main contrib | |
| deb http://deb.debian.org/debian bullseye-backports main contrib | |
| deb-src http://deb.debian.org/debian bullseye-backports main contrib | |
| EOF | |
| ;; | |
| 12|bookworm) | |
| cat <<'EOF'> ${APT_CONF} | |
| deb http://deb.debian.org/debian bookworm main contrib | |
| deb-src http://deb.debian.org/debian bookworm main contrib | |
| deb http://deb.debian.org/debian-security/ bookworm-security main contrib | |
| deb-src http://deb.debian.org/debian-security/ bookworm-security main contrib | |
| deb http://deb.debian.org/debian bookworm-updates main contrib | |
| deb-src http://deb.debian.org/debian bookworm-updates main contrib | |
| deb http://deb.debian.org/debian bookworm-backports main contrib | |
| deb-src http://deb.debian.org/debian bookworm-backports main contrib | |
| EOF | |
| ;; | |
| 13|trixie) | |
| cat <<'EOF'> ${APT_CONF} | |
| deb http://deb.debian.org/debian trixie main contrib | |
| deb-src http://deb.debian.org/debian trixie main contrib | |
| deb http://deb.debian.org/debian-security/ trixie-security main contrib | |
| deb-src http://deb.debian.org/debian-security/ trixie-security main contrib | |
| deb http://deb.debian.org/debian trixie-updates main contrib | |
| deb-src http://deb.debian.org/debian trixie-updates main contrib | |
| deb http://deb.debian.org/debian trixie-backports main contrib | |
| deb-src http://deb.debian.org/debian trixie-backports main contrib | |
| EOF | |
| ;; | |
| *) | |
| echo 'Invalid Debian version' | |
| echo 'Choose from 10~13' | |
| exit 1 | |
| ;; | |
| esac | |
| } | |
| StartUpgrade(){ | |
| ## Backup sshd_config first | |
| [[ ! -f /etc/ssh/sshd_config.bckup ]] && cp -f /etc/ssh/sshd_config /etc/ssh/sshd_config.bckup; | |
| unset VERSION_ID;source /etc/os-release; | |
| local OLD_VER="$VERSION_ID";local A="$OLD_VER" | |
| export DEBIAN_FRONTEND=noninteractive | |
| export aptopt='-o DPKg::Options::=--force-confnew -o DPkg::Options::=--force-overwrite --allow-unauthenticated -o Acquire::ForceIPv4=true' | |
| if [[ "$(cat /root/.IS_FIRST_RUN)" -eq 0 ]]; then | |
| apt autoremove -yf ${aptopt} | |
| apt autoclean | |
| apt clean | |
| rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | |
| fi | |
| rm -rf /var/lib/dpkg/lock /var/{lib/apt/lists/lock,cache/apt/archives/lock} | |
| apt update ${aptopt} | |
| dpkg --configure -a | |
| apt upgrade -yf ${aptopt} | |
| apt --fix-broken install -yf ${aptopt} | |
| rm -rf /var/lib/apt/lists/* | |
| RepoList "${1}" | |
| apt update ${aptopt} | |
| apt upgrade -yf ${aptopt} | |
| apt full-upgrade -yf ${aptopt} | |
| if [[ "$(cat /root/.IS_FIRST_RUN)" -eq 1 ]]; then | |
| echo 0 > /root/.IS_FIRST_RUN; | |
| else | |
| [[ "$VERSION_ID" == "12" ]] && rm -f /root/.IS_FIRST_RUN; | |
| apt autoremove -yf ${aptopt} | |
| fi | |
| cp -f /etc/ssh/sshd_config.bckup /etc/ssh/sshd_config;systemctl -q restart ssh sshd; | |
| unset VERSION_ID;source /etc/os-release; | |
| local NEW_VER="$VERSION_ID";local B="$NEW_VER" | |
| local P0="Upgraded from Debian ${A} to Debian ${B}" | |
| if [[ "${A}" == "${B}" ]]; then | |
| echo "Upgrade failed, version still Debian $B";exit 1; | |
| else | |
| echo "${P0} success" | |
| fi | |
| } | |
| StartUpgrade ${1} | |
| echo "Try to reboot your instance now to take effect" | |
| exit 0 |