# - bof - #

#!/bin/bash



<<'comment'

# -  - #
# - Name - #
general_Functions.sh

# -  - #
# - Location - #
/DataPool/Images/Programs/Linux.Img/Linux_Arch.Img/Arch_Install/KarlaS_Arch.Ins/bash_funcions_

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

curl -O http://192.168.1.200/Programs/Linux.Img/Linux_Arch.Img/Arch_Install/KarlaS_Arch.Ins/bash_functions_/general_Functions.sh;
chmod +x ~/general_Functions.sh; ~/./general_Functions.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;

# -  - #
Documentation:
https://superuser.com/questions/332252/how-to-create-and-format-a-partition-using-a-bash-script

comment



# -  - #
# - sample_ - #
function sample_(){
  local pacmanF_=/etc/pacman.conf \
        sSed_='ParallelDownloads = 5' \
        candy_='ILoveCandy';
  local msg_0='Configuring '$pacmanF_' ...' \
        msg_1=$pacmanF_' already configured...' \
        sS1_='' sS2_='' sS3_='' sS4_='';
        
  echo '';

}



# BAT / CMD goto function
function goto
{
    label=$1
    cmd=$(sed -n "/^:[[:blank:]][[:blank:]]*${label}/{:a;n;p;ba};" $0 | 
          grep -v ':$')
    eval "$cmd"
    exit
}



# -  - #
# - gotoSample_ - #
function gotoSample_(){

  #apt update
  echo 'Hello...'
  
  # Just for the heck of it: how to create a variable where to jump to:
  #start=${1:-"start"}
  goto "$start"

: start
  goto_msg="Starting..."
  echo $goto_msg
  # Just jump to the label:
  goto "continue"

: skipped
  goto_msg="This is skipped!"
  echo $goto_msg

: continue
  goto_msg="Ended..."
  echo "$goto_msg"

  # following doesn't jump to apt update whereas original does
  goto update
}



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

  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

  Disk1_=$Disk_'1';
  Disk2_=$Disk_'2'
    
<<'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

(
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 +10G # 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_;

mkfs.ext4 -L Arch /dev/$Disk1_;
mkfs.ext4 -L Data /dev/$Disk2_;

echo 'Bios partition table created,';
echo 'Disk was formated...';

}



# -  - #
# - createDisk_ - #
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
}




createDisk_ 1

#gotoSample_




<<'comment'
ssh-keygen -R 192.168.122.100;
curl -O http://192.168.1.200/Programs/Linux.Img/Linux_Arch.Img/Arch_Install/KarlaS_Arch.Ins/bash_functions_/general_Functions.sh;
chmod +x ~/general_Functions.sh; ~/./general_Functions.sh;
comment



# - eof - #
