]> git.ipfire.org Git - thirdparty/systemd.git/blob - travis-ci/managers/travis_wait.bash
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[thirdparty/systemd.git] / travis-ci / managers / travis_wait.bash
1 # This was borrowed from https://github.com/travis-ci/travis-build/tree/master/lib/travis/build/bash
2 # to get around https://github.com/travis-ci/travis-ci/issues/9979. It should probably be removed
3 # as soon as Travis CI has started to provide an easy way to export the functions to bash scripts.
4
5 travis_jigger() {
6 local cmd_pid="${1}"
7 shift
8 local timeout="${1}"
9 shift
10 local count=0
11
12 echo -e "\\n"
13
14 while [[ "${count}" -lt "${timeout}" ]]; do
15 count="$((count + 1))"
16 echo -ne "Still running (${count} of ${timeout}): ${*}\\r"
17 sleep 60
18 done
19
20 echo -e "\\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"${*}\"${ANSI_RESET}\\n"
21 kill -9 "${cmd_pid}"
22 }
23
24 travis_wait() {
25 local timeout="${1}"
26
27 if [[ "${timeout}" =~ ^[0-9]+$ ]]; then
28 shift
29 else
30 timeout=20
31 fi
32
33 local cmd=("${@}")
34 local log_file="travis_wait_${$}.log"
35
36 "${cmd[@]}" &>"${log_file}" &
37 local cmd_pid="${!}"
38
39 travis_jigger "${!}" "${timeout}" "${cmd[@]}" &
40 local jigger_pid="${!}"
41 local result
42
43 {
44 wait "${cmd_pid}" 2>/dev/null
45 result="${?}"
46 ps -p"${jigger_pid}" &>/dev/null && kill "${jigger_pid}"
47 }
48
49 if [[ "${result}" -eq 0 ]]; then
50 echo -e "\\n${ANSI_GREEN}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}"
51 else
52 echo -e "\\n${ANSI_RED}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}"
53 fi
54
55 echo -e "\\n${ANSI_GREEN}Log:${ANSI_RESET}\\n"
56 cat "${log_file}"
57
58 return "${result}"
59 }