sh/bash/rescue.sh
2024-11-12 10:25:44 +01:00

114 lines
2.8 KiB
Bash

rescue_configure() {
local hostname="${1}"
# apt / conf
printf "\
Acquire::AllowInsecureRepositories False;
Acquire::AllowWeakRepositories False;
Acquire::AllowDowngradeToInsecureRepositories False;
Acquire::Check-Valid-Until True;
APT::Install-Recommends False;
APT::Install-Suggests False;
APT::Get::Show-Versions True;
Dir::Etc::SourceParts \"\";
Dpkg::Progress True;
" >"/etc/apt/apt.conf.d/apt.conf"
# apt / sources
printf "%s" "\
deb https://deb.debian.org/debian \
${DEBIAN_CODENAME} main non-free-firmware contrib non-free
deb https://deb.debian.org/debian \
${DEBIAN_CODENAME}-backports main non-free-firmware contrib non-free
deb https://deb.debian.org/debian \
${DEBIAN_CODENAME}-updates main non-free-firmware contrib non-free
deb https://deb.debian.org/debian-security \
${DEBIAN_CODENAME}-security main non-free-firmware contrib non-free
" >"/etc/apt/sources.list"
# bash / rc
main_link_bashrc
mv .bashrc .bashrc.old
# host name
hostname "${hostname}"
# locales
printf "\
en_US.UTF-8 UTF-8
fr_FR.UTF-8 UTF-8
" >"/etc/locale.gen"
# generate locales
locale-gen
# update catalog
apt_update
# disable frontend
debian_disable_frontend
# install backports
apt_install_backports "tmux"
# install packages
apt_install_release "apt-file" "mosh" "screen" "byobu"
# update catalog
apt_update
}
rescue_install() {
# update catalog
apt_update
# disable frontend
debian_disable_frontend
# upgrade packages
apt_upgrade
# install packages
apt_install_release \
"man-db" \
"dmidecode" "efibootmgr" "lshw" "pciutils" "usbutils" \
"parted" "mdadm" "cryptsetup-bin" "lvm2" \
"btrfs-progs" "dosfstools" "duperemove" "squashfs-tools" \
"git" "micro" "nano" "python3" "rsync" "vim" \
"exa" "lf" "ncdu" "nnn" "ranger" "tree" \
"file" "htop" "iotop" "ipcalc" "libdigest-sha3-perl" "lsof"
# install backports
apt_install_backports \
"grub-pc-bin" \
\
"grub-efi-amd64-bin"
}
rescue_upload() {
local host="${1}"
local hostname="${2}"
if [ -n "${hostname}" ]; then
local user="root"
#
local user_host="${user}@${host}"
# remove fingerprints
ssh-keygen -R "${host}"
# copy ssh id
ssh-copy-id \
-o "StrictHostKeyChecking=accept-new" \
"${user_host}"
# upload root
rsync --delete --recursive \
"${MAIN_BASH_ROOT}/" "${user_host}:/etc/bash/"
# call setup
# TODO variable
ssh "${user_host}" -- "\
source \"/etc/bash/main.sh\" ; rescue_configure \"${hostname}\""
# create session
ssh "${user_host}" -- byobu new-session -d
# send keys
ssh "${user_host}" -- byobu send-keys "rescue_install" "C-m"
# attach session
mosh "${user_host}" -- byobu attach-session
else
echo "host & hostname"
return 1
fi
}
rescue_wipe_1_zero() {
dd status="progress" \
if="/dev/zero" of="/dev/mapper/crypt" bs="512M"
}
rescue_wipe_3_close() {
umount "/media/boot"
umount "/media/crypt" &&
cryptsetup luksClose "crypt"
}