#!/usr/bin/env bash

wget -q --spider https://scr.tyleo.dev

if [ $? -eq 0 ]; then
    echo "> Connected to tyleo.dev domain ok. "
else
    echo "> Connect to Internet and Try Again. "
    exit
fi

###############################################################################################
# Vivaldi Replacement Sources
# https://downloads.vivaldi.com/stable/vivaldi-stable-7.3.3635.9-1.x86_64.rpm
# Sourced : https://hst.tyleo.dev/rpm/vivaldi-base.rpm
# Repo is added on RPM install, additionaly, add automatic upgrade to latest just after it.
###############################################################################################

Arg1=$1

wget scr.tyleo.dev/setup/fedora -O ./fedora &>/dev/null
ver="3.2.7_fedoraws_gen4.1_git.tyleo.dev"
clear

# Functions

update-system-hostname() {
NHostname=$(whiptail --title "Fedora Workstation Setup | Hostname Updater" --inputbox "Type the new hostname (No Spaces Please)" 8 60 $(hostnamectl hostname --static) 3>&1 1>&2 2>&3)

if [[ $NHostname = "" ]]|[[ $NHostname = $(hostnamectl hostname --static) ]]; then
    echo "No Change Applied."
else
    sudo hostnamectl hostname --static "$NHostname"
    sudo hostnamectl hostname --pretty "Système $NHostname"
fi

}

update-system-packages() {
sudo dnf makecache
sudo dnf up -y
}

get_waydroid_inithelp() {
    clear
    echo '------------------------------------------------------------------------------------
 Commands to run and URL to register your WayDroid to Google Services Central (GSC)
------------------------------------------------------------------------------------

> Run theses commands (order is important) in your shell :

waydroid session start &
sudo waydroid shell

> Run this command after starting waydroid shell :

ANDROID_RUNTIME_ROOT=/apex/com.android.runtime ANDROID_DATA=/data ANDROID_TZDATA_ROOT=/apex/com.android.tzdata ANDROID_I18N_ROOT=/apex/com.android.i18n sqlite3 /data/data/com.google.android.gsf/databases/gservices.db "select * from main where name = \"android_id\";"
exit

> Copy the ID printed (only the numbers), then paste on https://www.google.com/android/uncertified website (Google Account must be logged in, automatic within Google Chrome)
 
> You can stop session using this commande :
 
waydroid session stop
'
}

open_secure_backup() {
    vivaldi-stable --app="https://secure-backup-orion.tyleo.dev"
}

open_webgallery() {
    vivaldi-stable --app="https://webgallery.tyleo.dev/gallery"
}

open_privategallery() {
    vivaldi-stable --app="https://privategallery.tyleo.dev/login"
}

open_vaultwarden() {
    vivaldi-stable --app="https://vaultwarden.tyleo.dev"
}

get_logo() {
    wget "https://res.tyleo.dev/gen15/Gen15-LOGO.png" -O $HOME/logo.png
}

selinux_disable() {
    sed "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config > sudo /etc/selinux/config
    echo "Reboot recommended."
}

setup_waydroid() {
    if [ -x /usr/bin/waydroid ]; then
    echo "> Waydroid is already installed. No action required, use Waydroid OTA to update it."
    else
    sudo dnf in -y waydroid
    sudo waydroid init -s GAPPS -c "https://ota.waydro.id/system" -v "https://ota.waydro.id/vendor"
    get_waydroid_inithelp
    fi
}

setup_netdata(){
    sudo dnf in -y netdata
    sudo systemctl enable --now netdata
}

inject-wlcm-reg() {
    wget scr.tyleo.dev/runner/reg -O /tmp/tyleo_reg
    wget scr.tyleo.dev/runner/wlcm-v2 -O /tmp/tyleo_wlcm
    echo "/usr/bin/wlcm" > /tmp/wlcm_profile
    sudo cp /tmp/tyleo_wlcm /usr/bin/wlcm
    sudo cp /tmp/tyleo_reg /usr/bin/reg
    sudo chmod +x /usr/bin/reg
    sudo chmod +x /usr/bin/wlcm
    sudo cp /tmp/wlcm_profile /etc/profile.d/wlcm.sh
    sudo chmod +x /etc/profile.d/wlcm.sh
}

install_nautilus(){
    sudo dnf makecache
    # sudo dnf install -y dolphin
    sudo dnf install -y nautilus
}

