tabs
This commit is contained in:
parent
783d5e334e
commit
bf1e7539fa
1 changed files with 282 additions and 282 deletions
|
@ -1,13 +1,13 @@
|
||||||
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 "\
|
||||||
Acquire::AllowInsecureRepositories False;
|
Acquire::AllowInsecureRepositories False;
|
||||||
Acquire::AllowWeakRepositories False;
|
Acquire::AllowWeakRepositories False;
|
||||||
Acquire::AllowDowngradeToInsecureRepositories False;
|
Acquire::AllowDowngradeToInsecureRepositories False;
|
||||||
|
@ -18,309 +18,309 @@ 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
|
||||||
# host name
|
# host name
|
||||||
hostname "${hostname}"
|
hostname "${hostname}"
|
||||||
# locales
|
# locales
|
||||||
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
|
||||||
apt-get update
|
apt-get update
|
||||||
#
|
#
|
||||||
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
|
||||||
apt-get update
|
apt-get update
|
||||||
}
|
}
|
||||||
|
|
||||||
rescue_hetzner_install() {
|
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=(
|
||||||
)
|
)
|
||||||
# update catalog
|
# update catalog
|
||||||
apt-get update
|
apt-get update
|
||||||
#
|
#
|
||||||
debian_disable_frontend
|
debian_disable_frontend
|
||||||
# upgrade packages
|
# upgrade packages
|
||||||
apt-get upgrade --assume-yes
|
apt-get upgrade --assume-yes
|
||||||
#
|
#
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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}"
|
||||||
# remove fingerprints
|
# remove fingerprints
|
||||||
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
|
||||||
# TODO variable
|
# TODO variable
|
||||||
ssh "${user_host}" -- "source '/etc/bash/main.sh' ; rescue_hetzner_configure '${hostname}'"
|
ssh "${user_host}" -- "source '/etc/bash/main.sh' ; rescue_hetzner_configure '${hostname}'"
|
||||||
# create session
|
# create session
|
||||||
ssh "${user_host}" -- byobu new-session -d
|
ssh "${user_host}" -- byobu new-session -d
|
||||||
# send keys
|
# send keys
|
||||||
ssh "${user_host}" -- byobu send-keys 'rescue_hetzner_install' 'C-m'
|
ssh "${user_host}" -- byobu send-keys 'rescue_hetzner_install' 'C-m'
|
||||||
# attach session
|
# attach session
|
||||||
mosh "${user_host}" -- byobu attach-session
|
mosh "${user_host}" -- byobu attach-session
|
||||||
else
|
else
|
||||||
echo 'Host?'
|
echo 'Host?'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
rescue_hetzner_wipe_8_8_0_init() {
|
rescue_hetzner_wipe_8_8_0_init() {
|
||||||
local device
|
local device
|
||||||
local devices=(
|
local devices=(
|
||||||
'/dev/sda'
|
'/dev/sda'
|
||||||
'/dev/sdb'
|
'/dev/sdb'
|
||||||
)
|
)
|
||||||
local members
|
local members
|
||||||
local number
|
local number
|
||||||
local passphrase
|
local passphrase
|
||||||
local unit='mib'
|
local unit='mib'
|
||||||
# read passphrase
|
# read passphrase
|
||||||
echo -n 'PassPhrase: '
|
echo -n 'PassPhrase: '
|
||||||
read -r -s passphrase
|
read -r -s passphrase
|
||||||
#
|
#
|
||||||
lsblk
|
lsblk
|
||||||
echo -n 'WIPE' "${devices[@]}" '/?\ OR CANCEL /!\'
|
echo -n 'WIPE' "${devices[@]}" '/?\ OR CANCEL /!\'
|
||||||
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}" unit "${unit}" \
|
||||||
mkpart "crypt-${number}" 33282 7630885
|
mkpart "crypt-${number}" 33282 7630885
|
||||||
#
|
#
|
||||||
parted "${device}" unit "${unit}" \
|
parted "${device}" unit "${unit}" \
|
||||||
mkpart "boot-${number}" 514 33282
|
mkpart "boot-${number}" 514 33282
|
||||||
#
|
#
|
||||||
parted "${device}" unit "${unit}" \
|
parted "${device}" unit "${unit}" \
|
||||||
mkpart "esp-${number}" 2 514
|
mkpart "esp-${number}" 2 514
|
||||||
parted "${device}" set 3 esp on
|
parted "${device}" set 3 esp on
|
||||||
#
|
#
|
||||||
parted "${device}" unit "${unit}" \
|
parted "${device}" unit "${unit}" \
|
||||||
mkpart "bios-${number}" 1 2
|
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() {
|
||||||
local passphrase
|
local passphrase
|
||||||
# close
|
# close
|
||||||
cryptsetup luksClose 'crypt'
|
cryptsetup luksClose 'crypt'
|
||||||
# read passphrase
|
# read passphrase
|
||||||
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'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue