#!/bin/bash

EXIT_CODE=0
SCRIPT_DIR=$(dirname "$0")
PATCHES_DIR="$SCRIPT_DIR/patches"

if [[ ! -d "$PATCHES_DIR" ]]; then
    echo "[-] Error: directory with patches not found: $PATCHES_DIR"
    exit 1
fi

for patch_file in "$PATCHES_DIR"/*.sh; do
    if [ -f "$patch_file" ] && [ -x "$patch_file" ]; then
        "$patch_file" "$1"
        if [ $? -eq 2 ]; then
            EXIT_CODE=2
        fi
    fi
done

exit $EXIT_CODE