update-personnal-packages() {
sudo dnf in      -y fedora-workstation-repositories
sudo fedora-third-party enable
sudo fedora-third-party refresh
sudo dnf remove  -y gnome-text-editor
sudo dnf install -y gedit
sudo dnf in      -y "https://hst.tyleo.dev/packages/rpm/ocs-url_fc20.rpm"
sudo dnf in      -y rsnapshot lshw lshw-gui id3v2 switchdesk switchdesk-gui go ruby subfinder engrampa flatpak nmap nmtui gparted duf alien aria2 micro gnome-boxes ptyxis timeshift pwgen ncdu htop btop glances figlet fish zsh gimp openshot distrobox docker docker-compose gnome-software
sudo dnf in      -y gnome-tweaks
sudo dnf in      -y ffmpeg
# Visual Studio Code (RPM Version)
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\nautorefresh=1\ntype=rpm-md\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" | sudo tee /etc/yum.repos.d/vscode.repo > /dev/null
sudo dnf check-update
sudo dnf install code code-insiders -y
# YouTube Dler, Updater and Converter
wget hst.tyleo.dev/yt/yt-dlp    -O /tmp/yt-dlp   
wget hst.tyleo.dev/yt/yt-mp3    -O /tmp/yt-mp3   
wget hst.tyleo.dev/yt/yt-mp4    -O /tmp/yt-mp4   
wget hst.tyleo.dev/yt/yt-update -O /tmp/yt-update
#### SYSTEM INTEGRATION ##############
sudo cp -v /tmp/yt-dlp    /bin/yt-dlp   
sudo cp -v /tmp/yt-mp3    /bin/yt-mp3   
sudo cp -v /tmp/yt-mp4    /bin/yt-mp4   
sudo cp -v /tmp/yt-update /bin/yt-update
## EXEC +x ###########################
sudo chmod -v +x /bin/yt-dlp   
sudo chmod -v +x /bin/yt-mp3   
sudo chmod -v +x /bin/yt-mp4   
sudo chmod -v +x /bin/yt-update
## UPDATE ############################
sudo /bin/yt-dlp -U
######################################
# IPConfig4Linux Integration #########
######################################
## Get
wget scr.tyleo.dev/runner/ipconfig -O /tmp/ipconfig
## SYSTEM INTEGRATION
sudo cp -v /tmp/ipconfig /bin/ipconfig
## EXEC +x ###########################
sudo chmod +x /bin/ipconfig
######################################
}

update-flatpak-games-bigs-packages() {
if [ -x /usr/bin/flatpak ]; then
sudo flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo >>/dev/null
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo >>/dev/null
# sudo flatpak install flathub -y \
echo "No Big Games registered."
sudo flatpak update -y
fi
}

update-flatpak-emulators-packages() {
if [ -x /usr/bin/flatpak ]; then
sudo flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo >>/dev/null
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo >>/dev/null
sudo flatpak install flathub -y \
org.ppsspp.PPSSPP \
net.shadps4.shadPS4 \
net.rpcs3.RPCS3 \
net.pcsx2.PCSX2 \
org.duckstation.DuckStation \
com.github.Rosalie241.RMG \
net.kuribo64.melonDS \
io.mgba.mGBA \
io.github.ryubing.Ryujinx \
app.xemu.xemu \
com.snes9x.Snes9x \
org.purei.Play \
org.mamedev.MAME \
io.github.sameboy.SameBoy \
com.vba_m.visualboyadvance-m
sudo dnf in -y \
dolphin-emu
## Blacklisted Emulators (or removed for DNF version)
sudo flatpak remove -y \
org.DolphinEmu.dolphin-emu
sudo flatpak update -y
fi
}

update-flatpak-games-packages() {
if [ -x /usr/bin/flatpak ]; then
sudo flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo >>/dev/null
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo >>/dev/null
### WAIT LIST
# 
###
sudo flatpak install flathub -y \
io.gitlab.stone_kingdoms.StoneKingdoms \
io.openrct2.OpenRCT2 \
uk.co.powdertoy.tpt \
net.hhoney.rota \
net.hhoney.tinycrate \
org.gnome.Sudoku \
com.atlauncher.ATLauncher \
org.kartkrew.RingRacers \
com.github.Anuken.Mindustry \
org.srb2.SRB2Kart \
net.sourceforge.ExtremeTuxRacer \
io.sourceforge.trigger_rally.TriggerRally \
net.sourceforge.torcs \
dev.tchx84.Gameeky \
com.github.juzzlin.DustRacing2D \
com.simutrans.Simutrans \
ca.victorz.acr.AssaultCubeReloaded \
com.adilhanney.ricochlime \
io.sourceforge.YSoccer \
io.thp.numptyphysics \
de.blobbyvolley.BlobbyVolley2
sudo flatpak update -y
fi
}

