#!/bin/bash
pkg install root-repo -y


echo -e "\e[36m[+] Installing Required packages\e[0m"termux-setup-storage
pkg update -y

pkg upgrade -y
pkg install wget
pkg install git -y
pkg install hashdeep -y
pkg install x11-repo
clear


echo -e "\e[33m[i] Setting up storage permissions..\e[0m"
yes | termux-setup-storage &>/dev/null
sleep 2
clear
while true; do
    if [ -d ~/storage/shared ]; then
        break
    else
        echo -e "\e[31m[ERR] Storage permission denied\e[0m"
    fi
done
clear
sleep 2

echo -e "\e[36m[+] Installing Termux-am\e[0m"
pkg install termux-am -y &>/dev/null
echo -e "\e[32m[âœ“] Termux-am Installed Successfully\e[0m"
echo -e "\n"
clear
if [ -e $PREFIX/glibc ]; then
    echo -n "Removing previous glibc. Continue? (Y/n) "
    read i
    if [ "$i" = "Y" ] || [ "$i" = "y" ]; then
        rm -rf $PREFIX/glibc
    else
        return 1
    fi
fi

INSTALL_WOW64=0

echo "Select an option"
echo "1) Install boxvidra with box86 build (6 June)"
echo "2) Install boxvidra with wow64 build (Complete version)"
echo ""
echo -n "Selected number: "
read i
case "$i" in
1)
    echo -e "\e[36m[+] Installing Boxvidra Box86 build\e[0m"
    wget -q --show-progress -O /data/data/com.termux/files/usr/glibc.box86.tar.xz https://github.com/AGENT404TRD/BOXVIDRA-EMULATOR/releases/download/Glibc/glibc.box86.tar.xz
    sleep 2
    echo -e "\e[33m[i] Extracting Box86 build glibc...\e[0m"
    tar -xf /data/data/com.termux/files/usr/glibc.box86.tar.xz -C /data/data/com.termux/files/usr/
    cp /data/data/com.termux/files/usr/glibc/opt/scripts/boxvidra /data/data/com.termux/files/usr/bin
    cp /data/data/com.termux/files/usr/glibc/opt/scripts/vidra /data/data/com.termux/files/usr/bin
    chmod +x /data/data/com.termux/files/usr/glibc/opt/scripts/*
    chmod 777 /data/data/com.termux/files/usr/bin/boxvidra
    chmod 777 /data/data/com.termux/files/usr/bin/boxvidra
    rm /data/data/com.termux/files/usr/glibc.box86.tar.xz
    echo -e "\n"
    echo -e "\e[32m[âœ“] Boxvidra Box86 build Installed Successfully.\e[0m"
    ;;
2)
    echo -e "\e[36m[+] Installing Boxvidra Wow64 build\e[0m"
    wget -q --show-progress -O /data/data/com.termux/files/usr/glibc.wow64.tar.xz https://github.com/AGENT404TRD/BOXVIDRA-EMULATOR/releases/download/Glibc/glibc.wow64.tar.xz
    sleep 2
    echo -e "\e[33m[i] Extracting Wow64 build glibc...\e[0m"
    tar -xf /data/data/com.termux/files/usr/glibc.wow64.tar.xz -C /data/data/com.termux/files/usr/
    cp /data/data/com.termux/files/usr/glibc/opt/scripts/boxvidra /data/data/com.termux/files/usr/bin
    chmod +x /data/data/com.termux/files/usr/glibc/opt/scripts/*
    chmod 777 /data/data/com.termux/files/usr/bin/boxvidra
    rm /data/data/com.termux/files/usr/glibc.wow64.tar.xz
    echo -e "\n"
    echo -e "\e[32m[âœ“] Boxvidra Wow64 build Installed Successfully.\e[0m"
    ;;
*)
    return 1
    ;;
esac

clear
sleep 2
echo -e "\e[32m[+] Installing Termux Packages...\e[0m"
apt-get clean -y
apt-get update -y
apt-get upgrade -y
pkg install wget -y
pkg install root-repo -y
apt-get -y --with-new-pkgs -o Dpkg::Options::="--force-confdef" upgrade
echo -e "\e[32m[âœ“] Termux packages Installed Successfully.\e[0m"
echo -e "\n"
clear

echo -e "\e[36m[+] Installing Termux X11 packages...\e[0m"
pkg install x11-repo -y &>/dev/null
pkg install termux-x11-nightly -y &>/dev/null
echo -e "\e[32m[âœ“] Termux X11 Packages Installed Successfully.\e[0m"
echo -e "\n"

echo -e "\e[36m[+] Installing Boxvidra Emulator Packages...\e[0m"
pkg install tur-repo -y &>/dev/null
pkg install xwayland -y &>/dev/null
pkg install xorg-xrandr -y &>/dev/null
pkg install p7zip -y &>/dev/null
pkg install patchelf -y &>/dev/null
pkg install ncurses-utils -y &>/dev/null
pkg install hashdeep -y &>/dev/null
pkg install mesa-zink virglrenderer-mesa-zink vulkan-loader-android virglrenderer-android -y &>/dev/null
apt install android-tools -y &>/dev/null
pkg install python-tkinter -y &>/dev/null
echo -e "\e[32m[âœ“] Boxvidra Emulator Packages Installed Successfully.\e[0m"
echo -e "\n"
sleep 3
clear

echo -e "\e[36m[+] Installing Xfce4, Plugins and Tools\e[0m"
echo -e "\n"
pkg install xfce4 -y
apt install xfce4-whiskermenu-plugin -y
apt install xfce4-screenshooter -y
apt install xfce4-taskmanager -y
apt install xfce4-docklike-plugin -y
apt install matchbox-keyboard -y
echo -e "\e[32m[âœ“] Xfce4, Plugins, Tools, Packages, Installed Successfully.\e[0m"
echo -e "\n"
sleep 3
clear

echo -e "\e[36m[+] Installing Boxvidra Emulator Programs, Browsers, Etc..\e[0m"
echo -e "\n"
pkg install gimp -y
pkg install mpv -y
pkg install firefox -y
pkg install vlc -y
pkg install vlc-qt -y
pkg install abiword -y
apt install ristretto -y
echo -e "\n"
echo -e "\e[32m[âœ“] Boxvidra Emulator Programs, Browsers, Other Applications Installed Successfully.\e[0m"
clear
sleep 3

# CREATE DESKTOP FILE
if [ ! -d ~/Desktop ]; then
    mkdir -p ~/Desktop
fi

echo "Select a Theme to Download/Install"
echo "1) Windows 10 Light Theme"
echo "2) Windows 10 Dark Theme"
echo "3) Windows 10 Red, Gaming Theme"
echo "4) Windows 10 Purple, Space Theme"
echo ""
echo -n "Selected number : "
read i
case "$i" in
1)
   echo -n "Installing Windows 10 theme (Light) ..."

   wget -q --show-progress -O Windows.10.Light.tar.xz https://github.com/AGENT404TRD/BOXVIDRA-EMULATOR/releases/download/Themes/Windows.10.Light.tar.xz
   tar -xf Windows.10.Light.tar.xz
   cd 'Windows 10 Light'
   cp -r .icons /data/data/com.termux/files/home/
   cp -r .themes /data/data/com.termux/files/home/
   cp -r APPLICATIONS /data/data/com.termux/files/home
   cp .config.tar.xz /data/data/com.termux/files/home
   tar -xf /data/data/com.termux/files/home/.config.tar.xz -C /data/data/com.termux/files/home
   cp Windows-10-master.zip /data/data/com.termux/files/usr/share/icons
   unzip /data/data/com.termux/files/usr/share/icons/Windows-10-master.zip -d /data/data/com.termux/files/usr/share/icons
   cp -r WALLPAPERS /data/data/com.termux/files/home
   cp -r BOXVIDRA-CFG /data/data/com.termux/files/home
   cp PROGRAMS/* /data/data/com.termux/files/home/Desktop
   rm /data/data/com.termux/files/home/.config.tar.xz
   cd 'PROGRAMS'
   cd ..
   rm -r 'Windows 10 Light'
   rm Windows.10.Light.tar.xz
   clear
   echo -n "Windows 10 theme (Light) Installed Successfully"
   sleep 3
    ;;
2)
   echo -n "Installing Windows 10 theme (Dark) ..."

   wget -q --show-progress -O Windows.10.Dark.tar.xz https://github.com/AGENT404TRD/BOXVIDRA-EMULATOR/releases/download/Themes/Windows.10.Dark.tar.xz
   tar -xf Windows.10.Dark.tar.xz
   cd 'Windows 10 Dark'
   cp -r .icons /data/data/com.termux/files/home/
   cp -r .themes /data/data/com.termux/files/home/
   cp -r APPLICATIONS /data/data/com.termux/files/home
   cp .config.tar.xz /data/data/com.termux/files/home
   tar -xf /data/data/com.termux/files/home/.config.tar.xz -C /data/data/com.termux/files/home
   cp Windows-10-master.zip /data/data/com.termux/files/usr/share/icons
   unzip /data/data/com.termux/files/usr/share/icons/Windows-10-master.zip -d /data/data/com.termux/files/usr/share/icons
   cp -r WALLPAPERS /data/data/com.termux/files/home
   cp -r BOXVIDRA-CFG /data/data/com.termux/files/home
   cp PROGRAMS/* /data/data/com.termux/files/home/Desktop
   rm /data/data/com.termux/files/home/.config.tar.xz
   cd ..
   rm -r 'Windows 10 Dark'
   rm Windows.10.Dark.tar.xz
   clear
   echo -n "Windows 10 theme (Dark) Installed Successfully"
   sleep 3
   ;;
3)
   echo -n "Installing Windows 10 theme (Red, Gaming) ..."

   wget -q --show-progress -O Windows.10.Red.tar.xz https://github.com/AGENT404TRD/BOXVIDRA-EMULATOR/releases/download/Themes/Windows.10.Red.tar.xz
   tar -xf Windows.10.Red.tar.xz
   cd 'Windows 10 Red'
   cp -r .icons /data/data/com.termux/files/home/
   cp -r .themes /data/data/com.termux/files/home/
   cp -r APPLICATIONS /data/data/com.termux/files/home
   cp .config.tar.xz /data/data/com.termux/files/home
   tar -xf /data/data/com.termux/files/home/.config.tar.xz -C /data/data/com.termux/files/home
   cp Windows-10-master.zip /data/data/com.termux/files/usr/share/icons
   unzip /data/data/com.termux/files/usr/share/icons/Windows-10-master.zip -d /data/data/com.termux/files/usr/share/icons
   cp -r WALLPAPERS /data/data/com.termux/files/home
   cp -r BOXVIDRA-CFG /data/data/com.termux/files/home
   cp PROGRAMS/* /data/data/com.termux/files/home/Desktop
   rm /data/data/com.termux/files/home/.config.tar.xz
   cd ..
   rm -r 'Windows 10 Red'
   rm Windows.10.Red.tar.xz
   clear
   echo -n "Windows 10 theme (Red, Gaming) Installed Successfully"
   sleep 3
   ;;
4)
   echo -n "Installing Windows 10 theme (Purple, Space) ..."

   wget -q --show-progress -O Windows.10.Purple.tar.xz https://github.com/AGENT404TRD/BOXVIDRA-EMULATOR/releases/download/Themes/Windows.10.Purple.tar.xz
   tar -xf Windows.10.Purple.tar.xz
   cd 'Windows 10 Purple'
   cp -r .icons /data/data/com.termux/files/home/
   cp -r .themes /data/data/com.termux/files/home/
   cp -r APPLICATIONS /data/data/com.termux/files/home
   cp .config.tar.xz /data/data/com.termux/files/home
   tar -xf /data/data/com.termux/files/home/.config.tar.xz -C /data/data/com.termux/files/home
   cp Windows-10-master.zip /data/data/com.termux/files/usr/share/icons
   unzip /data/data/com.termux/files/usr/share/icons/Windows-10-master.zip -d /data/data/com.termux/files/usr/share/icons
   cp -r WALLPAPERS /data/data/com.termux/files/home
   cp -r BOXVIDRA-CFG /data/data/com.termux/files/home
   cp PROGRAMS/* /data/data/com.termux/files/home/Desktop
   rm /data/data/com.termux/files/home/.config.tar.xz
   cd ..
   rm -r 'Windows 10 Purple'
   rm Windows.10.Purple.tar.xz
   clear
   echo -n "Windows 10 theme (Purple, Space) Installed Successfully"
   sleep 3
   ;;
*)
   echo "Invalid option, please select a valid number."
   ;;
esac
    
clear
sleep 2

echo -e "\e[32m[âœ“] Boxvidra Emulator Installed Successfully.\e[0m"
echo -e "\n"
echo "Type \"boxvidra\" To Start"



