add a root-user check, clean up some formatting
This commit is contained in:
parent
190607cf35
commit
16e18662a0
1 changed files with 16 additions and 7 deletions
|
@ -2,7 +2,13 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
## Initial setup
|
# Check if the script is run as root
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
echo "This script must be run as root"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initial setup
|
||||||
if [[ ! -d /data ]]; then
|
if [[ ! -d /data ]]; then
|
||||||
mkdir -p /data
|
mkdir -p /data
|
||||||
fi
|
fi
|
||||||
|
@ -10,7 +16,7 @@ cd /data
|
||||||
|
|
||||||
RUNNER_USERID="${RUNNER_USERID:-1000}"
|
RUNNER_USERID="${RUNNER_USERID:-1000}"
|
||||||
|
|
||||||
## Setup User
|
# Setup User
|
||||||
if id "forgejo-runner" &>/dev/null; then
|
if id "forgejo-runner" &>/dev/null; then
|
||||||
if [[ ! -z "${RUNNER_USERID}" ]]; then
|
if [[ ! -z "${RUNNER_USERID}" ]]; then
|
||||||
echo "Changing UID of forgejo-runner to ${RUNNER_USERID}"
|
echo "Changing UID of forgejo-runner to ${RUNNER_USERID}"
|
||||||
|
@ -20,9 +26,11 @@ else
|
||||||
echo "Creating user forgejo-runner with UID ${RUNNER_USERID}"
|
echo "Creating user forgejo-runner with UID ${RUNNER_USERID}"
|
||||||
adduser --uid "${RUNNER_USERID}" --home /home/forgejo-runner --disabled-password --gecos "" forgejo-runner
|
adduser --uid "${RUNNER_USERID}" --home /home/forgejo-runner --disabled-password --gecos "" forgejo-runner
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Ensure /data is owned by the runner user
|
||||||
chown -R forgejo-runner:forgejo-runner /data
|
chown -R forgejo-runner:forgejo-runner /data
|
||||||
|
|
||||||
## Handle and alter the config file
|
# Handle and alter the config file
|
||||||
if [[ -z "${CONFIG_FILE}" ]]; then
|
if [[ -z "${CONFIG_FILE}" ]]; then
|
||||||
CONFIG_FILE="/data/config.yml"
|
CONFIG_FILE="/data/config.yml"
|
||||||
fi
|
fi
|
||||||
|
@ -37,12 +45,12 @@ if [[ ! -f "${CONFIG_FILE}" ]]; then
|
||||||
sed -i "/^ A_TEST_ENV_NAME_1:/d" ${CONFIG_FILE}
|
sed -i "/^ A_TEST_ENV_NAME_1:/d" ${CONFIG_FILE}
|
||||||
sed -i "/^ A_TEST_ENV_NAME_2:/d" ${CONFIG_FILE}
|
sed -i "/^ A_TEST_ENV_NAME_2:/d" ${CONFIG_FILE}
|
||||||
|
|
||||||
# apply default values for docker
|
# Apply default values for docker
|
||||||
sed -i "/\"labels\":/c\ \"labels\": [\"docker:docker://code.forgejo.org/oci/node:20-bookworm\", \"ubuntu-22.04:docker://catthehacker/ubuntu:act-22.04\"]" ${CONFIG_FILE}
|
sed -i "/\"labels\":/c\ \"labels\": [\"docker:docker://code.forgejo.org/oci/node:20-bookworm\", \"ubuntu-22.04:docker://catthehacker/ubuntu:act-22.04\"]" ${CONFIG_FILE}
|
||||||
|
|
||||||
sed -i "/^ network:/c\ network: host" config.yml
|
sed -i "/^ network:/c\ network: host" ${CONFIG_FILE}
|
||||||
sed -i "/^ privileged:/c\ privileged: true" ${CONFIG_FILE}
|
sed -i "/^ privileged:/c\ privileged: true" ${CONFIG_FILE}
|
||||||
sed -i "/^ options:/c\ options: -v /certs/client:/certs/client" config.yml
|
sed -i "/^ options:/c\ options: -v /certs/client:/certs/client" ${CONFIG_FILE}
|
||||||
sed -i "/^ docker_host:/c\ docker_host: tcp://${DOCKER_HOST}:2376" ${CONFIG_FILE}
|
sed -i "/^ docker_host:/c\ docker_host: tcp://${DOCKER_HOST}:2376" ${CONFIG_FILE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -51,6 +59,7 @@ if [[ ! -z "${ENV_FILE}" ]]; then
|
||||||
else
|
else
|
||||||
ENV_FILE="/data/.env"
|
ENV_FILE="/data/.env"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f "${ENV_FILE}" ]]; then
|
if [[ ! -f "${ENV_FILE}" ]]; then
|
||||||
echo "Creating ${ENV_FILE} and populating with default values"
|
echo "Creating ${ENV_FILE} and populating with default values"
|
||||||
cat <<EOF > ${ENV_FILE}
|
cat <<EOF > ${ENV_FILE}
|
||||||
|
@ -59,7 +68,6 @@ if [[ ! -f "${ENV_FILE}" ]]; then
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
EXTRA_ARGS=""
|
EXTRA_ARGS=""
|
||||||
if [[ ! -z "${RUNNER_LABELS}" ]]; then
|
if [[ ! -z "${RUNNER_LABELS}" ]]; then
|
||||||
EXTRA_ARGS="${EXTRA_ARGS} --labels ${RUNNER_LABELS}"
|
EXTRA_ARGS="${EXTRA_ARGS} --labels ${RUNNER_LABELS}"
|
||||||
|
@ -101,6 +109,7 @@ if [[ ! -s "${RUNNER_FILE}" ]]; then
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Prevent reading the token from the forgejo-runner process
|
# Prevent reading the token from the forgejo-runner process
|
||||||
unset RUNNER_TOKEN
|
unset RUNNER_TOKEN
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue