# - bof - #

#!/bin/bash

Opt_=$1;



<<'comment'
# -  - #
# - File name - #
Ermanno_Btrfs-Arch.sh

cd ~/; rm -rf ~/Ermanno_Btrfs-Arch.sh; vim ~/Ermanno_Btrfs-Arch.sh;
copy & paste this content
chmod +x ~/Ermanno_Btrfs-Arch.sh; ~/./Ermanno_Btrfs-Arch.sh;

cd ~/.ssh;
ssh-keygen -t rsa;

# -  - #
# - Fixing ssh error - #
ssh-keygen -R "you server hostname or ip"
ssh-keygen -R 10.0.0.1
ssh-keygen -R 192.168.1.1;
comment



currentD_=($PWD);


iMac_='Yes';
iMac_='No';

HPLaptop_='Yes';
HPLaptop_='No';

HPDesktop_='Yes';
HPDesktop_='No';

uServerIP_isdevelopmentUS_='www.isdevelopment.us';
gateway4_isdevelopmentUS_='192.168.1.1';

uServerIP_uSVManager='192.168.1.101';
gateway4_uSVManager='192.168.1.1';

uServerIP_uSProxmox='192.168.1.100';
gateway4_uSProxmox='192.168.1.1';


ViManager_='Yes';
VEProxmox_='No';
RealMetal_='No';
WebServer_='No';


if [ "$ViManager_" == "Yes" ]; then
   uServerIP_=$uServerIP_uSVManager;
   gateway4_=$gateway4_uSVManager;
elif [ "$VEProxmox_" == "Yes" ]; then
   uServerIP_=$uServerIP_uSProxmox;
   gateway4_=$gateway4_uSProxmox;
elif [ "$WebServer_" == "Yes" ]; then
   uServerIP_=$uServerIP_isdevelopmentUS_;
   gateway4_=$gateway4_isdevelopmentUS_;
elif [ "$RealMetal_" == "Yes" ]; then
   uServerIP_=$uServerIP_isdevelopmentUS_;
   gateway4_=$gateway4_isdevelopmentUS_;
fi;


 hostName_='ArchBtrfs';
#hostName_='HPDesktopArch';


Addresses_='8.8.8.8, 8.8.4.4';
swapG_='2G';
swapName_='swap.img';

User_='luigi';
User_='is_derayo';

adminUser_=$User_;

if [ "$User_" == "is_derayo" ]; then
   adminName_="Djalmar Enrique Rayo";
   rootPasswd_='Administrator2';
elif [ "$User_" == "luigi" ]; then
   adminName_='Luigi Guarnieri';
   rootPasswd_='dispata06041940';
fi;

adminPasswd_=$rootPasswd_;


 createDiskConfirmation_='No';
 createDiskConfirmation_='Yes';

if [ "$hostName_" == "HPLaptopArch" ] || [ "$hostName_" == "HPDesktopArch" ]; then
   createDiskConfirmation_="No"; fi;

 system_='BIOS';
 system_='UEFI';

 Btrfs_='Yes';
#Btrfs_='No';

# ( BIOS diskType_=1, UEFI diskType_=2 )
if [ "$system_" == "BIOS" ]; then diskType_=1; else diskType_=2; fi;

 OS_Prober_='Yes';
#OS_Prober_='No';



# -  - #
# - createDisk_Bios_ - #
function createDisk_Bios_(){
  local Disk_='' Disk1_='' Disk2_='' \
        d1_='sda' d2_='vda' d3_='';

  if [ "$iMac_" == "Yes" ]; then d1_='sdb'; fi;
  if [ "$HPLaptop_" == "Yes" ]; then d1_='nvme0n1'; fi;
  
  d3_=$(lsblk | grep -oF "$d1_"" ");   # look for sda
  # - Is d3_ empty ? - #
  if [ "$d3_" == "" ]; then
    d3_=$(lsblk | grep -oF "$d2_"" ");
    if [ "$d3_" == "" ]; then
      echo 'There is not disk present to format...';
      return;
    else
      Disk_=$d2_;
    fi;
  else
    Disk_=$d1_;
  fi;

  if [ "$HPLaptop_" == "Yes" ]; then
    Disk1_=$Disk_'p1';
    Disk2_=$Disk_'p2';
  else
    Disk1_=$Disk_'1';
    Disk2_=$Disk_'2';
  fi;

<<'comment'
  # -  - #
  # - Format HDD - #

  fdisk /dev/vda;
  o  # DOS Partition Table
  n  # New
  p  # Primary
  1  # Default
  83 # Linux
  w  # Write changes to disk

  fdisk -l /dev/vda;
  Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 sectors

  Device     Boot    Start       End   Sectors Size Id Type
  /dev/vda1           2048  62916607  62914560  30G 83 Linux
  /dev/vda2       62916608 209715199 146798592  70G 83 Linux

  lsblk -f
  NAME   FSTYPE  FSVER            LABEL       UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
  sr0    iso9660 Joliet Extension ARCH_202202 2022-02-01-17-06-09-00                              
  vda                                                                                             
  ├─vda1 ext4    1.0              Arch        6ff0e382-26a7-42c4-b27d-d1c8866f63f3   15.6G    42% /
  └─vda2 ext4    1.0              Data        ea1d7285-8570-48a9-839f-19bb0017b55c  
comment

#sudo wipefs -a -f /dev/$Disk_
#sudo wipefs -o 0x1fe /dev/$Disk_;

(
echo o    # New empty DOS partition table
echo n    # New partition
echo p    # Primary partition
echo 1    # Partition number
echo      # First sector (default: 1)
echo +30G # Arch partition
echo n    # Add a new partition
echo p    # Primary partition
echo 2    # Partition number
echo      # First sector (default: 1)
echo      # Last sector (default, rest of partition Data) 
echo w    # Write changes
) | sudo fdisk /dev/$Disk_;

(echo Y) | sudo mkfs.ext4 -L Arch /dev/$Disk1_;
(echo Y) | sudo mkfs.ext4 -L Data /dev/$Disk2_;

  echo "";
  echo 'BIOS partition table created,';
  echo 'Disk was formated...';
  sleep 10;
}