update-flatpak-packages() {
if [ -x /usr/bin/flatpak ]; then
sudo flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo >>/dev/null
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo >>/dev/null
sudo flatpak install flathub -y \
com.github.tchx84.Flatseal \
io.github.dweymouth.supersonic \
io.github.ungoogled_software.ungoogled_chromium \
com.bitwarden.desktop \
xyz.armcord.ArmCord \
org.onlyoffice.desktopeditors \
io.github.revisto.drum-machine \
io.github.jeffshee.Hidamari \
io.github.dvlv.boxbuddyrs \
io.github.flattool.Ignition \
de.capypara.FieldMonitor \
us.materialio.Materialious \
org.mozilla.Thunderbird \
org.kde.calligra \
com.hunterwittenborn.Celeste \
io.github.giantpinkrobots.varia \
md.obsidian.Obsidian \
io.gitlab.news_flash.NewsFlash \
org.cockpit_project.CockpitClient \
org.sqlitebrowser.sqlitebrowser \
com.github.finefindus.eyedropper \
io.missioncenter.MissionCenter \
org.gnome.design.Lorem \
io.github.lo2dev.Echo \
io.github.realmazharhussain.GdmSettings \
com.mattjakeman.ExtensionManager \
io.gitlab.elescoute.password \
org.dupot.easyflatpak \
com.konstantintutsch.Lock \
io.github.vikdevelop.SaveDesktop \
io.github.plrigaux.sysd-manager \
io.github.vemonet.EmojiMart \
com.github.fabiocolacio.marker \
org.gnome.DejaDup \
de.schmidhuberj.DieBahn \
dev.zelikos.rollit \
im.bernard.Memorado \
app/com.github.iwalton3.jellyfin-media-player \
it.mijorus.gearlever \
io.github.flattool.Warehouse \
io.gitlab.adhami3310.Impression \
com.jgraph.drawio.desktop \
org.gabmus.swatch \
io.github.wiiznokes.fan-control \
io.github.fsobolev.TimeSwitch \
ca.vlacroix.Tally \
dev.qwery.AddWater \
org.gnome.World.PikaBackup \
com.gitlab.davem.ClamTk \
com.github.alecaddd.sequeler \
it.fabiodistasio.AntaresSQL \
io.gitlab.elescoute.spacelaunch \
me.iepure.devtoolbox \
com.github.phase1geo.minder \
ca.desrt.dconf-editor \
page.codeberg.libre_menu_editor.LibreMenuEditor \
pl.youkai.nscan \
app.drey.Dialect \
org.gnome.Geary \
com.github.hugolabe.Wike \
com.rafaelmardojai.Blanket \
ca.edestcroix.Recordbox \
org.nickvision.tagger \
io.github.nokse22.asciidraw \
net.nokyan.Resources \
org.easycoding.TunedSwitcher \
io.github.halfmexican.Mingle \
org.gnome.Firmware \
io.github.ronniedroid.concessio \
net.codelogistics.webapps \
io.freetubeapp.FreeTube \
io.github.amit9838.mousam \
org.gabmus.whatip \
com.quexten.Goldwarden \
info.smplayer.SMPlayer \
io.github.kukuruzka165.materialgram \
com.usebottles.bottles
# Removing Blacklisted Packs
sudo flatpak remove -y \
com.visualstudio.code \
app.zen_browser.zen \
io.github.spacingbat3.webcord
sudo flatpak update -y
fi
}

update-flatpak-keyguard() {
sudo wget "https://github.com/AChep/keyguard-app/releases/download/r20250226.1/Keyguard.flatpak" -O /tmp/keyguard.flatpak
sudo flatpak install "/tmp/keyguard.flatpak" -y
}

update-flatpak-sublime-music() {
sudo wget "https://hst.tyleo.dev/flatpaks/sublime-music.flatpak" -O /tmp/sublime-music.flatpak
sudo flatpak install "/tmp/sublime-music.flatpak" -y
}

kde_install_xrdp() {
    sudo dnf in xrdp plasma-workspace-x11 -y
    echo "> Configuring FirewallD for XRDP Service on 0.0.0.0:3389..."
    sudo firewall-cmd --permanent --add-port=3389/tcp
    sudo firewall-cmd --reload
    echo "> Autorizing XRDP Processes..."
    sudo chcon --type=bin_t /usr/sbin/xrdp
    sudo chcon --type=bin_t /usr/sbin/xrdp-sesman
    echo "> Enabling and Starting XRDP Services Daemons..."
    sudo systemctl enable xrdp --now
    sudo systemctl enable xrdp-sesman --now
}

invoke-reg-script() {
    wget scr.tyleo.dev/setup/wr -O /tmp/wr
    sudo bash /tmp/wr
    sudo reg
}

unreg-reg-script() {
    wget scr.tyleo.dev/setup/wr -O /tmp/wr
    sudo bash /tmp/wr
    sudo reg --cleanup
}

