#!/bin/bash -e
# this bash script will loop through all the .sh files under bin
# execute the script and check the result (exit code) to see if
# there's any error

echo "IMPORTANT: this script should be run by the CI (e.g. Jenkins) only. There's no need to run this script to update Petstore samples for all generators."
echo "Please press CTRL+C to stop or the script will continue in 10 seconds."

sleep 10

for SCRIPT in `ls -l ./bin/*.sh | grep -v all`
do
    if [ -f $SCRIPT -a -x $SCRIPT ]
    then
        $SCRIPT
        rc=$?
        if [[ $rc != 0 ]]
        then
            echo "ERROR!! FAILED TO RUN $SCRIPT"
            exit $rc;
        fi
    fi
done
