tos/installation/install

176 lines
5.1 KiB
Bash
Executable file

#!/bin/bash
# ================= #
# === UTILITIES === #
# ================= #
error() {
echo "Error:" "$1"
exit
}
# ==================== #
# === SYSTEM CHECK === #
# ==================== #
system_check() {
echo "Check if booted in uefi mode..."
ls /sys/firmware/efi/efivars > /dev/null || error "The system is not booted in UEFI mode"
}
# ======================= #
# === PREPARE INSTALL === #
# ======================= #
prepare_install() {
echo "Update mirror list..."
reflector --country France --protocol https --sort rate --save /etc/pacman.d/mirrorlist
echo "Install dependencies..."
pacman -Sy --noconfirm dialog
}
# ======================== #
# === ASK INFORMATIONS === #
# ======================== #
ask_infos() {
# Disk selection
disks=$(lsblk --raw --noheadings --output TYPE,PATH,SIZE | grep disk | cut -d " " -f 2-)
disk=$(dialog --nocancel --stdout --menu "Instalation Disk" 0 0 0 $disks)
[ "$disk" == "" ] && error "No disk chosen"
# Settings from nano
nano settings
. ./settings
}
# ================== #
# === SETUP DISK === #
# ================== #
setup_disk() {
echo "Create disk partitions..."
printf ",512M,U\n,,V\n" | sfdisk --wipe always --label gpt $disk
echo "Get partitions name..."
efi_part=$(lsblk $disk --raw --noheadings --output TYPE,PATH,SIZE | grep part | cut -d " " -f 2 | head -n 1)
lvm_part=$(lsblk $disk --raw --noheadings --output TYPE,PATH,SIZE | grep part | cut -d " " -f 2 | tail -n 1)
echo "Encrypt lvm partition..."
echo -n "$password" | cryptsetup luksFormat "$lvm_part" -
echo -n "$password" | cryptsetup luksOpen "$lvm_part" crypt-lvm
echo "Load disk settings..."
swap_size=$(free --giga | awk '/Mem/{print $2}' | sed "s;$;G;")
echo " Swap size:" "$swap_size"
echo "Create lvm volumes..."
pvcreate /dev/mapper/crypt-lvm
vgcreate system /dev/mapper/crypt-lvm
lvcreate -L "$root_size" system -n root
lvcreate -L "$home_size" system -n home
lvcreate -L "$swap_size" system -n swap
echo "Format volumes and uefi..."
mkfs.ext4 /dev/system/root
mkfs.ext4 /dev/system/home
mkswap /dev/system/swap
mkfs.fat -F32 "$efi_part"
echo "Mount volumes and uefi..."
mount /dev/system/root /mnt
mount --mkdir /dev/system/home /mnt/home
swapon /dev/system/swap
mount --mkdir "$efi_part" /mnt/boot
}
# ====================== #
# === INSTALL SYSTEM === #
# ====================== #
install_system() {
echo "Add tos repository..."
echo "[tos]" >> /etc/pacman.conf
echo "SigLevel = Optional TrustAll" >> /etc/pacman.conf
echo "Server = https://git.tipragot.fr/tipragot/tos/-/raw/main/repository" >> /etc/pacman.conf
echo "Install arch linux..."
pacstrap -K /mnt tos-desktop "tos-drivers-${drivers}"
echo "Generate fstab..."
genfstab -U /mnt >> /mnt/etc/fstab
echo "Enable Network Manager..."
arch-chroot /mnt systemctl enable NetworkManager
}
# ===================== #
# === USER SETTINGS === #
# ===================== #
user_settings() {
echo "Update hostname..."
echo "$hostname" > /mnt/etc/hostname
printf "127.0.0.1 localhost\n::1 localhost\n127.0.1.1 %s\n" "$hostname"
echo "Update timezone..."
arch-chroot /mnt ln -sf "/usr/share/zoneinfo/$timezone" /etc/localtime
arch-chroot /mnt hwclock --systohc
echo "Update language..."
sed -i "s;#${language}.UTF-8 UTF-8;${language}.UTF-8 UTF-8;" /mnt/etc/locale.gen
echo "LANG=${language}.UTF-8" >> /mnt/etc/locale.conf
arch-chroot /mnt locale-gen
echo "Update keymap..."
echo "KEYMAP=$keymap" >> /mnt/etc/vconsole.conf
}
define_users() {
# Enable sudo
arch-chroot /mnt groupadd sudo
sed -i "s;# %sudo\tALL=(ALL:ALL) ALL;%sudo ALL=(ALL:ALL) ALL;" /mnt/etc/sudoers
# Create user
arch-chroot /mnt groupadd -r autologin
arch-chroot /mnt useradd -m -G sudo,autologin me
# Set passwords
arch-chroot /mnt bash -c "printf '%s\n%s\n' '$password' '$password' | passwd root"
arch-chroot /mnt bash -c "printf '%s\n%s\n' '$password' '$password' | passwd me"
}
# =================== #
# === SYSTEM BOOT === #
# =================== #
system_boot() {
echo "Update mkinitcpio..."
sed -i "s;^HOOKS=.*;HOOKS=(base udev autodetect keyboard keymap modconf block encrypt lvm2 filesystems fsck);" /mnt/etc/mkinitcpio.conf
arch-chroot /mnt mkinitcpio -p linux
echo "Change grub settings..."
sed -i "s;GRUB_TIMEOUT=.*;GRUB_TIMEOUT=0;" /mnt/etc/default/grub
sed -i "s;GRUB_CMDLINE_LINUX=.*;GRUB_CMDLINE_LINUX=\"cryptdevice=$lvm_part:crypt-lvm\";" /mnt/etc/default/grub
sed -i "s;#GRUB_ENABLE_CRYPTODISK=.*;GRUB_ENABLE_CRYPTODISK=y;" /mnt/etc/default/grub
sed -i "s;GRUB_TIMEOUT_STYLE=.*;GRUB_TIMEOUT_STYLE=hidden;" /mnt/etc/default/grub
arch-chroot /mnt grub-install --efi-directory=/boot "$efi_part"
arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
}
# ===================== #
# === INSTALL STEPS === #
# ===================== #
set -e
system_check
prepare_install
ask_infos
setup_disk
install_system
user_settings
define_users
system_boot