install-vpn-client() {
# sudo tee /etc/yum.repos.d/pritunl.repo << EOF
# [pritunl]
# name=Pritunl Repository
# baseurl=https://repo.pritunl.com/stable/yum/fedora/41/
# gpgcheck=1
# enabled=1
# gpgkey=https://raw.githubusercontent.com/pritunl/pgp/master/pritunl_repo_pub.asc
# EOF
# sudo dnf install pritunl-client-electron -y
sudo rm /etc/yum.repos.d/pritunl.repo -f
sudo dnf remove pritunl-client-electron -y
}

update-fonts-package() {
# Sourcing and Parameters
SOURCE_FONT_PACKFILE="https://res.tyleo.dev/fonts/fontpack.tar.gz"
TEMP_FONT_PACKFILE="/tmp/fontpack.tar.gz"
FONTDIR="/usr/share/fonts/custom"

# Preparing Font Directory
sudo rm -rfv $FONTDIR >/dev/null
sudo mkdir -pv $FONTDIR

# Downloading Assets and Placing Them
sudo wget $SOURCE_FONT_PACKFILE -O $TEMP_FONT_PACKFILE
sudo tar -xvf $TEMP_FONT_PACKFILE -C $FONTDIR

# Refreshing FC Cache
sudo fc-cache -r

# Applying Current Font Settings
setup_font

}

update-theming-pack() {
echo "> Preparing Theming Packs..."
gsettings set org.gnome.mutter check-alive-timeout 240000

# Graphite Theme Settings
## Color Chooser ##
clear
title="Theme Color and Mode Selection"
header-show
#echo -n "> Make color choice (default is Red) :
# 1. Red
# 2. Blue
# 3. Pink
# 4. Purple
# 5. Teal
# 6. White
# 7. Green
# 8. Orange
# 9. Yellow
#
#> Choice : "
#read colorchoice
#if [[ $colorchoice = $null ]]; then
#    ThemeColor="-red"
#fi
#if [[ $colorchoice = 1 ]]; then
#    ThemeColor="-red"
#fi
#if [[ $colorchoice = 2 ]]; then
#    ThemeColor="-blue"
#fi
#if [[ $colorchoice = 3 ]]; then
#    ThemeColor="-pink"
#fi
#if [[ $colorchoice = 4 ]]; then
#    ThemeColor="-purple"
#fi
#if [[ $colorchoice = 5 ]]; then
#    ThemeColor="-teal"
#fi
#if [[ $colorchoice = 6 ]]; then
#    ThemeColor=""
#fi
#if [[ $colorchoice = 7 ]]; then
#    ThemeColor="-green"
#fi
#if [[ $colorchoice = 8 ]]; then
#    ThemeColor="-orange"
#fi
#if [[ $colorchoice = 9 ]]; then
#    ThemeColor="-yellow"
#fi
####################
#

mkdir $HOME/.themes
mkdir -p $HOME/.local/icons

wget "https://res.tyleo.dev/gtk/mc3d/mc3d-icon.tar.xz"     -O /tmp/icontheme.tar.xz
wget "https://res.tyleo.dev/gtk/lavanda/Lavanda-Dark.tar.xz"    -O /tmp/gsh-gtktheme-dark.tar.xz
wget "https://res.tyleo.dev/gtk/cursor/McMojave-cursors.tar.xz" -O /tmp/cursors.tar.xz

# Cursors and Icons are stored in the same directory (System)
sudo tar -xvf /tmp/cursors.tar.xz                           -C  /usr/share/icons # Cursor
sudo tar -xvf /tmp/icontheme.tar.xz                         -C  /usr/share/icons # Icons 

# Cursors and Icons are stored in the same directory (User)
sudo tar -xvf /tmp/cursors.tar.xz                           -C  $HOME/.local/share/icons # Cursor
sudo tar -xvf /tmp/icontheme.tar.xz                         -C  $HOME/.local/share/icons # Icons 

# GTK Theme Extract (System)
sudo tar -xvf /tmp/gsh-gtktheme-dark.tar.xz                          -C  /usr/share/themes # Shell & GUI Themes

# GTK Theme Extract (User)
sudo tar -xvf /tmp/gsh-gtktheme-dark.tar.xz                          -C  $HOME/.themes # Shell & GUI Themes

sudo gsettings set org.gnome.desktop.interface gtk-theme "Lavanda-Dark"
sudo gsettings set org.gnome.desktop.wm.preferences theme "Lavanda-Dark"
sudo gsettings set org.gnome.desktop.interface icon-theme "MacOS-3D-Icons"
gsettings set org.gnome.desktop.interface gtk-theme "Lavanda-Dark"
gsettings set org.gnome.desktop.wm.preferences theme "Lavanda-Dark"
gsettings set org.gnome.desktop.interface icon-theme "MacOS-3D-Icons"
gsettings set org.gnome.desktop.interface cursor-theme "McMojave-cursors"
dconf write /org/gnome/shell/extensions/user-theme/name "'Lavanda-Dark'"
flatpak override --user --env=GTK_THEME=Lavanda-Dark
sudo flatpak override --env=GTK_THEME=Lavanda-Dark


flatpak override --user --filesystem=~/.themes
sudo flatpak override --filesystem=~/.themes
flatpak override --user --filesystem=~/.local/share/icons
sudo flatpak override --filesystem=~/.local/share/icons
if [[ $DESKTOP_SESSION == "gnome" ]]; then
sudo cp /etc/environment /etc/environment.bak
echo "GTK_THEME='Lavanda-Dark'"       | sudo tee /etc/environment
echo "export GTK_THEME='Lavanda-Dark'"| sudo tee -a /etc/environment
else
echo "Gnome is not active, not applying Environments Overrides."
fi
}

