#!/bin/bash

# Update package lists
apt update



# Clone the roop repository
git clone https://github.com/C0untFloyd/roop-unleashed

# Change directory to roop
cd roop-unleashed

# Checkout a specific commit - you can remove this line to install latest version
#git checkout 3d02b267663e4badc5c7936d5295effcae3dfbc0

# Create a Python virtual environment
python3 -m venv venv

# Activate the virtual environment
source venv/bin/activate

# Install onnxruntime-gpu and requirements
pip install -r requirements.txt

pip uninstall torchaudio torchvision torch --yes
pip install torch==2.5.1 xformers==0.0.28.post3 torchaudio torchvision --index-url https://download.pytorch.org/whl/cu124
pip install onnxruntime-gpu==1.20.1

wget https://huggingface.co/MonsterMMORPG/Generative-AI/resolve/main/cuda-keyring_1.1-1_all.deb
dpkg -i cuda-keyring_1.1-1_all.deb
apt-get update
apt-get -y install cudnn
apt-get -y install cudnn-cuda-12

echo 'export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
echo 'export CUDNN_PATH=/usr/lib/x86_64-linux-gnu/libcudnn.so' >> ~/.bashrc
source ~/.bashrc
ldconfig -N -v $(sed 's/:/ /g' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep libcudnn

cd ..
python Fix.py

# Install python3.10-tk package
yes | apt-get install -y python3.10-tk

yes | apt-get install ffmpeg

yes | apt-get install p7zip-full
