setup-forgejo/forgejo-lib.sh

84 lines
1.7 KiB
Bash
Raw Normal View History

#!/bin/bash
# SPDX-License-Identifier: MIT
set -e
export DEBIAN_FRONTEND=noninteractive
: ${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
}
function dependency_go() {
2023-11-09 10:02:08 -05:00
go_version="1.21.4.linux-amd64" # Set the desired Go version here
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
}
function build_runner() {
local git="$1"
local version="${2:-main}"
2023-12-20 16:22:14 -05:00
local dir="$3"
local tmp=$(mktemp -d)
(
2023-12-20 16:22:14 -05:00
cd $tmp
checkout "$git"
dependency_go
cd forgejo-runner
git checkout "$version"
make build
)
2023-12-20 16:22:14 -05:00
mv $tmp/forgejo-runner/forgejo-runner $dir
forgejo-runner --version
2023-12-20 16:22:14 -05:00
rm -fr "$tmp"
}