# -  - #
# - createDisk_UEFI_ - #
function createDisk_UEFI_(){
  local Disk_='' Disk1_='' Disk2_='' Disk3_='' Disk4_='' \
        d1_='sda' d2_='vda' d3_='' d4_='';

  if [ "$iMac_" == "Yes" ]; then d1_='sdb'; fi;
  if [ "$HPLaptop_" == "Yes" ]; then d1_='nvme0n1'; fi;

  d3_=$(lsblk | grep -oF "$d1_"" ");   # look for sda
  # - Is d3_ empty ? - #
  if [ "$d3_" == "" ]; then
    d3_=$(lsblk | grep -oF "$d2_"" ");
    if [ "$d3_" == "" ]; then
      echo 'There is not disk present to format...';
      return;
    else
      Disk_=$d2_;
    fi;
  else
    Disk_=$d1_;
  fi;

  if [ "$HPLaptop_" == "Yes" ]; then
    Disk1_=$Disk_'p1';
    Disk2_=$Disk_'p2';
    Disk3_=$Disk_'p3';
  else
    Disk1_=$Disk_'1';
    Disk2_=$Disk_'2';
    Disk3_=$Disk_'3';
    Disk4_=$Disk_'4';
  fi;

<<'comment'
  # -  - #
  # - Format HDD - #

  if [ "$d3_" != "" ]; then Disk_=$d2_; fi;
  if [ $(lsblk -f | grep -oF  "$Disk1_") = $Disk1_ ] && \
     [ $(lsblk -f | grep -oF  "$Disk2_") = $Disk2_ ] && \
     [ $(lsblk -f | grep -oF  "$Disk3_") = $Disk3_ ]; then echo $Disk1_" "$Disk2_" "$Disk3_; fi;

  gdisk -l /dev/vda;

  vda
  ├─vda1 vfat     FAT32            EFI BOOT    0548-C74E
  ├─vda2 swap     1                Swap         c7335240-6db1-4a89-89ce-428b77ce5c0b
  ├─vda3 btrfs                     Arch        a4011d58-cede-4059-afa0-00aaf0891d55
  └─vda4 btrfs                     Data        2f14e979-a386-44ab-93fb-78ac932fd8a0


  gdisk /dev/vda;
  o                 # GPT Partition Table
  n                 # New
  Y                 # Yes
  t                 # Type
  ef00              # EFI system partition +640M
  
  8300              # Linux filesystem       30G
  8300              # Linux filesystem      rest

  w                 # Write changes to disk

  gdisk -l /dev/vda;

  GPT fdisk (gdisk) version 1.0.8

  Partition table scan:
    MBR: protective
    BSD: not present
    APM: not present
    GPT: present

  Found valid GPT with protective MBR; using GPT.
  Disk /dev/vda: 209715200 sectors, 100.0 GiB

  Number  Start (sector)    End (sector)  Size       Code  Name
     1            2048         1312767   640.0 MiB   EF00  EFI system partition
     2         1312768        64227327   30.0 GiB    8300  Linux filesystem
     3        64227328       209715166   69.4 GiB    8300  Linux filesystem

  lsblk -f
  NAME   FSTYPE  FSVER            LABEL       UUID                                 
  sr0    iso9660 Joliet Extension ARCH_202202 2022-02-01-17-06-09-00              
  vda  
  ├─vda1 vfat    FAT32            EFI BOOT    70E-7DA8
  ├─vda2 ext4    1.0              Arch        6ff0e382-26a7-42c4-b27d-d1c8866f63f3
  └─vda3 ext4    1.0              Data        ea1d7285-8570-48a9-839f-19bb0017b55c



(
echo d     # Delete partition
echo 3     # Number
echo Y     # Yes
echo w     # Write changes
echo Y     # Yes
) | sudo gdisk /dev/vda;

(
echo d     # Delete partition
echo 2     # Number
echo Y     # Yes
echo w     # Write changes
echo Y     # Yes
) | sudo gdisk /dev/vda;

(
echo d     # Delete partition
echo 1     # Number
echo Y     # Yes
echo w     # Write changes
echo Y     # Yes
) | sudo gdisk /dev/vda;

sudo wipefs -a -f /dev/vda;
sudo wipefs -a -f /dev/$Disk_;
sudo wipefs -o 0x1fe /dev/$Disk_;
comment


#sudo wipefs -a -f /dev/$Disk_;

(
echo o     # New empty GPT partition table
echo Y     # Yes
echo n     # New partition
echo 1     # Partition number
echo       # First sector (default: 1)
echo +640M # Arch partition
echo ef00  # EFI system partition
echo n     # New partition
echo 2     # Partition number
echo       # First sector (default: 1)
echo +4G   # Swap
echo 8200  # Linux swap
echo n     # New partition
echo 3     # Partition number
echo       # First sector (default: 1)
echo +35G  # Arch
echo 8300  # Linux filesystem
echo n     # Add a new partition
echo 4     # Data
echo       # First sector (default: 1)
echo       # Last sector (default, rest of partition Data) 
echo 8300  # Linux filesystem
echo w     # Write changes
echo Y     # Write changes
) | sudo gdisk /dev/$Disk_;

#EFI System Partition - EFI Boot
#sudo mkfs.vfat -n BOOT /dev/vda1;
 sudo mkfs.vfat -n BOOT /dev/$Disk1_;

#Swap partition
#sudo mkswap -L Swap /dev/vda2;
(echo Y) | sudo mkswap -L Swap /dev/$Disk2_;

#Arch Btrfs partition
#sudo mkfs.btrfs -L Arch /dev/vda3;
(echo Y) | sudo mkfs.btrfs -L Arch /dev/$Disk3_;

#Data Btrfs partition
#sudo mkfs.btrfs -L Data /dev/vda4;
(echo Y) | sudo mkfs.btrfs -L Data /dev/$Disk4_;

<<'comment'
  mkswap -L Swap /dev/vda2;
  swapon /dev/vda2;
  swapoff /dev/vda2;
comment

  echo "";
  echo 'UEFI partition table created,';
  echo 'Disk was formated...';
  sleep 10;
}



<<'comment'
(
echo o     # New empty GPT partition table
echo Y     # Yes
echo w     # Write changes
echo Y     # Yes
) | sudo gdisk /dev/sda;
sudo reboot now;

(
echo o     # New empty GPT partition table
echo Y     # Yes
echo w     # Write changes
echo Y     # Yes
) | sudo gdisk /dev/vda;
sudo reboot now;
comment



