67 lines
2.1 KiB
Bash
67 lines
2.1 KiB
Bash
#!/bin/bash
|
|
TOKEN_FILE="/var/lib/gitea/workflow-pr.token"
|
|
|
|
# Wait for the token file to be created by the gitea setup script
|
|
echo "Waiting for $TOKEN_FILE..."
|
|
while [ ! -s "$TOKEN_FILE" ]; do
|
|
sleep 2
|
|
done
|
|
|
|
# Read token and trim whitespace/newlines
|
|
GITEA_TOKEN=$(cat "$TOKEN_FILE" | tr -d '\n\r ' )
|
|
|
|
if [ -z "$GITEA_TOKEN" ]; then
|
|
echo "Error: Token file $TOKEN_FILE is empty after trimming."
|
|
exit 1
|
|
fi
|
|
|
|
export GITEA_TOKEN
|
|
echo "GITEA_TOKEN exported (length: ${#GITEA_TOKEN})"
|
|
|
|
# Wait for the dummy data to be created by the gitea setup script
|
|
echo "Waiting for workflow.config in products/SLFO..."
|
|
API_URL="http://gitea-test:3000/api/v1/repos/products/SLFO/contents/workflow.config"
|
|
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GITEA_TOKEN" "$API_URL")
|
|
|
|
while [ "$HTTP_STATUS" != "200" ]; do
|
|
echo "workflow.config not found yet (HTTP Status: $HTTP_STATUS). Retrying in 5s..."
|
|
sleep 5
|
|
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GITEA_TOKEN" "$API_URL")
|
|
done
|
|
|
|
# Wait for the shared SSH key to be generated by the gitea setup script
|
|
echo "Waiting for /var/lib/gitea/ssh-keys/id_ed25519..."
|
|
while [ ! -f /var/lib/gitea/ssh-keys/id_ed25519 ]; do
|
|
sleep 2
|
|
done
|
|
|
|
export AUTOGITS_IDENTITY_FILE="/root/.ssh/id_ed25519"
|
|
|
|
# Pre-populate known_hosts with Gitea's SSH host key
|
|
echo "Preparing SSH environment in /root/.ssh..."
|
|
mkdir -p /root/.ssh
|
|
chmod 700 /root/.ssh
|
|
|
|
# Copy the private key to the standard location and set permissions
|
|
cp /var/lib/gitea/ssh-keys/id_ed25519 /root/.ssh/id_ed25519
|
|
chmod 600 /root/.ssh/id_ed25519
|
|
|
|
echo "Scanning Gitea SSH host key..."
|
|
# We try multiple times because Gitea might still be starting its SSH server
|
|
for i in {1..10}; do
|
|
ssh-keyscan -p 3022 gitea-test >> /root/.ssh/known_hosts 2>/dev/null && break
|
|
echo "Retrying ssh-keyscan in 2s..."
|
|
sleep 2
|
|
done
|
|
chmod 644 /root/.ssh/known_hosts
|
|
|
|
exe=$(which workflow-pr)
|
|
exe=${exe:-/usr/local/bin/workflow-pr}
|
|
|
|
package=$(rpm -qa | grep autogits-workflow-pr) || :
|
|
|
|
echo "!!!!!!!!!!!!!!!! using binary $exe; installed package: $package"
|
|
which strings > /dev/null 2>&1 && strings "$exe" | grep -A 2 vcs.revision= | head -4 || :
|
|
|
|
exec "$exe" "$@"
|