update-usermod() {
sudo dnf in -y fish
sudo usermod --shell /usr/bin/fish root
sudo usermod --shell /usr/bin/fish $USER
}

install-gnome-extensions() {
sudo dnf in openssl -y
EXT_LIST=( dash-to-dock@micxgx.gmail.com
user-theme@gnome-shell-extensions.gcampax.github.com
arcmenu@arcmenu.com
trayIconsReloaded@selfmade.pl
extension-list@tu.berry
add-username-toppanel@brendaw.com
gsconnect@andyholmes.github.io
caffeine@patapon.info
drive-menu@gnome-shell-extensions.gcampax.github.com
CoverflowAltTab@palatis.blogspot.com
burn-my-windows@schneegans.github.com
Hide_Activities@shay.shayel.org
quick-settings-tweaks@qwreey
mediacontrols@cliffniff.github.com
tilingshell@ferrarodomenico.com
transparent-top-bar@ftpix.com
no-overview@fthx
compact-quick-settings@gnome-shell-extensions.mariospr.org )

for i in "${EXT_LIST[@]}"
do
    gnome-extensions uninstall dash-to-panel@jderose9.github.com &>> /dev/null
    busctl --user call org.gnome.Shell.Extensions /org/gnome/Shell/Extensions org.gnome.Shell.Extensions InstallRemoteExtension s ${i} &
done
}

execute-reboot() {
    sudo /usr/sbin/reboot
}

## FEDORA BASEOS FILES
osrel="/etc/fedora-release"
######################

## COLORS
# Reset
Color_Off='\033[0m'       # Text Reset

# Regular Colors
Black='\033[0;30m'        # Black
Red='\033[0;31m'          # Red
Green='\033[0;32m'        # Green
Yellow='\033[0;33m'       # Yellow
Blue='\033[0;34m'         # Blue
Purple='\033[0;35m'       # Purple
Cyan='\033[0;36m'         # Cyan
White='\033[0;37m'        # White

# Bold
BBlack='\033[1;30m'       # Black
BRed='\033[1;31m'         # Red
BGreen='\033[1;32m'       # Green
BYellow='\033[1;33m'      # Yellow
BBlue='\033[1;34m'        # Blue
BPurple='\033[1;35m'      # Purple
BCyan='\033[1;36m'        # Cyan
BWhite='\033[1;37m'       # White

# Underline
UBlack='\033[4;30m'       # Black
URed='\033[4;31m'         # Red
UGreen='\033[4;32m'       # Green
UYellow='\033[4;33m'      # Yellow
UBlue='\033[4;34m'        # Blue
UPurple='\033[4;35m'      # Purple
UCyan='\033[4;36m'        # Cyan
UWhite='\033[4;37m'       # White

# Background
On_Black='\033[40m'       # Black
On_Red='\033[41m'         # Red
On_Green='\033[42m'       # Green
On_Yellow='\033[43m'      # Yellow
On_Blue='\033[44m'        # Blue
On_Purple='\033[45m'      # Purple
On_Cyan='\033[46m'        # Cyan
On_White='\033[47m'       # White

# High Intensity
IBlack='\033[0;90m'       # Black
IRed='\033[0;91m'         # Red
IGreen='\033[0;92m'       # Green
IYellow='\033[0;93m'      # Yellow
IBlue='\033[0;94m'        # Blue
IPurple='\033[0;95m'      # Purple
ICyan='\033[0;96m'        # Cyan
IWhite='\033[0;97m'       # White