# -  - #
# - diskLabels_ 1 $Disk1_ $Disk2_ $Disk3_ - #
function diskLabels_(){
  local systemType_=$1 $Disk1_=$2 $Disk2_=$3 $Disk3_=$4;

  case $systemType_ in
    ''|*[!0-9]*)
      echo '';
      echo 'Its not a number...';
      ;;
    1)
      if [ $(lsblk -f | grep -oF  "$Disk1_") = $Disk1_ ] && \
         [ $(lsblk -f | grep -oF  "$Disk2_") = $Disk2_ ]; then return; fi;

      sudo e2label /dev/$Disk1_ Arch;
      sudo e2label /dev/$Disk2_ Data;
      ;;
    2)
      if [ $(lsblk -f | grep -oF  "$Disk1_") = $Disk1_ ] && \
         [ $(lsblk -f | grep -oF  "$Disk2_") = $Disk2_ ] && \
         [ $(lsblk -f | grep -oF  "$Disk3_") = $Disk3_ ] && \
         [ $(lsblk -f | grep -oF  "$Disk4_") = $Disk4_ ]; then return; fi;

      sudo dosfslabel /dev/$Disk1_ BOOT;
      sudo swaplabel --label Swap /dev/$Disk2_;
      sudo e2label /dev/$Disk3_ Arch;
      sudo e2label /dev/$Disk4_ Data;
      ;;
    *)
      echo "Option no valid: " $Opt_;
      ;;
  esac
}



# -  - #
# - createDisk_ 1 - #
function createDisk_(){
  local Disk_=$1;
  case $Disk_ in
    ''|*[!0-9]*)
      echo '';
      echo 'Its not a number...';
      ;;
    1)
      createDisk_Bios_;
      ;;
    2)
      createDisk_UEFI_;
      ;;
    *)
      echo "Option no valid: " $Opt_;
      ;;
  esac
  
  echo "";
  lsblk -f;
  echo "";
  echo "10 seconds pause (disk structure)...";
  sleep 10;
}



# -  - #
# - ArchBase1_ - #
function ArchBase1_(){
local Disk_='' \
      Disk1_='' Disk2_='' Disk3_='' Disk4_='' \
      d1_='sda' d2_='vda' d3_='';

  if [ "$iMac_" == "Yes" ]; then d1_='sdb'; fi;
  if [ "$HPLaptop_" == "Yes" ]; then d1_='nvme0n1'; fi;

  d3_=$(lsblk | grep -oF "$d1_"" ");   # vda/sda/sdb/nvme0n1p "lsblk -f" line
  if [ "$d3_" == "" ]; then
    d3_=$(lsblk | grep -oF "$d2_"" ");
    if [ "$d3_" == "" ]; then
      echo 'There is not disk present for this installation...';
      exit;
    else
      Disk_=$d2_;
    fi;
  else
    Disk_=$d1_;
  fi;

  if [ "$HPLaptop_" == "Yes" ]; then
    Disk1_=$Disk_'p1';
    Disk2_=$Disk_'p2';
    Disk3_=$Disk_'p3';
  else
    Disk1_=$Disk_'1';
    Disk2_=$Disk_'2';
    Disk3_=$Disk_'3';
    Disk4_=$Disk_'4';
  fi;

  # -  - #
  # - Timezone - #
  timedatectl set-ntp true;
  timedatectl set-timezone America/New_York;
  timedatectl status;


<<'comment'
  # -  - #
  # - BTRFS Requirements - #
  vda
  ├─vda1 vfat     FAT32            EFI BOOT    0548-C74E
  ├─vda2 swap     1                Swap         c7335240-6db1-4a89-89ce-428b77ce5c0b
  ├─vda3 btrfs                     Arch        a4011d58-cede-4059-afa0-00aaf0891d55
  └─vda4 btrfs                     Data        2f14e979-a386-44ab-93fb-78ac932fd8a0
comment


  # -  - #
  # - Mount partitions & Create subvolumes - #
  # swapon /dev/vda2;
  # mount /dev/vda3 /mnt;

  # -  - #
  # - Mount sda/vda - #
  if [ "$system_" == "BIOS" ]; then
    diskLabels_ 1 $Disk1_ $Disk2_;
    mount /dev/$Disk1_ /mnt;
  elif [ "$system_" == "UEFI" ]; then
    diskLabels_ 2 $Disk1_ $Disk2_ $Disk3_ $Disk4_;
    swapon /dev/$Disk2_; 
    mount /dev/$Disk3_ /mnt;
    mkdir -p /mnt/boot/efi;
    mount /dev/$Disk1_ /mnt/boot/efi;
  fi;

  echo "";
  if [ "$createDiskConfirmation_" == "No" ]; then
     echo "";
     echo "Mounts as shown...";
     lsblk -f;
     echo "";
     echo "";
     sleep 15;
  fi;


  echo "";
  echo "Swap memory mounted...";
  free -h;
  echo "";
  sleep 15;


  # -  - #
  # - 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 noatime,compress=lzo,space_cache=v2,subvol=@ /dev/vda3 /mnt;
  mkdir -p /mnt/{boot,home,var,.snapshots};
  mount -o noatime,compress=lzo,space_cache=v2,subvol=@home /dev/vda3 /mnt/home;
  mount -o noatime,compress=lzo,space_cache=v2,subvol=@var /dev/vda3 /mnt/var;
  mount -o noatime,compress=lzo,space_cache=v2,subvol=@.snapshots /dev/vda3 /mnt/.snapshots;

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

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


  # -  - #
  # - Mount Data subvolume - #
  mount -o noatime,compress=lzo,space_cache=v2,subvol=@Data /dev/vda4 /mnt/Data;

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

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


  # -  - #
  # - 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  networkmanager-openvpn \
                openssh samba snapper sudo sshfs tilix vim wpa_supplicant;



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

  # -  - #
  # - Copy script /mnt - #
  cp Ermanno_Btrfs-Arch.sh /mnt;
  arch-chroot /mnt ./Ermanno_Btrfs-Arch.sh 2 $Disk_;
}



