RescueΒΆ

#! /bin/bash
FILE="$(realpath "${BASH_SOURCE[0]}")"
DIRECTORY="$(dirname "${FILE}")"
cd "${DIRECTORY}"

UPGRADE_SCRIPT='upgrade.sh'
HOST="${1}"
USER_HOST="root@${HOST}"

# remove known host's ssh public key
ssh-keygen -R "${HOST}"
# copy ssh id and host's public key
ssh-copy-id \
-o StrictHostKeyChecking=accept-new \
"${USER_HOST}"
# copy bash profile
scp /etc/bash.bashrc "${USER_HOST}:/etc/"
# copy upgrade script
scp "${UPGRADE_SCRIPT}" "${USER_HOST}:"
# run upgrade script
ssh "${USER_HOST}" "./${UPGRADE_SCRIPT}"
# launch session
ssh "${USER_HOST}" byobu new-session -d
# connect to session
mosh "${USER_HOST}" byobu attach-session
# remove other sources
rm /etc/apt/sources.list.d/*
# set official repository
echo -n "\
deb https://deb.debian.org/debian buster main contrib non-free
deb https://deb.debian.org/debian buster-updates main contrib non-free
deb https://deb.debian.org/debian-security buster/updates main contrib non-free
" > /etc/apt/sources.list
# set batch mode
export DEBIAN_FRONTEND=noninteractive
# update packages catalog
apt-get update
# upgrade keyring
apt-get --assume-yes install debian-archive-keyring
# update packages catalog
apt-get update
# upgrade critical dependency
apt-get --assume-yes install libc6-dev
# upgrade apt
apt-get --assume-yes install apt \
--option Dpkg::Options::=--force-confnew
# update packages catalog
apt-get update
# install mobile shell
apt-get --assume-yes install mosh
# install terminal multiplexer wrapper
apt-get --assume-yes install byobu
mkdir ~/.byobu
echo -n "\
tmux_left='session'
tmux_right='uptime whoami hostname date time'
screen_lower_left='session'
screen_lower_right='uptime whoami hostname date time'
screen_upper_left=''
screen_upper_right=''
" > ~/.byobu/status
# upgrade core utils
apt-get --assume-yes install coreutils
# install official parted dependency
apt-get --assume-yes install libparted2=3.2-25 \
--allow-downgrades
# install official parted
apt-get --assume-yes install parted=3.2-25
# upgrade multi disk admin
apt-get --assume-yes install mdadm
# upgrade remote synchronization
apt-get --assume-yes install rsync
# upgrade grub bios binaries
apt-get --assume-yes install grub-pc-bin
# install squashfs tools
apt-get --assume-yes install squashfs-tools
# clean packages
apt-get clean