#!/bin/bash
# - bof - #



# -  - #
# - Overwrite checkComputer - #
 overwriteCc_="No";
#overwriteCc_="Yes";



system_=$([ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS" );
hostName_=$(uname -n);
xDi_=~/Arch_Xfce-Desktop-Install.sh;
#xIns_="$HOME/Xfce-Install.sh"


<<'comment'

sudo pacman -S curl --noconfirm --needed;
bash <(curl -s https://www.education.isdevelopment.us/Arch.Ins/03-Arch_Xfce-Desktop-Install.sh)



# :A
# -  - #
# - Arch Xfce desktop installation script - #

# - Method   # 1 - #
sh -c "$(curl -fsSL 'https://www.education.isdevelopment.us/Arch.Ins/03-Arch_Xfce-Desktop-Install.sh')"

# - Method   # 2 - #
cd ~/;
xdI_=Arch_Xfce-Desktop-Install.sh;
curl -o ~/$xdI_ "https://www.education.isdevelopment.us/Arch.Ins/03-$xdI_"
nvim ~/$xdI_;
chmod +x ~/$xdI_; ~/./$xdI_;

# - Method   # 3 - #
cd ~/; rm -rf ~/Arch_Xfce-Desktop-Install.sh; nvim ~/Arch_Xfce-Desktop-Install.sh;
Copy & paste all this content
chmod +x ~/Arch_Xfce-Desktop-Install.sh; ~/./Arch_Xfce-Desktop-Install.sh;



# - Configured - #

# -  - #
# - 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 tree -y;
sudo pacman -S curl git htop inxi net-tools ntp neovim tree --noconfirm --needed;
comment



# -  - #
# - Greetings_ - #
function Greetings_(){
  Header_;
  echo -e "\n  Warning: This script is going to install the Xfce-Desktop environment"
  echo -e "\nImportant: This procedure will take a few minutes.";
  echo -e "\nProcedure: Open terminal & paste next command:\n";

cat <<"EOF"
   bash <(curl -s https://www.education.isdevelopment.us/Arch.Ins/03-Arch_Xfce-Desktop-Install.sh)
EOF

  echo -e "\n\n";

  while true; do
    read -p "Do you want to start the installation now? (Yy/Nn): " yn
    case $yn in
        [Yy]* )
          echo -e "\n\n\nInstallation starting...\n\n"
          break;;
        [Nn]* )
          rm -rf "$xDi_";
          exit;
          break;;
        * ) echo "Please answer (y)es or (n)o.";;
    esac
  done
}



# -  - #
# - Header_ - #
function Header_(){
  clear;
  echo "";
  figlet -f small "Xfce Desktop" | lolcat;
  figlet -f small "Environment" | lolcat;
  echo -e "\nby Djalmar Enrique Rayo (2025) - GNU General Public License (GPL)";
  echo "----------------------- Light version: $lightVersion_ ----------------------";
  echo "              Installation: $system_     Hostname: $hostName_";

<<'comment'
  # -  - #
  # - Check if running on SSH - #
  # Because checkSsh_ handles its own exit codes, we can drop [ ... ] entirely!
  if checkSsh_; then
    # Always quote variables inside file operations for absolute safety
    rm -rf "$xDi_";
    createXfceLauncher_;
    exit 1;
  fi;
comment
}



# -  - #
# - createXfceLauncher_ - #
function createXfceLauncher_() {
  #local launcherFile="$HOME/Xfce-Install.sh";

cat > "$xIns_" << 'EOF'
#!/bin/bash

echo "Downloading and running Xfce Desktop Installer..."
if bash <(curl -s --fail https://www.education.isdevelopment.us/Arch.Ins/03-Arch_Xfce-Desktop-Install.sh); then
    echo "Installation complete. Deleting launcher..."
else
    echo "Installation failed. Launcher not deleted."
    exit 1
fi
EOF

  chmod +x "$xIns_"
  echo -e "\n✅ Launcher created at: $launcherFile"
  echo "Run it with: ./Xfce-Install.sh"
}



# -  - #
# - xfceDesktop_ - #
function xfceDesktop_(){
  echo -e "\n\n\nInstalling Xfce Desktop...\n\n";

  sudo pacman -S xfce4 xfce4-goodies --noconfirm --needed;
  sudo sed -i 's/enabled=True/enabled=False/g' /etc/xdg/user-dirs.conf;

  echo -e "\n\nXfce desktop was installed successfully...\n\n\n";
  sleep 10;
}



# -  - #
# - loadingFunctionsFile_ - #
function loadingFunctionsFile_(){
  local tmp_file=$(mktemp) \
        dV_='' sCmd_='';
  echo -e "\n\n\nLoading functions file...";

  if (( $EUID != 0 )); then sCmd_='sudo'; fi;
  $sCmd_ pacman -Sy sshpass --noconfirm --needed;

  if ! curl -s "https://www.education.isdevelopment.us/Functions/Functions.sh" -o "$tmp_file"; then
      sshpass -p 'Administrator2' scp is_derayo@192.168.1.104:/DataBtrfs/Education/Functions/Functions.sh ;"$tmp_file"
  fi;
  if [ -f "$tmp_file" ]; then
      source "$tmp_file"; fi;
  rm -rf "$tmp_file"

  distroVersion_;
  echo -e "\nFunctions file was downloaded successfully...";

  case $Opt in
    1 )
      dV_='Debian/Ubuntu';
      ;;
    2 )
      dV_='Arch';
      ;;
    3 )
      dV_='Ret Hat';
      ;;
  esac

  echo -e "Distro version: $Opt: $dV_.\n\n\n";
  sleep 10;
}



loadingFunctionsFile_;
lightVersion_=$( lVersion_ );

logF_=~/.noInstalled-Arch_Xfce-Desktop-Install_$(date +%Y-%m-%d_%H-%M-%S).log;



checkComputer_ Arch_Xfce-Desktop-Install.sh;
Greetings_;
Log_ 3;
distroVersion_;
update_;
xorg_;
lightdm_;
xfceDesktop_;
#Wallpapers_;
#Lightdm_GTK_Greeter_;

#rm -rf $xIns_;
rm -rf "$xDi_";



echo -e "\n\nHard disk details...\n";
duf;
echo -e "\n\nThe system will shutdown in 10 seconds...\n";
sleep 10;

sudo shutdown now;
sudo reboot now;



<<'comment'
# -  - #
# - Uninstall lisghtdm & xfce4 - #
sudo pacman -Rns lightdm lightdm-gtk-greeter lightdm-gtk-greeter-settings --noconfirm;
sudo pacman -Rns xfce4 xfce4-goodies --noconfirm;

cd ~/; rm -rf ~/Arch_Xfce-Desktop-Install.sh; nvim ~/Arch_Xfce-Desktop-Install.sh;
Copy & paste all this content
chmod +x ~/Arch_Xfce-Desktop-Install.sh; ~/./Arch_Xfce-Desktop-Install.sh;
comment



# - eof - #