# -  - #
# - ArchBase2_ - #
function ArchBase2_(){
  local Disk_=$2 \
        hostnameF_=/etc/hostname \
        hostsF_=/etc/hosts;

  # -  - #
  # - Set localtime - #
  ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime;

  # -  - #
  # - Set hardware clock - #
  hwclock --systohc;

  # -  - #
  # - generate locate - #
  sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen;
  locale-gen;

  # -  - #
  # - Set language - #
  echo "LANG=en_US.UTF-8" >> /etc/locale.conf;

  # -  - #
  # - Set keyboard layout - #
  echo "KEYMAP=us" >> /etc/vconsole.conf;

  # -  - #
  # - Set hostname - #
  rm -rf $hostnameF_;
  echo $hostName_ >> $hostnameF_;
  hostnamectl set-hostname $hostName_;

  # -  - #
  # - Set local ip address - #
  rm -rf $hostsF_;
  echo "127.0.0.1 localhost" > $hostsF_;
  echo "::1       localhost" >> $hostsF_;
  echo '127.0.1.1 '$hostName_'.localdomain '$hostName_ >> $hostsF_;



  # -  - #
  # - Hardware software - #

  # -  - #
  # - All video cards (generics) - #
  if [ "$HPLaptop_" == "No" ]; then
     pacman -S xf86-video-vesa xf86-video-ati xf86-video-intel xf86-video-amdgpu \
               xf86-video-nouveau --noconfirm --needed; fi;

  # -  - #
  # - Intel, AMD & nvidia - #
  if [ "$iMac_" == "No" ] && [ "$HPLaptop_" == "No" ]; then
     pacman -S intel-ucode amd-ucode nvidia nvidia-utils --noconfirm --needed; fi;

  # - Intel & nVidia- #
  if [ "$HPLaptop_" == "Yes" ]; then
     pacman -S intel-ucode nvidia nvidia-utils --noconfirm --needed; fi;
     # amd-ucode

  # -  - #
  # - Utilitary software - #
  pacman -S acpi acpi_call alsa-utils dnsutils inetutils powertop reflector \
            tlp xdg-utils xdg-user-dirs --noconfirm --needed;
  pacman -S bluez bluez-utils wireless_tools --noconfirm --needed;



  # -  - #
  if [ "$system_" == "UEFI" ]; then
     pacman -S efibootmgr dosfstools mtools --noconfirm --needed; fi;

  # -  - #
  # - Double boot activation - #
  if [ "$OS_Prober_" == "Yes" ]; then
     pacman -S os-prober --noconfirm --needed;
     os-prober;
     sed -i 's/#GRUB_DISABLE_OS_PROBER=false/GRUB_DISABLE_OS_PROBER=false/' /etc/default/grub;
  fi;
 


  # -  - #
  # - Install grub - #

  # - Prepare grub Btrfs configuration - #
  sed -i 's/MODULES=()/MODULES=(btrfs)/' /etc/mkinitcpio.conf;
  mkinitcpio -p linux;

  if [ "$system_" == "BIOS" ]; then
     grub-install /dev/$Disk_;
  elif [ "$system_" == "UEFI" ]; then
     grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB --recheck;
  fi;
  echo "";
  echo "15 seconds pause (grub-installed)...";
  sleep 15;

  # -  - #
  # - Create grub.cfg file - #
  grub-mkconfig -o /boot/grub/grub.cfg;
  echo "";
  echo "15 seconds pause (grub-mkconfig configured)...";
  sleep 15;



  # -  - #
  # - Root password & create new user & password - #

  # -  - #
  echo "";
  echo "Creating root password...";
  #echo 'root:'$rootPasswd_ | sudo chpasswd;
  echo 'root:'$rootPasswd_ | chpasswd;  
  sleep 10;

  echo "";
  echo "Authorizing root user full ssh access...";
  sshdConf_=/etc/ssh/sshd_config;  
  #sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' $sshdConf_;
  #sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' $sshdConf_;
  sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' $sshdConf_;
  sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' $sshdConf_;
  sleep 10;

  # -  - #
  echo "";
  echo "Creating admin user...";
  useradd -m $adminUser_;
  usermod -aG audio,optical,storage,video,wheel $adminUser_;
  usermod -c "$adminName_" $adminUser_; 
  #echo $adminUser_':'$adminPasswd_ | sudo chpasswd;
  echo $adminUser_':'$adminPasswd_ | chpasswd;
  sleep 10;

<<comment
  # -  - #
  echo "";
  echo "Creating guest user...";
  useradd -m $GuestUser_;
  usermod -aG audio,optical,storage,video,wheel $GuestUser_;
  usermod -c "$GuestName_" $GuestUser_; 
  #echo $GuestUser_':'$GuestPasswd_ | sudo chpasswd;
  echo $GuestUser_':'$GuestPasswd_ | chpasswd;
  sleep 10;
comment

  # -  - #
  # - Authorize wheel to sudo - #
  sed -i 's/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers;


  # -  - #
  # - Printer - #
  pacman -S cups cups-pdf hplip libcups system-config-printer --noconfirm --needed;
  systemctl enable cups;


  # -  - #
  # - Additional software - #

  # -  - #
  # - Programs - #
  sudo pacman -S audacious bash-completion bleachbit bpytop curl dolphin evince filelight file-roller \
                 filezilla firefox gcc geeqie gimp gnome-disk-utility gnome-calculator gnome-multi-writer \
                 gnome-packagekit gnome-terminal gnome-system-monitor gpart gparted gpicview grub-customizer \
                 gvfs htop kpat libreoffice man mate-icon-theme-faenza mysql-clients neofetch nmap ntfs-3g pavucontrol \
                 pinta plank poppler-glib postgresql pv pydf python p7zip reflector rsync screenfetch simple-scan smplayer \
                 spectacle testdisk thunar transmission-gtk tree unrar unzip viewnior vlc whois wget \
                 yajl --noconfirm --needed;



  # -  - #
  # - Picture viewer programs - #
  pacman -S gpicview viewnior --noconfirm --needed;

  # -  - #
  # - Media utilities - #
  pacman -S brasero clementine xfburn --noconfirm --needed;

  # -  - #
  # - To install yay & yaourt - #
  pacman -S binutils fakeroot make --noconfirm --needed;

  # -  - #
  # - Arch themes - #
  pacman -S adapta-gtk-theme arc-gtk-theme arc-icon-theme archlinux-wallpaper gtkmm3 \
            papirus-icon-theme ttf-freefont --noconfirm --needed;



  # -  - #
  # - Enable ssh & NetworkManager - #
  systemctl enable sshd;
  systemctl enable NetworkManager;
  #systemctl enable systemd-resolved.service;

  #systemctl enable systemd-networkd;
  #systemctl start systemd-networkd;


  if [ "$HPLaptop_" == "Yes" ]; then 
    NetworkFile_;
    NetworkConfiguration_;
  fi;


  rm -rf /Ermanno_Btrfs-Arch.sh;

  # -  - #
  # - Exit & reboot - #
  echo '';
  printf "\e[1;32mDone! Type umount -a and shutdown now.\e[0m";
  echo '';

}



