mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
0661c74880
These come originally from https://github.com/travis-ci/travis-build and are available when running on Travis, but not when running inside a Docker container on Travis as we do in order to build for Android. The goal is to provide a quasi heart-beat on STDOUT during very long running commands - without this the wget to download Qt often times out, so that's where we are going to use this. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
65 lines
1.2 KiB
Bash
65 lines
1.2 KiB
Bash
#!/bin/bash
|
|
# SPDX-License-Identifier: MIT
|
|
# SPDX-Copyright: Copyright (c) 2016 Travis CI GmbH <contact@travis-ci.org>
|
|
#
|
|
# this is based on code from https://github.com/travis-ci/travis-build
|
|
|
|
travis_wait() {
|
|
local timeout=$1
|
|
|
|
if [[ $timeout =~ ^[0-9]+$ ]]; then
|
|
# looks like an integer, so we assume it is a timeout
|
|
shift
|
|
else
|
|
# default value
|
|
timeout=20
|
|
fi
|
|
|
|
local cmd="$@"
|
|
local log_file=travis_wait_$$.log
|
|
|
|
$cmd &>$log_file &
|
|
local cmd_pid=$!
|
|
|
|
travis_jigger $! $timeout $cmd &
|
|
local jigger_pid=$!
|
|
local result
|
|
|
|
{
|
|
wait $cmd_pid 2>/dev/null
|
|
result=$?
|
|
ps -p$jigger_pid &>/dev/null && kill $jigger_pid
|
|
}
|
|
|
|
if [ $result -eq 0 ]; then
|
|
echo -e "\nThe command $cmd exited with $result."
|
|
else
|
|
echo -e "\nThe command $cmd exited with $result."
|
|
fi
|
|
|
|
echo -e "\nLog:\n"
|
|
cat $log_file
|
|
|
|
return $result
|
|
}
|
|
|
|
travis_jigger() {
|
|
# helper method for travis_wait()
|
|
local cmd_pid=$1
|
|
shift
|
|
local timeout=$1 # in minutes
|
|
shift
|
|
local count=0
|
|
|
|
# clear the line
|
|
echo -e "\n"
|
|
|
|
while [ $count -lt $timeout ]; do
|
|
count=$(($count + 1))
|
|
echo -ne "Still running ($count of $timeout): $@\r"
|
|
sleep 60
|
|
done
|
|
|
|
echo -e "\nTimeout (${timeout} minutes) reached. Terminating \"$@\"\n"
|
|
kill -9 $cmd_pid
|
|
}
|