Pretty print.

This commit is contained in:
Tommaso Chiti 2021-10-31 08:42:25 +01:00
parent 61617beb60
commit e522bc1090

View file

@ -3,7 +3,12 @@
# Cleaning the TTY. # Cleaning the TTY.
clear clear
# Selecting a kernel to install. # Pretty print (function).
print () {
echo -e "\e[1m\e[93m[ \e[92m•\e[93m ] \e[4m$1\e[0m"
}
# Selecting a kernel to install (function).
kernel_selector () { kernel_selector () {
echo "List of kernels:" echo "List of kernels:"
echo "1) Stable — Vanilla Linux kernel and modules, with a few patches applied." echo "1) Stable — Vanilla Linux kernel and modules, with a few patches applied."
@ -26,7 +31,7 @@ kernel_selector () {
esac esac
} }
# Selecting a way to handle internet connection. # Selecting a way to handle internet connection (function).
network_selector () { network_selector () {
echo "Network utilities:" echo "Network utilities:"
echo "1) IWD — iNet wireless daemon is a wireless daemon for Linux written by Intel (WiFi-only)." echo "1) IWD — iNet wireless daemon is a wireless daemon for Linux written by Intel (WiFi-only)."
@ -73,7 +78,7 @@ PS3="Select the disk where Arch Linux is going to be installed: "
select ENTRY in $(lsblk -dpnoNAME|grep -P "/dev/sd|nvme|vd"); select ENTRY in $(lsblk -dpnoNAME|grep -P "/dev/sd|nvme|vd");
do do
DISK=$ENTRY DISK=$ENTRY
echo "Installing Arch Linux on $DISK." print "Installing Arch Linux on $DISK."
break break
done done
@ -85,12 +90,12 @@ then
wipefs -af "$DISK" &>/dev/null wipefs -af "$DISK" &>/dev/null
sgdisk -Zo "$DISK" &>/dev/null sgdisk -Zo "$DISK" &>/dev/null
else else
echo "Quitting." print "Quitting."
exit exit
fi fi
# Creating a new partition scheme. # Creating a new partition scheme.
echo "Creating new partition scheme on $DISK." print "Creating new partition scheme on $DISK."
parted -s "$DISK" \ parted -s "$DISK" \
mklabel gpt \ mklabel gpt \
mkpart ESP fat32 1MiB 513MiB \ mkpart ESP fat32 1MiB 513MiB \
@ -101,27 +106,27 @@ ESP="/dev/disk/by-partlabel/ESP"
Cryptroot="/dev/disk/by-partlabel/Cryptroot" Cryptroot="/dev/disk/by-partlabel/Cryptroot"
# Informing the Kernel of the changes. # Informing the Kernel of the changes.
echo "Informing the Kernel about the disk changes." print "Informing the Kernel about the disk changes."
partprobe "$DISK" partprobe "$DISK"
# Formatting the ESP as FAT32. # Formatting the ESP as FAT32.
echo "Formatting the EFI Partition as FAT32." print "Formatting the EFI Partition as FAT32."
mkfs.fat -F 32 $ESP &>/dev/null mkfs.fat -F 32 $ESP &>/dev/null
# Creating a LUKS Container for the root partition. # Creating a LUKS Container for the root partition.
echo "Creating LUKS Container for the root partition" print "Creating LUKS Container for the root partition"
cryptsetup luksFormat $Cryptroot cryptsetup luksFormat $Cryptroot
echo "Opening the newly created LUKS Container." print "Opening the newly created LUKS Container."
cryptsetup open $Cryptroot cryptroot cryptsetup open $Cryptroot cryptroot
BTRFS="/dev/mapper/cryptroot" BTRFS="/dev/mapper/cryptroot"
# Formatting the LUKS Container as BTRFS. # Formatting the LUKS Container as BTRFS.
echo "Formatting the LUKS container as BTRFS." print "Formatting the LUKS container as BTRFS."
mkfs.btrfs $BTRFS &>/dev/null mkfs.btrfs $BTRFS &>/dev/null
mount $BTRFS /mnt mount $BTRFS /mnt
# Creating BTRFS subvolumes. # Creating BTRFS subvolumes.
echo "Creating BTRFS subvolumes." print "Creating BTRFS subvolumes."
btrfs su cr /mnt/@ &>/dev/null btrfs su cr /mnt/@ &>/dev/null
btrfs su cr /mnt/@home &>/dev/null btrfs su cr /mnt/@home &>/dev/null
btrfs su cr /mnt/@snapshots &>/dev/null btrfs su cr /mnt/@snapshots &>/dev/null
@ -129,7 +134,7 @@ btrfs su cr /mnt/@var_log &>/dev/null
# Mounting the newly created subvolumes. # Mounting the newly created subvolumes.
umount /mnt umount /mnt
echo "Mounting the newly created subvolumes." print "Mounting the newly created subvolumes."
mount -o ssd,noatime,space_cache,compress=zstd,subvol=@ $BTRFS /mnt mount -o ssd,noatime,space_cache,compress=zstd,subvol=@ $BTRFS /mnt
mkdir -p /mnt/{home,.snapshots,/var/log,boot} mkdir -p /mnt/{home,.snapshots,/var/log,boot}
mount -o ssd,noatime,space_cache=v2,compress=zstd,discard=async,subvol=@home $BTRFS /mnt/home mount -o ssd,noatime,space_cache=v2,compress=zstd,discard=async,subvol=@home $BTRFS /mnt/home
@ -141,13 +146,13 @@ mount $ESP /mnt/boot/
kernel_selector kernel_selector
# Pacstrap (setting up a base sytem onto the new root). # Pacstrap (setting up a base sytem onto the new root).
echo "Installing the base system (it may take a while)." print "Installing the base system (it may take a while)."
pacstrap /mnt base $kernel $microcode linux-firmware btrfs-progs grub grub-btrfs efibootmgr snapper reflector base-devel snap-pac zram-generator pacstrap /mnt base $kernel $microcode linux-firmware btrfs-progs grub grub-btrfs efibootmgr snapper reflector base-devel snap-pac zram-generator
network_selector network_selector
# Generating /etc/fstab. # Generating /etc/fstab.
echo "Generating a new fstab." print "Generating a new fstab."
genfstab -U /mnt >> /mnt/etc/fstab genfstab -U /mnt >> /mnt/etc/fstab
# Setting hostname. # Setting hostname.
@ -167,7 +172,7 @@ read -r -p "Please insert the keyboard layout you use: " kblayout
echo "KEYMAP=$kblayout" > /mnt/etc/vconsole.conf echo "KEYMAP=$kblayout" > /mnt/etc/vconsole.conf
# Setting hosts file. # Setting hosts file.
echo "Setting hosts file." print "Setting hosts file."
cat > /mnt/etc/hosts <<EOF cat > /mnt/etc/hosts <<EOF
127.0.0.1 localhost 127.0.0.1 localhost
::1 localhost ::1 localhost
@ -175,10 +180,11 @@ cat > /mnt/etc/hosts <<EOF
EOF EOF
# Configuring /etc/mkinitcpio.conf. # Configuring /etc/mkinitcpio.conf.
echo "Configuring /etc/mkinitcpio.conf for LUKS hook." print "Configuring /etc/mkinitcpio.conf for LUKS hook."
sed -i -e 's,modconf block filesystems keyboard,keyboard keymap modconf block encrypt filesystems,g' /mnt/etc/mkinitcpio.conf sed -i -e 's,modconf block filesystems keyboard,keyboard keymap modconf block encrypt filesystems,g' /mnt/etc/mkinitcpio.conf
# Setting up LUKS2 encryption and apparmor. # Setting up LUKS2 encryption in grub.
print "Setting up grub config."
UUID=$(blkid $Cryptroot | cut -f2 -d'"') UUID=$(blkid $Cryptroot | cut -f2 -d'"')
sed -i "s,quiet,quiet cryptdevice=UUID=$UUID:cryptroot root=$BTRFS,g" /mnt/etc/default/grub sed -i "s,quiet,quiet cryptdevice=UUID=$UUID:cryptroot root=$BTRFS,g" /mnt/etc/default/grub
@ -190,12 +196,15 @@ arch-chroot /mnt /bin/bash -e <<EOF
# Setting up clock. # Setting up clock.
hwclock --systohc hwclock --systohc
# Generating locales. # Generating locales.
echo "Generating locales." echo "Generating locales."
locale-gen &>/dev/null locale-gen &>/dev/null
# Generating a new initramfs. # Generating a new initramfs.
echo "Creating a new initramfs." echo "Creating a new initramfs."
mkinitcpio -P &>/dev/null mkinitcpio -P &>/dev/null
# Snapper configuration # Snapper configuration
umount /.snapshots umount /.snapshots
rm -r /.snapshots rm -r /.snapshots
@ -204,6 +213,7 @@ arch-chroot /mnt /bin/bash -e <<EOF
mkdir /.snapshots mkdir /.snapshots
mount -a mount -a
chmod 750 /.snapshots chmod 750 /.snapshots
# Installing GRUB. # Installing GRUB.
echo "Installing GRUB on /boot." echo "Installing GRUB on /boot."
grub-install --target=x86_64-efi --efi-directory=/boot/ --bootloader-id=GRUB &>/dev/null grub-install --target=x86_64-efi --efi-directory=/boot/ --bootloader-id=GRUB &>/dev/null
@ -211,6 +221,7 @@ arch-chroot /mnt /bin/bash -e <<EOF
# Creating grub config file. # Creating grub config file.
echo "Creating GRUB config file." echo "Creating GRUB config file."
grub-mkconfig -o /boot/grub/grub.cfg &>/dev/null grub-mkconfig -o /boot/grub/grub.cfg &>/dev/null
# Adding user with sudo privilege # Adding user with sudo privilege
if [ -n "$username" ]; then if [ -n "$username" ]; then
echo "Adding $username with root privilege." echo "Adding $username with root privilege."
@ -218,34 +229,35 @@ arch-chroot /mnt /bin/bash -e <<EOF
usermod -aG wheel $username usermod -aG wheel $username
echo "$username ALL=(ALL) ALL" >> /etc/sudoers.d/$username echo "$username ALL=(ALL) ALL" >> /etc/sudoers.d/$username
fi fi
EOF EOF
# Setting root password. # Setting root password.
echo "Setting root password." print "Setting root password."
arch-chroot /mnt /bin/passwd arch-chroot /mnt /bin/passwd
[ -n "$username" ] && echo "Setting user password for ${username}." && arch-chroot /mnt /bin/passwd "$username" [ -n "$username" ] && echo "Setting user password for ${username}." && arch-chroot /mnt /bin/passwd "$username"
# Enabling Reflector timer. # Enabling Reflector timer.
echo "Enabling Reflector." print "Enabling Reflector."
systemctl enable reflector.timer --root=/mnt &>/dev/null systemctl enable reflector.timer --root=/mnt &>/dev/null
# Enabling Snapper automatic snapshots. # Enabling Snapper automatic snapshots.
echo "Enabling Snapper and automatic snapshots entries." print "Enabling Snapper and automatic snapshots entries."
systemctl enable snapper-timeline.timer --root=/mnt &>/dev/null systemctl enable snapper-timeline.timer --root=/mnt &>/dev/null
systemctl enable snapper-cleanup.timer --root=/mnt &>/dev/null systemctl enable snapper-cleanup.timer --root=/mnt &>/dev/null
systemctl enable grub-btrfs.path --root=/mnt &>/dev/null systemctl enable grub-btrfs.path --root=/mnt &>/dev/null
# Enabling systemd-oomd. # Enabling systemd-oomd.
echo "Enabling systemd-oomd." print "Enabling systemd-oomd."
systemctl enable systemd-oomd --root=/mnt &>/dev/null systemctl enable systemd-oomd --root=/mnt &>/dev/null
# ZRAM configuration # ZRAM configuration.
bash -c 'cat > /mnt/etc/systemd/zram-generator.conf' <<-'EOF' cat > /mnt/etc/systemd/zram-generator.conf <<EOF
[zram0] [zram0]
zram-fraction = 1 zram-fraction = 1
max-zram-size = 8192 max-zram-size = 8192
EOF EOF
# Finishing up # Finishing up.
echo "Done, you may now wish to reboot (further changes can be done by chrooting into /mnt)." print "Done, you may now wish to reboot (further changes can be done by chrooting into /mnt)."
exit exit