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,5 +1,5 @@
rescue_hetzner_configure() {
local hostname="${1}"
local hostname="${1}"
local package
local packages=(
'mosh'
@ -17,14 +17,14 @@ APT::Install-Suggests False;
APT::Get::Show-Versions True;
Dir::Etc::SourceParts '';
Dpkg::Progress True;
" > '/etc/apt/apt.conf'
" >'/etc/apt/apt.conf'
# apt / sources
echo -n "\
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-updates 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
main_link_bashrc
mv .bashrc .bashrc.old
@ -34,7 +34,7 @@ deb https://deb.debian.org/debian-security bookworm-security main non-free-firmw
echo -n "\
en_US.UTF-8 UTF-8
fr_FR.UTF-8 UTF-8
" > '/etc/locale.gen'
" >'/etc/locale.gen'
# generate locales
locale-gen
# update catalog
@ -42,8 +42,9 @@ fr_FR.UTF-8 UTF-8
#
debian_disable_frontend
# install packages
for package in "${packages[@]}" ; do
echo ; echo "${package}"
for package in "${packages[@]}"; do
echo
echo "${package}"
apt-get install \
--assume-yes \
"${package}"
@ -82,16 +83,18 @@ rescue_hetzner_install() {
#
apt_clean_cache
# install packages
for package in "${packages[@]}" ; do
echo ; echo "${package}"
for package in "${packages[@]}"; do
echo
echo "${package}"
apt-get install \
--assume-yes \
"${package}"
apt_clean_cache
done
# install backports
for package in "${backports[@]}" ; do
echo ; echo "${package}"
for package in "${backports[@]}"; do
echo
echo "${package}"
apt-get install \
--assume-yes \
--target-release "${release}-backports" \
@ -103,7 +106,7 @@ rescue_hetzner_install() {
rescue_hetzner_upload() {
local host="${1}"
local hostname="${2}"
if [ "${hostname}" ] ; then
if [ "${hostname}" ]; then
local user='root'
#
local user_host="${user}@${host}"
@ -149,40 +152,46 @@ rescue_hetzner_wipe_8_8_0_init() {
read
#
number=0
for device in "${devices[@]}" ; do
for device in "${devices[@]}"; do
((number++))
echo ; echo "#${number}: ${device}"
echo
echo "#${number}: ${device}"
#
parted "${device}" --script mktable gpt
parted "${device}" --script \
mktable gpt
#
parted "${device}" unit "${unit}" \
mkpart "crypt-${number}" 33282 7630885
parted "${device}" \
unit "${unit}" mkpart "crypt-${number}" 33282 7630885
#
parted "${device}" unit "${unit}" \
mkpart "boot-${number}" 514 33282
parted "${device}" \
unit "${unit}" mkpart "boot-${number}" 514 33282
#
parted "${device}" unit "${unit}" \
mkpart "esp-${number}" 2 514
parted "${device}" set 3 esp on
parted "${device}" \
unit "${unit}" mkpart "esp-${number}" 2 514
parted "${device}" \
set 3 esp on
#
parted "${device}" unit "${unit}" \
mkpart "bios-${number}" 1 2
parted "${device}" set 4 bios_grub on
parted "${device}" \
unit "${unit}" mkpart "bios-${number}" 1 2
parted "${device}" \
set 4 bios_grub on
done
#
number=0
for device in "${devices[@]}" ; do
for device in "${devices[@]}"; do
((number++))
echo ; echo "#${number}: ${device}4"
echo
echo "#${number}: ${device}4"
# wipe bios
dd \
if='/dev/zero' of="${device}4"
done
#
number=0
for device in "${devices[@]}" ; do
for device in "${devices[@]}"; do
((number++))
echo ; echo "#${number}: ${device}3"
echo
echo "#${number}: ${device}3"
# format esp
dd \
if='/dev/zero' of="${device}3" bs='1M'
@ -198,16 +207,17 @@ rescue_hetzner_wipe_8_8_0_init() {
done
#
number=0
for device in "${devices[@]}" ; do
for device in "${devices[@]}"; do
((number++))
echo ; echo "#${number}: ${device}2"
echo
echo "#${number}: ${device}2"
# wipe boot
dd status='progress' \
if='/dev/zero' of="${device}2" bs='1G' count=1
done
#
members=()
for device in "${devices[@]}" ; do
for device in "${devices[@]}"; do
members+=("${device}2")
done
mdadm \
@ -231,16 +241,17 @@ rescue_hetzner_wipe_8_8_0_init() {
'/dev/md/boot' '/media/boot'
#
number=0
for device in "${devices[@]}" ; do
for device in "${devices[@]}"; do
((number++))
echo ; echo "#${number}: ${device}1"
echo
echo "#${number}: ${device}1"
# wipe crypt head
dd status='progress' \
if='/dev/zero' of="${device}1" bs='1G' count=1
done
#
members=()
for device in "${devices[@]}" ; do
for device in "${devices[@]}"; do
members+=("${device}1")
done
mdadm \
@ -252,8 +263,8 @@ rescue_hetzner_wipe_8_8_0_init() {
--uuid '00000000:00000000:00000000:00000001' \
"${members[@]}"
# encrypt
echo "${passphrase}" \
| cryptsetup \
echo "${passphrase}" |
cryptsetup \
--verbose \
--batch-mode \
--type 'luks2' \
@ -266,8 +277,8 @@ rescue_hetzner_wipe_8_8_0_init() {
luksFormat \
'/dev/md/crypt'
# open
echo "${passphrase}" \
| cryptsetup luksOpen '/dev/md/crypt' 'crypt'
echo "${passphrase}" |
cryptsetup luksOpen '/dev/md/crypt' 'crypt'
}
rescue_hetzner_wipe_8_8_1_zero() {
@ -284,8 +295,8 @@ rescue_hetzner_wipe_8_8_2_make() {
echo -n 'PassPhrase: '
read -r -s passphrase
# encrypt
echo "${passphrase}" \
| cryptsetup \
echo "${passphrase}" |
cryptsetup \
--verbose \
--batch-mode \
--type 'luks2' \
@ -298,8 +309,8 @@ rescue_hetzner_wipe_8_8_2_make() {
luksFormat \
'/dev/md/crypt'
# open
echo "${passphrase}" \
| cryptsetup luksOpen '/dev/md/crypt' 'crypt'
echo "${passphrase}" |
cryptsetup luksOpen '/dev/md/crypt' 'crypt'
# format crypt
mkfs.btrfs --force \
--checksum 'sha256' \
@ -321,6 +332,6 @@ rescue_hetzner_wipe_8_8_2_make() {
rescue_hetzner_wipe_8_8_3_close() {
umount '/media/boot'
#
umount '/media/crypt' \
&& cryptsetup luksClose 'crypt'
umount '/media/crypt' &&
cryptsetup luksClose 'crypt'
}