sh/shell/rescue/common.sh

114 lines
2.8 KiB
Bash
Raw Normal View History

2024-11-11 16:33:55 +00:00
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 \
2024-11-12 05:03:36 +00:00
${DEBIAN_CODENAME} main non-free-firmware contrib non-free
2024-11-11 16:33:55 +00:00
deb https://deb.debian.org/debian \
2024-11-12 05:03:36 +00:00
${DEBIAN_CODENAME}-backports main non-free-firmware contrib non-free
2024-11-11 16:33:55 +00:00
deb https://deb.debian.org/debian \
2024-11-12 05:03:36 +00:00
${DEBIAN_CODENAME}-updates main non-free-firmware contrib non-free
2024-11-11 16:33:55 +00:00
deb https://deb.debian.org/debian-security \
2024-11-12 05:03:36 +00:00
${DEBIAN_CODENAME}-security main non-free-firmware contrib non-free
2024-11-11 16:33:55 +00:00
" >"/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
2024-11-11 19:42:37 +00:00
apt_update
2024-11-11 16:33:55 +00:00
# disable frontend
debian_disable_frontend
# install backports
2024-11-12 05:03:36 +00:00
apt_install_backports "tmux"
2024-11-11 16:33:55 +00:00
# install packages
2024-11-12 05:03:36 +00:00
apt_install_release "apt-file" "mosh" "screen" "byobu"
2024-11-11 16:33:55 +00:00
# update catalog
2024-11-11 19:42:37 +00:00
apt_update
2024-11-11 16:33:55 +00:00
}
2024-11-11 16:52:34 +00:00
rescue_install() {
# update catalog
2024-11-11 19:42:37 +00:00
apt_update
2024-11-11 16:52:34 +00:00
# disable frontend
debian_disable_frontend
# upgrade packages
2024-11-11 19:40:56 +00:00
apt_upgrade
2024-11-11 16:52:34 +00:00
# install packages
2024-11-12 05:03:36 +00:00
apt_install_release \
2024-11-11 16:52:34 +00:00
"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
2024-11-12 05:03:36 +00:00
apt_install_backports \
2024-11-11 16:52:34 +00:00
"grub-pc-bin" \
\
"grub-efi-amd64-bin"
}
2024-11-11 16:56:25 +00:00
rescue_upload() {
local host="${1}"
local hostname="${2}"
2024-11-12 09:25:44 +00:00
if [ -n "${hostname}" ]; then
2024-11-11 16:56:25 +00:00
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 \
2024-11-15 15:26:54 +00:00
"$(main_env_root)" "${user_host}:/etc"
2024-11-11 16:56:25 +00:00
# call setup
# TODO variable
ssh "${user_host}" -- "\
2024-11-13 10:24:51 +00:00
. \"/etc/bash/main.sh\" ; rescue_configure \"${hostname}\""
2024-11-11 16:56:25 +00:00
# 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
2024-11-11 20:08:52 +00:00
echo "host & hostname"
2024-11-11 16:56:25 +00:00
return 1
fi
}
2024-11-11 16:59:03 +00:00
2024-11-11 17:02:21 +00:00
rescue_wipe_1_zero() {
2024-11-12 19:22:58 +00:00
fs_wipe "/dev/mapper/crypt" "512M"
2024-11-11 17:02:21 +00:00
}
2024-11-11 16:59:03 +00:00
rescue_wipe_3_close() {
umount "/media/boot"
umount "/media/crypt" &&
cryptsetup luksClose "crypt"
}