#!/bin/bash
# - bof - #



<<'comment'

xdg-user-dirs-update;
sudo apt install duf curl git neovim -y;
bash <(curl -s https://www.education.isdevelopment.us/Arch.Ins/Software.Ins/BashFiles.Ins/DataFoldersConfiguration.sh)



# - Configured - #

sudo pacman -S eza --noconfirm --needed;
sudo apt install eza -y;



cd ~/;
curl -o ~/sDF_.sh "https://www.education.isdevelopment.us/Arch.Ins/Software.Ins/BashFiles.Ins/DataFoldersConfiguration.sh"
chmod +x ~/sDF_.sh; ~/./sDF_.sh;

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



# -  - #
# - Vim commands - #
https://vim.rtorr.com/

rm -rf ~/.bashrc;
nvim ~/.bashrc;

rm -rf ~/.zshrc;
nvim ~/.zshrc;

ssh-keygen -R 192.168.1.1

# - On client - #
cd ~/.ssh;
ssh-keygen -t rsa;

cat ~/.ssh/id_rsa.pub;

# - On server - #
nvim ~/.ssh/authorized_keys;

sudo apt install curl git htop inxi net-tools ntp neovim screenfetch tree -y;
sudo pacman -S curl git htop inxi net-tools ntp neovim screenfetch tree --noconfirm --needed;

sS1_=$(echo $(lsblk -f | grep $sD_) | awk '{print $2;}');
if [ "$sS1_" == "btrfs" ]; then echo $sS1_; else echo "ext4"; fi;
comment



clear;

nD_=1;
sBtrfs_='btrfs'
sData_='Data';
sDB_='DataBtrfs';
sDP_='DataPool';
sUd_=~/.config/user-dirs.dirs;
sConf_='# - Configured - #';
sFs_=/etc/fstab;

sDc_=/Documents;
hDc_=~/Documents;

sDw_=/Downloads;
hDw_=~/Downloads;

sM_=/Music;
hM_=~/Music;

sP_=/Pictures;
hP_=~/Pictures;

sV_=/Videos;
hV_=~/Videos;

sTsfa_=/ToShare-FullAccess;
sTsjr_=/ToShare-JustRead;



# -  - #
# - Return partition - #
function lookData_(){
  # -  - #
  # - Check for DataPool - #
  if [[ $( which zfsutils-linux ) == "" ]]; then
    # -  - #
    # - Check for DataBtrfs - #
    sS1_=$( echo $( lsblk -fp | grep $sDB_ ) | awk '{print $3;}' );
    if [[ $sS1_ != "" ]]; then
      sS1_=$( echo $( sudo btrfs subvolume list /$sDB_ | grep @$sDB_ ) | awk '{print $9;}' );
      if [[ $sS1_ == "@DataBtrfs" ]]; then
        # -  - #
        # - Send DataBtrfs - #
        echo $sDB_;
      else
        # -  - #
        # - Send ext4 Data - #
        echo $sData_;
      fi;
    else
      echo $sData_;
    fi;
  else
    # -  - #
    # - Send DataPool - #
    echo $sDP_;
  fi;
}



# -  - #
# - DocumentsFolders_ - #
function DocumentsFolders_(){
  local sU_=$USER \
        sD_=/"$1";

  # -  - #
  # - Configure Data folders - #
  
  if [[ ! -d "$sD_" ]]; then
    sudo mkdir $sD_; fi;

  sudo chown -R $sU_:$sU_ $sD_;
  chmod -R 775 $sD_;

  # -  - #
  # - Create Documents folders - #
  mkdir -p $sD_$sDc_ $sD_$sDc_$sDw_ $sD_$sDc_$sM_ $sD_$sDc_$sP_ $sD_$sDc_$sV_;

  # -  - #
  # - Remove original Documents & links - #
  sudo rm -rf $hDc_ $hDw_ $hM_ $hP_ $hV_;

  # -  - #
  # - Create new Documents links - #
  ln -s $sD_$sDc_ $hDc_;
  ln -s $sD_$sDc_$sDw_ $hDw_;
  ln -s $sD_$sDc_$sM_ $hM_;
  ln -s $sD_$sDc_$sP_ $hP_;
  ln -s $sD_$sDc_$sV_ $hV_;

  # -  - #
  # - Create samba folders - #
  mkdir -p $sD_$sDc_$sTsfa_ $sD_$sDc_$sTsjr_;

  # -  - #
  # - Make public samba folders - #
  chmod 777 $sD_$sDc_$sTsfa_;
  chmod 777 $sD_$sDc_$sTsjr_;
}



# -  - #
# - uDirDir_ - #
function uDirDir_(){
  local sD_=/$1;

  # -  - #
  # - Redirect $USER folders - #
  echo -e "\nDeleting $sUd_ file...";
  mkdir -p ~/.config;
  rm -rf $sUd_;

  echo -e "\nCreating new $sUd_ file..."

cat <<EOT >> $sUd_;

# -  - #
$sConf_
# - vim ~/.config/user-dirs.dirs - #
# -  - #

XDG_DOCUMENTS_DIR="$sD_$sDc_"
XDG_DOWNLOAD_DIR="$sD_$sDc_$sDw_"
XDG_MUSIC_DIR="$sD_$sDc_$sM_"
XDG_PICTURES_DIR="$sD_$sDc_$sP_"
XDG_VIDEOS_DIR="$sD_$sDc_$sV_"

EOT

sed -i '7 i XDG_DESKTOP_DIR="$HOME/Desktop"' $sUd_;
sed -i '8 i XDG_TEMPLATES_DIR="$HOME/Templates"' $sUd_;
sed -i '9 i XDG_PUBLICSHARE_DIR="$HOME/Public"' $sUd_;
}



if [[ -f "$sUd_" ]]; then
  if [[ $( cat $sUd_ | grep "$sConf_" ) != "" ]]; then
    echo -e "\n\n$sUd_ is already configured...\n\n\n"; sleep 10; exit 0; fi;
fi;



echo -e "\nConfiguring Data directories...";

dPartition_=$(lookData_);
#echo $dPartition_;
DocumentsFolders_ $dPartition_; 

if [[ "$nD_" == "1" ]]; then
  uDirDir_ $dPartition_; fi; 



rm -rf ~/sDF_.sh;

if [[ "$nD_" == "1" ]]; then
  echo -e "\n$sUd_ has been configured successfully...\n";
else
  echo -e "\nThis process has been aborted...\n";
fi;



# - eof - #