This commit is contained in:
Marc Beninca 2024-11-11 17:14:04 +01:00
parent 5776a03fe4
commit 6419243098
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -1,10 +1,10 @@
rescue_hetzner_configure() { rescue_hetzner_configure() {
local hostname="${1}" local hostname="${1}"
local package local package
local packages=( local packages=(
'mosh' 'mosh'
'screen' 'tmux' 'byobu' 'screen' 'tmux' 'byobu'
'apt-file' 'apt-file'
) )
# apt / conf # apt / conf
echo -n "\ echo -n "\
@ -17,14 +17,14 @@ APT::Install-Suggests False;
APT::Get::Show-Versions True; APT::Get::Show-Versions True;
Dir::Etc::SourceParts ''; Dir::Etc::SourceParts '';
Dpkg::Progress True; Dpkg::Progress True;
" > '/etc/apt/apt.conf' " >'/etc/apt/apt.conf'
# apt / sources # apt / sources
echo -n "\ echo -n "\
deb https://deb.debian.org/debian bookworm main non-free-firmware contrib non-free deb https://deb.debian.org/debian bookworm main non-free-firmware contrib non-free
deb https://deb.debian.org/debian bookworm-backports main non-free-firmware contrib non-free deb https://deb.debian.org/debian bookworm-backports main non-free-firmware contrib non-free
deb https://deb.debian.org/debian bookworm-updates main non-free-firmware contrib non-free deb https://deb.debian.org/debian bookworm-updates main non-free-firmware contrib non-free
deb https://deb.debian.org/debian-security bookworm-security main non-free-firmware contrib non-free deb https://deb.debian.org/debian-security bookworm-security main non-free-firmware contrib non-free
" > '/etc/apt/sources.list' " >'/etc/apt/sources.list'
# bash / rc # bash / rc
main_link_bashrc main_link_bashrc
mv .bashrc .bashrc.old mv .bashrc .bashrc.old
@ -34,7 +34,7 @@ deb https://deb.debian.org/debian-security bookworm-security main non-free-firmw
echo -n "\ echo -n "\
en_US.UTF-8 UTF-8 en_US.UTF-8 UTF-8
fr_FR.UTF-8 UTF-8 fr_FR.UTF-8 UTF-8
" > '/etc/locale.gen' " >'/etc/locale.gen'
# generate locales # generate locales
locale-gen locale-gen
# update catalog # update catalog
@ -42,11 +42,12 @@ fr_FR.UTF-8 UTF-8
# #
debian_disable_frontend debian_disable_frontend
# install packages # install packages
for package in "${packages[@]}" ; do for package in "${packages[@]}"; do
echo ; echo "${package}" echo
echo "${package}"
apt-get install \ apt-get install \
--assume-yes \ --assume-yes \
"${package}" "${package}"
apt_clean_cache apt_clean_cache
done done
# update catalog # update catalog
@ -57,19 +58,19 @@ rescue_hetzner_install() {
local package local package
local release='bookworm' local release='bookworm'
local packages=( local packages=(
# installed # installed
'dmidecode' 'efibootmgr' 'pciutils' 'usbutils' 'dmidecode' 'efibootmgr' 'pciutils' 'usbutils'
'parted' 'mdadm' 'cryptsetup-bin' 'lvm2' 'parted' 'mdadm' 'cryptsetup-bin' 'lvm2'
'btrfs-progs' 'dosfstools' 'btrfs-progs' 'dosfstools'
'git' 'nano' 'python3' 'rsync' 'vim' 'git' 'nano' 'python3' 'rsync' 'vim'
'file' 'htop' 'lsof' 'man-db' 'tree' 'uuid-runtime' 'file' 'htop' 'lsof' 'man-db' 'tree' 'uuid-runtime'
# install # install
'lshw' 'lshw'
'duperemove' 'squashfs-tools' 'duperemove' 'squashfs-tools'
'grub-efi-amd64-bin' 'grub-pc-bin' 'grub-efi-amd64-bin' 'grub-pc-bin'
'libdigest-sha3-perl' 'micro' 'libdigest-sha3-perl' 'micro'
'iotop' 'iotop'
'exa' 'ipcalc' 'lf' 'ncdu' 'nnn' 'ranger' 'exa' 'ipcalc' 'lf' 'ncdu' 'nnn' 'ranger'
) )
local backports=( local backports=(
) )
@ -82,20 +83,22 @@ rescue_hetzner_install() {
# #
apt_clean_cache apt_clean_cache
# install packages # install packages
for package in "${packages[@]}" ; do for package in "${packages[@]}"; do
echo ; echo "${package}" echo
echo "${package}"
apt-get install \ apt-get install \
--assume-yes \ --assume-yes \
"${package}" "${package}"
apt_clean_cache apt_clean_cache
done done
# install backports # install backports
for package in "${backports[@]}" ; do for package in "${backports[@]}"; do
echo ; echo "${package}" echo
echo "${package}"
apt-get install \ apt-get install \
--assume-yes \ --assume-yes \
--target-release "${release}-backports" \ --target-release "${release}-backports" \
"${package}" "${package}"
apt_clean_cache apt_clean_cache
done done
} }
@ -103,7 +106,7 @@ rescue_hetzner_install() {
rescue_hetzner_upload() { rescue_hetzner_upload() {
local host="${1}" local host="${1}"
local hostname="${2}" local hostname="${2}"
if [ "${hostname}" ] ; then if [ "${hostname}" ]; then
local user='root' local user='root'
# #
local user_host="${user}@${host}" local user_host="${user}@${host}"
@ -111,8 +114,8 @@ rescue_hetzner_upload() {
ssh-keygen -R "${host}" ssh-keygen -R "${host}"
# copy ssh id # copy ssh id
ssh-copy-id \ ssh-copy-id \
-o 'StrictHostKeyChecking=accept-new' \ -o 'StrictHostKeyChecking=accept-new' \
"${user_host}" "${user_host}"
# upload root # upload root
rsync --delete --recursive "${MAIN_BASH_ROOT}/" "${user_host}:/etc/bash/" rsync --delete --recursive "${MAIN_BASH_ROOT}/" "${user_host}:/etc/bash/"
# call setup # call setup
@ -149,131 +152,139 @@ rescue_hetzner_wipe_8_8_0_init() {
read read
# #
number=0 number=0
for device in "${devices[@]}" ; do for device in "${devices[@]}"; do
((number++)) ((number++))
echo ; echo "#${number}: ${device}" echo
echo "#${number}: ${device}"
# #
parted "${device}" --script mktable gpt parted "${device}" --script \
mktable gpt
# #
parted "${device}" unit "${unit}" \ parted "${device}" \
mkpart "crypt-${number}" 33282 7630885 unit "${unit}" mkpart "crypt-${number}" 33282 7630885
# #
parted "${device}" unit "${unit}" \ parted "${device}" \
mkpart "boot-${number}" 514 33282 unit "${unit}" mkpart "boot-${number}" 514 33282
# #
parted "${device}" unit "${unit}" \ parted "${device}" \
mkpart "esp-${number}" 2 514 unit "${unit}" mkpart "esp-${number}" 2 514
parted "${device}" set 3 esp on parted "${device}" \
set 3 esp on
# #
parted "${device}" unit "${unit}" \ parted "${device}" \
mkpart "bios-${number}" 1 2 unit "${unit}" mkpart "bios-${number}" 1 2
parted "${device}" set 4 bios_grub on parted "${device}" \
set 4 bios_grub on
done done
# #
number=0 number=0
for device in "${devices[@]}" ; do for device in "${devices[@]}"; do
((number++)) ((number++))
echo ; echo "#${number}: ${device}4" echo
echo "#${number}: ${device}4"
# wipe bios # wipe bios
dd \ dd \
if='/dev/zero' of="${device}4" if='/dev/zero' of="${device}4"
done done
# #
number=0 number=0
for device in "${devices[@]}" ; do for device in "${devices[@]}"; do
((number++)) ((number++))
echo ; echo "#${number}: ${device}3" echo
echo "#${number}: ${device}3"
# format esp # format esp
dd \ dd \
if='/dev/zero' of="${device}3" bs='1M' if='/dev/zero' of="${device}3" bs='1M'
mkfs.vfat \ mkfs.vfat \
-F 32 \ -F 32 \
-S 4096 \ -S 4096 \
-i "0000000${number}" \ -i "0000000${number}" \
-n "esp-${number}" \ -n "esp-${number}" \
"${device}3" "${device}3"
# mount esp # mount esp
mkdir --parents "/media/esp/${number}" mkdir --parents "/media/esp/${number}"
mount "${device}3" "/media/esp/${number}" mount "${device}3" "/media/esp/${number}"
done done
# #
number=0 number=0
for device in "${devices[@]}" ; do for device in "${devices[@]}"; do
((number++)) ((number++))
echo ; echo "#${number}: ${device}2" echo
echo "#${number}: ${device}2"
# wipe boot # wipe boot
dd status='progress' \ dd status='progress' \
if='/dev/zero' of="${device}2" bs='1G' count=1 if='/dev/zero' of="${device}2" bs='1G' count=1
done done
# #
members=() members=()
for device in "${devices[@]}" ; do for device in "${devices[@]}"; do
members+=("${device}2") members+=("${device}2")
done done
mdadm \ mdadm \
--create '/dev/md/boot' \ --create '/dev/md/boot' \
--level 0 \ --level 0 \
--metadata 1 \ --metadata 1 \
--name 'md:boot' \ --name 'md:boot' \
--raid-devices ${#devices[@]} \ --raid-devices ${#devices[@]} \
--uuid '00000000:00000000:00000000:00000002' \ --uuid '00000000:00000000:00000000:00000002' \
"${members[@]}" "${members[@]}"
# #
mkfs.btrfs --force \ mkfs.btrfs --force \
--checksum 'sha256' \ --checksum 'sha256' \
--label 'boot' \ --label 'boot' \
--uuid '00000000-0000-0000-0000-00000000000b' \ --uuid '00000000-0000-0000-0000-00000000000b' \
'/dev/md/boot' '/dev/md/boot'
# mount boot # mount boot
mkdir --parents '/media/boot' mkdir --parents '/media/boot'
mount \ mount \
--options 'autodefrag,compress-force=zstd' \ --options 'autodefrag,compress-force=zstd' \
'/dev/md/boot' '/media/boot' '/dev/md/boot' '/media/boot'
# #
number=0 number=0
for device in "${devices[@]}" ; do for device in "${devices[@]}"; do
((number++)) ((number++))
echo ; echo "#${number}: ${device}1" echo
echo "#${number}: ${device}1"
# wipe crypt head # wipe crypt head
dd status='progress' \ dd status='progress' \
if='/dev/zero' of="${device}1" bs='1G' count=1 if='/dev/zero' of="${device}1" bs='1G' count=1
done done
# #
members=() members=()
for device in "${devices[@]}" ; do for device in "${devices[@]}"; do
members+=("${device}1") members+=("${device}1")
done done
mdadm \ mdadm \
--create '/dev/md/crypt' \ --create '/dev/md/crypt' \
--level 0 \ --level 0 \
--metadata 1 \ --metadata 1 \
--name 'md:crypt' \ --name 'md:crypt' \
--raid-devices ${#devices[@]} \ --raid-devices ${#devices[@]} \
--uuid '00000000:00000000:00000000:00000001' \ --uuid '00000000:00000000:00000000:00000001' \
"${members[@]}" "${members[@]}"
# encrypt # encrypt
echo "${passphrase}" \ echo "${passphrase}" |
| cryptsetup \ cryptsetup \
--verbose \ --verbose \
--batch-mode \ --batch-mode \
--type 'luks2' \ --type 'luks2' \
--pbkdf 'argon2id' \ --pbkdf 'argon2id' \
--cipher 'aes-xts-plain64' \ --cipher 'aes-xts-plain64' \
--iter-time 8192 \ --iter-time 8192 \
--key-size 512 \ --key-size 512 \
--hash 'sha512' \ --hash 'sha512' \
--use-random \ --use-random \
luksFormat \ luksFormat \
'/dev/md/crypt' '/dev/md/crypt'
# open # open
echo "${passphrase}" \ echo "${passphrase}" |
| cryptsetup luksOpen '/dev/md/crypt' 'crypt' cryptsetup luksOpen '/dev/md/crypt' 'crypt'
} }
rescue_hetzner_wipe_8_8_1_zero() { rescue_hetzner_wipe_8_8_1_zero() {
# wipe crypt # wipe crypt
dd status='progress' \ dd status='progress' \
if='/dev/zero' of='/dev/mapper/crypt' bs='8G' if='/dev/zero' of='/dev/mapper/crypt' bs='8G'
} }
rescue_hetzner_wipe_8_8_2_make() { rescue_hetzner_wipe_8_8_2_make() {
@ -284,43 +295,43 @@ rescue_hetzner_wipe_8_8_2_make() {
echo -n 'PassPhrase: ' echo -n 'PassPhrase: '
read -r -s passphrase read -r -s passphrase
# encrypt # encrypt
echo "${passphrase}" \ echo "${passphrase}" |
| cryptsetup \ cryptsetup \
--verbose \ --verbose \
--batch-mode \ --batch-mode \
--type 'luks2' \ --type 'luks2' \
--pbkdf 'argon2id' \ --pbkdf 'argon2id' \
--cipher 'aes-xts-plain64' \ --cipher 'aes-xts-plain64' \
--iter-time 8192 \ --iter-time 8192 \
--key-size 512 \ --key-size 512 \
--hash 'sha512' \ --hash 'sha512' \
--use-random \ --use-random \
luksFormat \ luksFormat \
'/dev/md/crypt' '/dev/md/crypt'
# open # open
echo "${passphrase}" \ echo "${passphrase}" |
| cryptsetup luksOpen '/dev/md/crypt' 'crypt' cryptsetup luksOpen '/dev/md/crypt' 'crypt'
# format crypt # format crypt
mkfs.btrfs --force \ mkfs.btrfs --force \
--checksum 'sha256' \ --checksum 'sha256' \
--label 'crypt' \ --label 'crypt' \
--uuid '00000000-0000-0000-0000-00000000000c' \ --uuid '00000000-0000-0000-0000-00000000000c' \
'/dev/mapper/crypt' '/dev/mapper/crypt'
# mount crypt # mount crypt
mkdir --parents '/media/crypt' mkdir --parents '/media/crypt'
mount \ mount \
--options 'autodefrag,compress-force=zstd' \ --options 'autodefrag,compress-force=zstd' \
'/dev/mapper/crypt' '/media/crypt' '/dev/mapper/crypt' '/media/crypt'
# make swap file # make swap file
btrfs filesystem mkswapfile \ btrfs filesystem mkswapfile \
--size '64g' \ --size '64g' \
--uuid '00000000-0000-0000-0000-000000000005' \ --uuid '00000000-0000-0000-0000-000000000005' \
'/media/crypt/swap' '/media/crypt/swap'
} }
rescue_hetzner_wipe_8_8_3_close() { rescue_hetzner_wipe_8_8_3_close() {
umount '/media/boot' umount '/media/boot'
# #
umount '/media/crypt' \ umount '/media/crypt' &&
&& cryptsetup luksClose 'crypt' cryptsetup luksClose 'crypt'
} }