This repository has been archived on 2024-08-09. You can view files and clone it, but cannot push or open issues or pull requests.
joomla/bin/gitea_secrets.sh

39 lines
1.0 KiB
Bash
Raw Normal View History

#!/bin/bash
# Load environment variables from .env file
if [ -f ".env" ]; then
set -o allexport
source .env
set +o allexport
else
echo "Error: The .env file does not exist."
exit 1
fi
USERNAME=""
PASSWORD=""
read -p "Enter your Gitea username: " USERNAME
read -s -p "Enter your Gitea password: " PASSWORD
echo
secrets_response=$(curl -s -u "$USERNAME:$PASSWORD" "$GITEA_API/repos/$REPO_OWNER/$REPO_NAME/actions/secrets")
status_code=$(tail -c 3 <<< "$secrets_response")
if [[ $status_code -eq 401 ]]; then
echo "Authentication failed. Please check your username and password."
exit 1
fi
# Get the secret keys
secret_keys=$(echo "$secrets_response" | jq -r '.[].name')
# Loop through secret keys
for secret_key in $secret_keys; do
secret_response=$(curl -s -u "$USERNAME:$PASSWORD" "$GITEA_API/repos/$REPO_OWNER/$REPO_NAME/actions/secrets/$secret_key")
secret_value=$(echo "$secret_response" | jq -r '.secret')
# Update .env file
sed -i "s/$secret_key=.*/$secret_key=$secret_value/" .env
done