All checks were successful
ci/crow/cron/process-updates-alpine-320-arm64 Pipeline was successful
ci/crow/cron/process-updates-redhat-8-arm64 Pipeline was successful
ci/crow/cron/process-updates-redhat-8-amd64 Pipeline was successful
ci/crow/cron/process-updates-alpine-320-amd64 Pipeline was successful
ci/crow/cron/process-updates-ubuntu-2404-amd64 Pipeline was successful
ci/crow/cron/process-updates-redhat-9-arm64 Pipeline was successful
ci/crow/cron/process-updates-alpine-321-amd64 Pipeline was successful
ci/crow/cron/process-updates-ubuntu-2204-amd64 Pipeline was successful
ci/crow/cron/process-updates-redhat-9-amd64 Pipeline was successful
ci/crow/cron/process-updates-ubuntu-2404-arm64 Pipeline was successful
64 lines
1.6 KiB
Shell
64 lines
1.6 KiB
Shell
#!/bin/bash
|
|
|
|
set -o pipefail
|
|
set -x
|
|
|
|
# Function to URL-encode a string using Python
|
|
urlencode() {
|
|
python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1], safe=''))" "$1"
|
|
}
|
|
|
|
# Function to send the purge request using the provided API key
|
|
purge() {
|
|
local api_key="$1"
|
|
local url="$2"
|
|
curl -vL -X POST -H "AccessKey: $api_key" "$url"
|
|
}
|
|
|
|
# Function to generate the purge URLs for a given domain, arch, and OS ID
|
|
generate_urls() {
|
|
local domain="$1"
|
|
local arch="$2"
|
|
local os_id="$3"
|
|
|
|
# Array of resource paths (can be modified or extended as needed)
|
|
local resources=(
|
|
"src/contrib/PACKAGES"
|
|
"src/contrib/PACKAGES.gz"
|
|
"src/contrib/PACKAGES.rds"
|
|
"src/contrib/PACKAGES.db"
|
|
)
|
|
|
|
local urls=()
|
|
for resource in "${resources[@]}"; do
|
|
local target_url="https://${domain}/${arch}/${os_id}/latest/${resource}"
|
|
local encoded
|
|
encoded=$(urlencode "$target_url")
|
|
urls+=( "https://api.bunny.net/purge?url=${encoded}&async=false" )
|
|
done
|
|
|
|
echo "${urls[@]}"
|
|
}
|
|
|
|
# Function to process multiple domains.
|
|
# Usage: process_domains <BUNNYNET_API_KEY> <ARCH> <OS_ID> domain1 [domain2 ... domainN]
|
|
purge_cdn_cache() {
|
|
local api_key="$1"
|
|
local arch="$2"
|
|
local os_id="$3"
|
|
shift 3 # Remove the first three arguments, leaving the domains
|
|
|
|
for domain in "$@"; do
|
|
# Generate the list of URLs for the current domain
|
|
local urls
|
|
urls=($(generate_urls "$domain" "$arch" "$os_id"))
|
|
|
|
# Purge each URL
|
|
for url in "${urls[@]}"; do
|
|
purge "$api_key" "$url"
|
|
done
|
|
done
|
|
}
|
|
|
|
# Example usage:
|
|
# purge_cdn_cache "$BUNNYNET_API_KEY" "$ARCH" "$OS_ID" "domain1.com" "domain2.com"
|