<<'comment'
  case $MAX in
    ''|*[!0-9]*)
      echo "The value $MAX is not a number !"
      exit 1
      ;;
    *)
      if [ $MAX -lt 50 ] || [ $MAX -gt 100 ] ;then
        echo "The value $MAX is not between 50-100"
        exit 1
      fi
      echo "Looks like we are good !"
      ;;
comment



# -  - #
# - checkComputer_ - #
function checkComputer_(){
  clear;
  echo "";
  echo 'Checking computer...';
  if [ "$hostName_" == "HPLaptopArch" ] || [ "$hostName_" == "HPDesktopArch" ]; then
     echo "";
     echo "This process cannot be executed on $hostName_...";
     spd-say -w "This process cannot be executed on $hostName_";
     rm -rf ~/Ermanno_Btrfs-Arch.sh;
     echo "";
     exit;
  fi;
  echo "";
}



# -  - #
# - Network file - #
function NetworkFile_(){
	local networkF_=/home/is_derayo/20-wired.network;

cat <<EOT>> $networkF_;
# -  - #
# - Network file - #
# - sudo vim /etc/systemd/network/20-wired.network; - #

# - Documentation - #
# https://www.youtube.com/watch?v=iedzVZlAbqI
# -  - #

[Match]
Name=enp0s20f0u1c2

[Network]
DHCP=yes

EOT

}