# Bold High Intensity
BIBlack='\033[1;90m'      # Black
BIRed='\033[1;91m'        # Red
BIGreen='\033[1;92m'      # Green
BIYellow='\033[1;93m'     # Yellow
BIBlue='\033[1;94m'       # Blue
BIPurple='\033[1;95m'     # Purple
BICyan='\033[1;96m'       # Cyan
BIWhite='\033[1;97m'      # White

# High Intensity backgrounds
On_IBlack='\033[0;100m'   # Black
On_IRed='\033[0;101m'     # Red
On_IGreen='\033[0;102m'   # Green
On_IYellow='\033[0;103m'  # Yellow
On_IBlue='\033[0;104m'    # Blue
On_IPurple='\033[0;105m'  # Purple
On_ICyan='\033[0;106m'    # Cyan
On_IWhite='\033[0;107m'   # White
######################

header-show() {
    clear
    echo -e "$BIGreen> Starting WS Protocol..., Name : $title"
}

reload-script() {
    chmod +x $PWD/$(basename $0)
    bash -c "$PWD/$(basename $0)" && exit
}

wait-3s() {
    echo "> Waiting... Use CTRL+C to cancel procedure."
    sleep 0.25
    sleep 0.25
    sleep 0.25
    echo -e "  Started !$Color_Off"
}

wait-for-keypress() {
    echo -n -e $On_White $BBlack
    read -p " Press any key to continue... " -n1 -s
    echo -n -e $Color_Off
}

enable-cmd-mode() {
    echo -e -n $IYellow
}

disable-cmd-mode() {
    echo -e -n $Color_Off
}

kde_install_pmobile() {
    sudo dnf in -y plasma-mobile
    echo "!> Use login screen to switch to Mobile UI. /!\ Mobile UI is Wayland only /!\^"
}

kde_install_px11() {
    sudo dnf in -y plasma-workspace-x11
    echo "!> Use login screen to switch to X11, reboot is required for multi monitors setup."
}

show_script_version() {
    echo -e "$BIWhite Script Version : $ver $Color_Off"
    echo -e "$BICyan---------------------------------------------------------------------------"
}

show_licence(){
    whiptail --title "Licence, parce qu'il en fallait une." --ok-button "OKAY" --msgbox "              DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                      Version 2, December 2004

            Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

    Everyone is permitted to copy and distribute verbatim or modified
   copies of this license document, and changing it is allowed as long
                      as the name is changed.

              DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
     TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

 0. You just DO WHAT THE FUCK YOU WANT TO.
---------------------------------------------------------------------------" 20 75
 exit
}

