From 418489ad4fa5433438e0191ec94bd7ed73f97648 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 20 Dec 2023 22:22:14 +0100 Subject: [PATCH] no longer use /usr/local/bin --- .forgejo/workflows/integration-scripts.yml | 2 +- action.yml | 2 +- forgejo-lib.sh | 10 ++++++---- forgejo-runner.sh | 14 +++++++------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.forgejo/workflows/integration-scripts.yml b/.forgejo/workflows/integration-scripts.yml index 876fbfe..dce0a49 100644 --- a/.forgejo/workflows/integration-scripts.yml +++ b/.forgejo/workflows/integration-scripts.yml @@ -48,7 +48,7 @@ jobs: LXC_IP_PREFIX=10.0.10 forgejo-dependencies.sh forgejo-binary.sh ensure_user forgejo - chown forgejo $DIR /usr/local/bin + chown forgejo $DIR su -c "DIR=$DIR bash -x forgejo-binary.sh setup root admin1234 ${{ matrix.binary }}" forgejo su -c "DIR=$DIR bash -x forgejo-runner.sh setup" forgejo diff --git a/action.yml b/action.yml index 44e27e3..53af620 100644 --- a/action.yml +++ b/action.yml @@ -98,7 +98,7 @@ runs: fi if test "${{ inputs.binary }}"; then forgejo-binary.sh ensure_user forgejo - chown forgejo $(pwd) /usr/local/bin + chown forgejo $(pwd) su -c "DIR=$(pwd) forgejo-binary.sh setup ${{ inputs.user }} ${{ inputs.password }} ${{ inputs.binary }}" forgejo su -c "DIR=$(pwd) forgejo-runner.sh setup ${{ inputs.runner }} ${{ inputs.runner-version }} $(cat forgejo-url)" forgejo else diff --git a/forgejo-lib.sh b/forgejo-lib.sh index 7269a4c..108ed75 100644 --- a/forgejo-lib.sh +++ b/forgejo-lib.sh @@ -66,16 +66,18 @@ function checkout() { function build_runner() { local git="$1" local version="${2:-main}" - local dir=$(mktemp -d) + local dir="$3" + + local tmp=$(mktemp -d) ( - cd $dir + cd $tmp checkout "$git" dependency_go cd forgejo-runner git checkout "$version" make build ) - mv $dir/forgejo-runner/forgejo-runner /usr/local/bin + mv $tmp/forgejo-runner/forgejo-runner $dir forgejo-runner --version - rm -fr "$dir" + rm -fr "$tmp" } diff --git a/forgejo-runner.sh b/forgejo-runner.sh index cc61d08..68dbc89 100755 --- a/forgejo-runner.sh +++ b/forgejo-runner.sh @@ -20,12 +20,12 @@ function download() { local runner_repository="$1" local version="$2" - if ! which forgejo-runner > /dev/null; then - if ! curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-${version#v}-linux-amd64 > /usr/local/bin/forgejo-runner ; then + if ! which $DIR/forgejo-runner > /dev/null; then + if ! curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-${version#v}-linux-amd64 > $DIR/forgejo-runner ; then # backward compatibility for for the naming scheme prior to 3.0.0 - curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-linux-amd64 > /usr/local/bin/forgejo-runner + curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-linux-amd64 > $DIR/forgejo-runner fi - chmod 755 /usr/local/bin/forgejo-runner + chmod 755 $DIR/forgejo-runner fi } @@ -35,7 +35,7 @@ function register() { $DIR/forgejocli actions generate-runner-token | tee $DIR/forgejo-runner-token ( cd $DIR - timeout --signal=KILL 30 forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat $DIR/forgejo-runner-token) --labels docker:docker://code.forgejo.org/oci/node:20-bookworm,ubuntu-latest:docker://code.forgejo.org/oci/node:20-bookworm,self-hosted:lxc://debian:bookworm + timeout --signal=KILL 30 $DIR/forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat $DIR/forgejo-runner-token) --labels docker:docker://code.forgejo.org/oci/node:20-bookworm,ubuntu-latest:docker://code.forgejo.org/oci/node:20-bookworm,self-hosted:lxc://debian:bookworm ) } @@ -44,7 +44,7 @@ function run() { daemon --chdir=$DIR --unsafe \ --env="TERM=$TERM" --env="HOME=$(cat $DIR/forgejo-runner-home)" --env="PATH=$PATH" --env="USER=$USER" --env="TERM=dumb" --env="USERNAME=$USERNAME" --env="LANG=$LANG" \ --pidfile=$DIR/forgejo-runner-pid --errlog=$DIR/forgejo-runner.log --output=$DIR/forgejo-runner.log -- \ - forgejo-runner --config $FORGEJO_RUNNER_CONFIG daemon + $DIR/forgejo-runner --config $FORGEJO_RUNNER_CONFIG daemon sleep 1 cat $DIR/forgejo-runner.log } @@ -64,7 +64,7 @@ function setup() { dependencies if [[ "$version" =~ ^@ ]] ; then local branch=${version##@} - build_runner $runner_repository $branch + build_runner $runner_repository $branch $DIR else download $runner_repository $version fi