#!/bin/bash

# Check if PHP is installed
if ! command -v php &> /dev/null; then
    echo "Erreur: PHP n'est pas installé sur votre système. Merci d'installer PHP et relancer ce script."
    exit 1
fi

# Task 1: Unzip a file with a specific word in its name
unzip_file_with_keyword() {
    keyword="$1"
    found=false

    for file in *.zip; do
        if [[ "$file" == *"$keyword"* ]]; then
            found=true
            unzip "$file"
            echo "L'archive d'installation '$file' a bien été décompressée."
        fi
    done

    if [ "$found" != true ]; then
        echo "Erreur :  aucune archive d'installation n'a été trouvée."
        exit 1
    fi
}

# Task 2: Delete a folder
delete_folder() {
    if [ -d "$1" ]; then
        rm -r "$1"
        echo "Le dossier de cache '$1' a bien été supprimé."
    else
        echo "Error: Folder '$1' not found."
    fi
}

# Task 3: Execute a system command
execute_system_command() {
    echo "Execution de la commande système : $1"
    eval "$1"
}

# Uncomment and modify the lines below as needed.

unzip_file_with_keyword "sst_v"
delete_folder "var/cache/prod"
execute_system_command "php bin/console doctrine:migration:migrate --no-interaction"