show_header(){
    echo -e "${BICyan}---------------------------------------------------------------------------${Color_Off}"
echo -e "${BICyan}|${Color_Off}${BIGreen} ___         __    _____ __     __  ${BICyan}|${Color_Off}$BIPurple  _                 _               ${BICyan}|${Color_Off}
${BICyan}|${Color_Off}${BIGreen}  |   | _ _ (_ \_/(_  | |_ |\/|(_   ${BICyan}|${Color_Off}$BIPurple |_)|_  _  _ ._ o  |_).__ o _  __|_ ${BICyan}|${Color_Off}
${BICyan}|${Color_Off}${BIGreen}  | \/|(-(_)__) | __) | |__|  |__)  ${BICyan}|${Color_Off}$BIPurple |  | |(_)(/_| ||><|  |(_)|(/_(_ |_ ${BICyan}|${Color_Off}
${BICyan}|${Color_Off}${BIGreen}    /    Make IT Happening          ${BICyan}|${Color_Off}$BIPurple            Just Do It!  _|  GEN4   ${BICyan}|${Color_Off}${Color_Off}"
echo -e "$BICyan---------------------------------------------------------------------------$Color_Off"
}

if [[ $Arg1 = "--version" ]]||[[ $Arg1 = "-v" ]]; then
    show_header
    show_script_version
    exit
fi

if [[ $Arg1 = "--register" ]]||[[ $Arg1 = "-r" ]]; then
    show_header
    invoke-reg-script
    exit
fi

if [[ $Arg1 = "--unregister" ]]||[[ $Arg1 = "-u" ]]; then
    show_header
    unreg-reg-script
    exit
fi

if [[ $Arg1 = "--licence" ]]||[[ $Arg1 = "-l" ]]; then
    show_header
    show_licence
    exit
fi

if [[ $Arg1 = "--version" ]]||[[ $Arg1 = "-v" ]]; then
    show_header
    show_script_version
    exit
fi

if [[ $Arg1 = "--help" ]]||[[ $Arg1 = "-h" ]]; then
    whiptail --title "Guide de commande rapides" --msgbox " -a/--auto : Déclancher le Deploiement Automatique (Full).
 -h/--help : Afficher cette superbe aide faite main.
 -r/--register : Enregistrer le système avec le script reg (installe aussi WLCMv2)
 -v/--version : Affiche la version du script. Voir git.tyleo.dev pour les détails
 -l/--licence : Voir la licence de ce script. Faut croire, qu'il y'en a une." 12 90
    reload
fi

if [[ $Arg1 = "--auto" ]]||[[ $Arg1 = "-a" ]]; then
    show_header
    echo "$BICyan > Mode Automatique Invoqué. Lancement de la tâche Full Deploy dans 3 secondes."
    sleep 3
    clear
    title="Full Deploy/Update/Setup - From CLI (-a/--auto)"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-system-hostname
    update-system-packages
    update-personnal-packages
    install-vpn-client
    update-flatpak-packages
    update-flatpak-keyguard
    update-fonts-package
    update-theming-pack
    update-usermod
    inject-wlcm-reg
    disable-cmd-mode
    wait-for-keypress
    reload-script
    exit
fi

remove_chrome() {
    if command -v google-chrome >/dev/null 2>&1; then
    echo "Removing Google Chrome from system..."
    sudo killall chrome google-chrome google-chrome-stable
    sudo dnf remove -y google-chrome-stable
    sudo rm -fv /etc/yum.repos.d/google-chrome.repo
else
    echo "Chrome is missing, right thing."
fi
}

remove_brave() {
    if command -v brave-browser >/dev/null 2>&1; then
    echo "Removing Brave Browser from system..."
    sudo killall brave brave-browser brave-browser-beta brave-browser-nightly
    sudo dnf remove -y brave-browser brave-browser-beta brave-browser-nightly
    sudo rm -fv /etc/yum.repos.d/brave-browser*
else
    echo "Brave is missing, right thing."
fi
}

setup_vivaldi() {
if command -v vivaldi >/dev/null 2>&1; then
    sudo dnf makecache
    sudo dnf up -y vivaldi-stable
else
    echo "[vivaldi]
name=vivaldi
baseurl=https://repo.vivaldi.com/archive/rpm/x86_64
enabled=1
gpgcheck=0" | sudo tee /etc/yum.repos.d/vivaldi.repo
    sudo dnf in -y vivaldi-stable
fi
    # Addon for replacing Chrome commands by Vivaldi, allowing seamless transfer.
    sudo rm -fv /bin/google-chrome*
    echo 'vivaldi-stable "$@"' | sudo tee /bin/google-chrome
    sudo cp -v /usr/share/applications/vivaldi-stable.desktop /usr/share/applications/google-chrome.desktop
    sudo cp -fv /bin/google-chrome /bin/google-chrome-stable
    sudo chmod -v +x /bin/google-chrome*
}



setup_font() {
# Setup Oxanium Font
gsettings set org.gnome.desktop.interface document-font-name 'Comfortaa 13'
gsettings set org.gnome.desktop.interface font-name 'Comfortaa 13'
gsettings set org.gnome.desktop.interface monospace-font-name 'UNISPACE 13'
gsettings set org.gnome.desktop.interface text-scaling-factor '1.35'

}

#################################################################################################################
#################################################################################################################
#################################################################################################################
#################################################################################################################
#################################################################################################################
#################################################################################################################

menusizemini="20 70 10"
menusizenormal="30 70 22"

if [[ $Arg1 = "--mini" ]]; then
    menusize=$menusizemini
    menumode="| Mode Mini"
else
    menusize=$menusizenormal
    menumode=""
fi

choice=$(whiptail --title "Fedora Workstation Setup | v$ver $menumode" --nocancel --notags --menu "Choose an option" $menusize \
"QT" " Quit the Script" \
"A" " Execute All Jobs (Full Deploy)(-a/--auto)" \
"" "" \
"G" " Install Gnome Extensions" \
"W" " Install/Update WLCM & RegScript" \
"R" " Register this system (-r/--register)" \
"" "" \
"Vivaldi" " Install or Update Vivaldi Browser" \
"" "" \
"1" " Update System Packages & Configuration" \
"2" " Update Flatpak Packages & Configuration" \
"3" " Update Fontpack Configuration" \
"4" " Update Theming Configuration" \
"5" " Update System Hostname" \
"6" " Update Usermod Configuration" \
"7" " Update or Setup Fontpackage to SystemUI" \
"" "" \
"SELINUX" " Disable Selinux (Require Reboot)" \
"" "" \
"V" " Install/Update VPN Client" \
"K" " Install/Update Keyguard Client" \
"S" " Install/Update Subsonic Client" \
"M" " Install/Update Gaming Packages" \
"B" " Install/Update BgGame Packages" \
"E" " Install/Update Emulators Packages" \
"D" " Install and Initialize WayDroid OTA (Add H for help only)" \
"K0" " Install Plasma X11 Workspace" \
"K1" " Install Plasma Mobile Workspace" \
"K2" " Install XRDP on Plasma Desktop (This enable X11 Support)" \
"" "" \
"SB" " Open Secure Backup" \
"WB" " Open WebGallery" \
"PB" " Open PrivateGallery" \
"VB" " Open Vaultwarden" \
"DL" " Download Tyleo Logo (Gen15)" \
"" "" \
"RN" " Rename System" \
"" "" \
"RB" " Reboot Now !" \
3>&1 1>&2 2>&3)

if [[ $choice = $null ]]; then
    reload-script
fi

if [[ $choice = "" ]]; then
    reload-script
fi

if [[ $choice = "QT" ]]; then
    exit
fi

if [[ $choice = 7 ]]; then
    title="Font deploy"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    setup_font
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = SELINUX ]]; then
    title="Selinux Disabler"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    selinux_disable
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = "Vivaldi" ]]; then
    title="Vivaldi Browser Deployment"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    remove_chrome
    remove_brave
    setup_vivaldi
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = SB ]]; then
    open_secure_backup
    reload-script
