#!/bin/bash
cd /root/xplayer-ota
git restore .
git pull

# Download and extract files before running ansible-playbook
if [ -f "files_download.txt" ]; then
    echo "Downloading files from files_download.txt..."
    while IFS= read -r url; do
        if [ -n "$url" ]; then
            filename=$(basename "$url")
            echo "Downloading $filename..."
            wget -O "$filename" "$url"
            if [ $? -eq 0 ]; then
                echo "Extracting $filename..."
                tar -xJf "$filename"
                rm -f "$filename"
            else
                echo "Failed to download $url"
            fi
        fi
    done < files_download.txt
fi

ansible-playbook playbooks/site.yml -e force_update=true
