[3597] | 1 | #!/usr/bin/env kmk_ash
|
---|
| 2 | # $Id: retry-10-delay-500ms.sh 3597 2023-06-16 20:56:17Z bird $
|
---|
| 3 | ## @file
|
---|
| 4 | # kBuild Helper Script - Retry execution of command 10 times with 0.5 seconds delay.
|
---|
| 5 | #
|
---|
| 6 |
|
---|
| 7 | #
|
---|
| 8 | # Copyright (c) 2023 knut st. osmundsen <bird-kBuild-spam-xxiii@anduin.net>
|
---|
| 9 | #
|
---|
| 10 | # This file is part of kBuild.
|
---|
| 11 | #
|
---|
| 12 | # kBuild is free software; you can redistribute it and/or modify
|
---|
| 13 | # it under the terms of the GNU General Public License as published by
|
---|
| 14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | # (at your option) any later version.
|
---|
| 16 | #
|
---|
| 17 | # kBuild is distributed in the hope that it will be useful,
|
---|
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | # GNU General Public License for more details.
|
---|
| 21 | #
|
---|
| 22 | # You should have received a copy of the GNU General Public License
|
---|
| 23 | # along with kBuild; if not, write to the Free Software
|
---|
| 24 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 25 | #
|
---|
| 26 | #
|
---|
| 27 | # As a special exception you are granted permission to include this file, via
|
---|
| 28 | # the kmk include directive, as you wish without this in itself causing the
|
---|
| 29 | # resulting makefile, program or whatever to be covered by the GPL license.
|
---|
| 30 | # This exception does not however invalidate any other reasons why the makefile,
|
---|
| 31 | # program, whatever should not be covered the GPL.
|
---|
| 32 | #
|
---|
| 33 | #
|
---|
| 34 |
|
---|
| 35 | # First try...
|
---|
| 36 | "$@" && exit 0
|
---|
| 37 | MY_EXITCODE=$?
|
---|
| 38 |
|
---|
| 39 | # Retry up to five times with a little delay between each.
|
---|
| 40 | for MY_RETRY in 1 2 3 4 5 6 7 8 9;
|
---|
| 41 | do
|
---|
| 42 | echo "retry-10-delay-500ms.sh: Retry #${MY_RETRY} failed: ${MY_EXITCODE} (cmd: $*)"
|
---|
| 43 | kmk_sleep 500ms
|
---|
| 44 | "$@" && exit 0
|
---|
| 45 | MY_EXITCODE=$?
|
---|
| 46 | done
|
---|
| 47 | echo "retry-10-delay-500ms.sh: Giving up after 10 tries: ${MY_EXITCODE} (cmd: $*)" >&2
|
---|
| 48 | exit ${MY_EXITCODE}
|
---|
| 49 |
|
---|