fi

if [[ $choice = WB ]]; then
    open_webgallery
    reload-script
fi

if [[ $choice = PB ]]; then
    open_privategallery
    reload-script
fi

if [[ $choice = VB ]]; then
    open_vaultwarden
    reload-script
fi

if [[ $choice = DL ]]; then
    get_logo
    reload-script
fi

if [[ $choice = RN ]]; then
    title="Hostname Update"
    show_header
    header-show
    enable-cmd-mode
    update-system-hostname
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = A ]]; then
    title="Full Deploy/Update/Setup"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-system-hostname
    update-system-packages
    update-personnal-packages
    install_nautilus
    remove_chrome
    setup_vivaldi
    setup_netdata
    install-vpn-client
    update-flatpak-packages
    update-flatpak-keyguard
    update-fonts-package
    update-theming-pack
    update-usermod
    inject-wlcm-reg
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = W ]]; then
    title="Registering Script & WLCMv2"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    inject-wlcm-reg
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = D ]]; then
    title="WayDroid Installation and Ignition (GAPPS)"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    setup_waydroid
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = DH ]]; then
    title="WayDroid Installation and Ignition (GAPPS)(HELP Only)"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    get_waydroid_inithelp
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = R ]]; then
    title="Register my system"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    invoke-reg-script
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = K ]]; then
    title="Installation or Update of Keyguard Vaultwarden Client"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-flatpak-keyguard
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = E ]]; then
    title="Installation or Update of Emulators"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-flatpak-emulators-packages
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = S ]]; then
    title="Installation or Update of Subsonic Music Client"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-flatpak-sublime-music
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = 2 ]]; then
    title="Flatpak Updates Packages & Configuration"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-flatpak-packages
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = M ]]; then
    title="Games - Flatpak Updates Packages & Configuration"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-flatpak-games-packages
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = B ]]; then
    title="Big Games - Flatpak Updates Packages & Configuration"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-flatpak-games-bigs-packages
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = K2 ]]; then
    title="KDE DE - Remote Desktop Service (XRDP) with X11"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    kde_install_xrdp
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = K1 ]]; then
    title="KDE DE - Mobile UI"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    kde_install_pmobile
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = K0 ]]; then
    title="KDE DE - X11 Workspace (For NVIDIA Environnements)"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    kde_install_px11
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = 3 ]]; then
    title="Fontpack Updates and Installation"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-fonts-package
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = 4 ]]; then
    title="Theming for Gnome Desktop Updates and Installation"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-theming-pack
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = 5 ]]; then
    title="System Hostname Configuration"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-system-hostname
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = 6 ]]; then
    title="User Modifications Configurations"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-usermod
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = V ]]; then
    title="VPN Client Installation or Updates (Pritunl Client Electron)"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    install-vpn-client
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = 1 ]]; then
    title="System Packages Updates and Configurations"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    update-system-packages
    update-personnal-packages
    install_nautilus
    setup_netdata
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = G ]]; then
    title="Gnome Extensions List"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    install-gnome-extensions
    disable-cmd-mode
    wait-for-keypress
    reload-script
fi

if [[ $choice = RB ]]
then
    title="Rebooting System"
    show_header
    header-show
    wait-3s
    enable-cmd-mode
    echo "System Will Reboot after 3s..."
    disable-cmd-mode
    execute-reboot
    wait-3s
    reload-script
fi

if [[ $choice = T ]]
then
    title="Test Procedure"
    show_header
    header-show
    wait-3s 
    reload-script
fi

$Color_Off