# -  - #
# - Network configuration - #
function NetworkConfiguration_(){
	local configF_=/home/is_derayo/NetworkConfiguration.sh \
	      networkF_1=/home/is_derayo/20-wired.network \
	      networkF_2=/etc/systemd/network/20-wired.network;

# -  - #
# - Configuration file - #

cat <<EOT>> $configF_;
#!/bin/bash

# -  - #
# - Configured - #
# - vim ~/NetworkConfiguration.sh - #

# - Documentation - #
# https://www.youtube.com/watch?v=iedzVZlAbqI
# -  - #

clear;

#sudo ip link set dev wlo1 up;
sudo ip link set dev enp0s20f0u1c2 up;

#sudo wpa_passphrase IS_Network_5G-1 Administrator22@ > /etc/wifi.conf;
sudo cat /etc/wifi.conf;

sudo wpa_supplicant -B -i wlo1 -D wext -c /etc/wifi.conf;

sudo systemctl enable systemd-networkd;
sudo systemctl start systemd-networkd;

sudo systemctl enable systemd-resolved;
sudo systemctl start systemd-resolved;



sudo ip link set dev wlo1 up;
sudo ip link set dev enp0s20f0u1c2 up;

sudo dhcpcd enp0s20f0u1c2;

sudo systemctl restart systemd-networkd;
sudo systemctl restart systemd-resolved;

sudo nmcli dev wifi connect IS_Network_5G-1 password "Administrator22@"

sudo shutdown now;

EOT



  chown is_derayo:is_derayo $configF_;
  chmod 775 $configF_;



  # -  - #
  # - Set wlan0 up - #
  ip link set dev wlo1 up;
  ip link set dev enp0s20f0u1c2 up;
  
  # -  - #
  # - Generate configuration of wireless connection - #
  wpa_passphrase IS_Network_5G-1 Administrator22@ > /etc/wifi.conf;

  # -  - #
  # - Connect to the wifi network - #
  wpa_supplicant -B -i wlo1 -D wext -c /etc/wifi.conf;

  systemctl enable systemd-networkd;
  systemctl start systemd-networkd;
  
  systemctl enable systemd-resolved;
  systemctl start systemd-resolved;

  mv $networkF_1 $networkF_2;
  sudo dhcpcd enp0s20f0u1c2;

  systemctl restart systemd-networkd;
  systemctl restart systemd-resolved;
  
  sleep 5
}





case $Opt_ in
  ''|*[!0-9]*)

    checkComputer_;
    
    if [ "$createDiskConfirmation_" == "Yes" ]; then
       createDisk_ $diskType_; fi;
    ArchBase1_;
    umount -a;
    echo '';
    echo 'Arch installation is done...';
    read -t 5 -p 'System will shutdown now.';
    echo '';
    shutdown now;
    ;;
  2)
    ArchBase2_ $1 $2;
    ;;
  *)
    echo "Option no valid: " $Opt_;
    ;;
esac



<<'comment'
Very important:
Make the boot BIOS for a BIOS installation.
Make the boot UEFI for a UEFI installation.


cd ~/; rm -rf ~/Ermanno_Btrfs-Arch.sh; vim ~/Ermanno_Btrfs-Arch.sh;
copy & paste this content
chmod +x ~/Ermanno_Btrfs-Arch.sh; ~/./Ermanno_Btrfs-Arch.sh;

ssh-keygen -R 192.168.1.1
~/./Ermanno_Btrfs-Arch.sh;
comment



# - eof - #
