2023-10-14 15:59:11 -04:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2023-12-17 16:18:19 -05:00
|
|
|
set -e
|
2023-10-14 15:59:11 -04:00
|
|
|
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
2023-12-17 16:18:19 -05:00
|
|
|
: ${RETRY_DELAYS:=1 1 5 5 15 30}
|
|
|
|
|
|
|
|
function retry() {
|
|
|
|
local tmp=/tmp
|
|
|
|
rm -f $tmp/retry.out
|
|
|
|
success=false
|
|
|
|
for delay in $RETRY_DELAYS ; do
|
|
|
|
if "$@" >> $tmp/retry.out 2>&1 ; then
|
|
|
|
success=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
cat $tmp/retry.out
|
|
|
|
echo waiting $delay
|
|
|
|
sleep $delay
|
|
|
|
done
|
|
|
|
if test $success = false ; then
|
|
|
|
cat $tmp/retry.out
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function stop_daemon() {
|
|
|
|
local daemon=$1
|
|
|
|
local dir=${2:-.}
|
|
|
|
|
|
|
|
if test -f $dir/$daemon-pid ; then
|
|
|
|
local pid=$(cat $dir/$daemon-pid)
|
|
|
|
kill -TERM $pid
|
|
|
|
pidwait $pid || true
|
|
|
|
for delay in 1 1 2 2 5 5 ; do
|
|
|
|
if ! test -f $dir/$daemon-pid ; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep $delay
|
|
|
|
done
|
|
|
|
! test -f $dir/$daemon-pid
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-10-14 15:59:11 -04:00
|
|
|
function dependency_go() {
|
2023-11-09 10:02:08 -05:00
|
|
|
go_version="1.21.4.linux-amd64" # Set the desired Go version here
|
2023-10-14 15:59:11 -04:00
|
|
|
|
|
|
|
if ! which wget tar > /dev/null ; then
|
|
|
|
apt-get install -y -qq wget tar
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! which go > /dev/null ; then
|
|
|
|
wget --quiet "https://go.dev/dl/go$go_version.tar.gz"
|
|
|
|
tar zxf "go$go_version.tar.gz"
|
|
|
|
export PATH="$(pwd)/go/bin:$PATH"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkout() {
|
|
|
|
local git="$1"
|
2023-11-04 09:44:18 -04:00
|
|
|
git clone $git forgejo-runner
|
2023-10-14 15:59:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function build_runner() {
|
|
|
|
local git="$1"
|
|
|
|
local version="${2:-main}"
|
|
|
|
local dir=$(mktemp -d)
|
|
|
|
(
|
|
|
|
cd $dir
|
|
|
|
checkout "$git"
|
|
|
|
dependency_go
|
|
|
|
cd forgejo-runner
|
|
|
|
git checkout "$version"
|
|
|
|
make build
|
|
|
|
)
|
2023-11-04 11:29:25 -04:00
|
|
|
mv $dir/forgejo-runner/forgejo-runner /usr/local/bin
|
|
|
|
forgejo-runner --version
|
2023-10-14 15:59:11 -04:00
|
|
|
rm -fr "$dir"
|
|
|
|
}
|