#!/bin/bash

action=$1
patch_report=/tmp/patch_report
rm -f $"patch_report"
source /usr/lib/eole/ihm.sh

for patch_file in /usr/share/eole/backport-patches.d/*.patch
do
    if [ -e "$patch_file" ]
    then
        output=$(/usr/bin/patch --dry-run --fuzz=0 -u -N --reject-file=- -p0 -d/ -i $patch_file)
        res=$?
        file_path=$(echo $output | sed 's;checking file \(\(/[[:punct:][:alnum:]]\+\)\+\) .*;\1;')
        if [ "$res" != 0 ] && [[ "$output" =~ "FAILED" ]]
        then
            EchoRouge "Patch de $file_path échoué"
        else
            /usr/bin/patch --fuzz=0 -u -N --reject-file=- -p0 -d/ -i "$patch_file" >> "$patch_report" 2>&1
        fi

    fi
done

exit 0
