#!/bin/bash

# - bof - #

# -  - #
# - Documentation - #
# - https://www.nishantnadkarni.tech/posts/arch_installation/ - #



# -  - #
# - scp command - #
# scp is_derayo@192.168.1.100:/DataPool/Images/Programs/Linux.Img/Linux_Arch.Img/Arch_Install/Ermanno_Arch.Ins/ArchBase1_Ermanno_Btrfs_BareMetal.sh .;



# -  - #
# - When this error happen on ssh command - #
#
#  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#  @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
#  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#
#  # -  - #
#  # - Fixing this error - #
#  ssh-keygen -R "you server hostname or ip"
#  ssh-keygen -R 192.168.1.100;
#  ssh-keygen -R 192.168.1.200;
#  ssh-keygen -R 192.168.122.100;
#  ssh-keygen -R 192.168.122.200;



#:1
# -  - #
# - Initial configuration - #
timedatectl set-ntp true;
timedatectl set-timezone America/New_York;

# -  - #
# - BTRFS Requirements - #
#sda                                                                                              
#├─sda1 vfat     FAT32            EFI BOOT    170E-7DA8                                           
#├─sda2 swap     1                Swap        e5f92681-9039-4f26-8835-c9679772e372                
#├─sda3 btrfs                     Arch        e72d8f75-70ea-46bd-95ca-18b0b1c80eac                
#└─sda4 btrfs                     Data        883b5d02-46f8-4117-adba-bf5617685a66                



#:1.1
# -  - #
# - Mount partitions & Create subvolumes - #
swapon /dev/sda2;
mount /dev/sda3 /mnt;

# -  - #
# - Create subvolumes - #
btrfs subvolume create /mnt/@;
btrfs subvolume create /mnt/@home;
btrfs subvolume create /mnt/@var;
btrfs subvolume create /mnt/@.snapshots;
umount /mnt;

# -  - #
# - Mount subvolumes - #
mount -o ssd,noatime,nodiratime,compress=lzo,space_cache=v2,discard=async,subvol=@ /dev/sda3 /mnt;
mkdir -p /mnt/{boot,home,var,.snapshots};
mount -o ssd,noatime,nodiratime,compress=lzo,space_cache=v2,discard=async,subvol=@home /dev/sda3 /mnt/home;
mount -o ssd,noatime,nodiratime,compress=lzo,space_cache=v2,discard=async,subvol=@var /dev/sda3 /mnt/var;
mount -o ssd,noatime,nodiratime,compress=lzo,space_cache=v2,discard=async,subvol=@.snapshots /dev/sda3 /mnt/.snapshots;

# - commit: Periodic interval (second) data is synchronized to permanent storage - #
#mount -o noatime,commit=120,compress=lzo,space_cache=v2,subvol=@ /dev/sda3 /mnt;

# -  - #
# - Create Data subvolume - #
mkdir -p /mnt/Data;
mount /dev/sda4 /mnt/Data;
btrfs subvolume create /mnt/Data/@Data;
umount /mnt/Data;

# -  - #
# - Mount Data subvolume - #
mount -o ssd,noatime,nodiratime,compress=lzo,space_cache=v2,discard=async,subvol=@Data /dev/sda4 /mnt/Data;

# -  - #
# - Efi mount (Arch alone install) - #
mount /dev/sda1 /mnt/boot;

echo " ";
read -t 5 -p "Partitions processed.";
echo "5 Seconds pause...";


#:1.3
# -  - #
# - Install linux base - #
pacstrap /mnt base base-devel btrfs-progs dhcpcd dialog gedit git grub grub-btrfs linux linux-headers \
              linux-firmware mesa nano net-tools netctl networkmanager network-manager-applet openssh \
              samba snapper sudo sshfs tilix vim wpa_supplicant;



#:1.4
# -  - #
# - Generate fstab file - #
genfstab -U /mnt >> /mnt/etc/fstab;



#:1.5
# -  - #
# - Get into the new ArchLinux (login as root) - #
arch-chroot /mnt;



# - eof - #
