#!/bin/bash

ACME_HOME="/root/.acme.sh"
WEBROOT="/opt/data"
DOMAINS_FILE="/opt/domain.txt"

# Read the domain from the domain file
DOMAIN=$(cat $DOMAINS_FILE)

# Generate the challenge files
#~/.acme.sh/acme.sh --issue --debug 2 -d $DOMAIN --webroot $WEBROOT --server https://acme-staging-v02.api.letsencrypt.org/directory --force --config-home $ACME_HOME &
~/.acme.sh/acme.sh --issue --debug 2 -d $DOMAIN --webroot $WEBROOT --server https://acme-v02.api.letsencrypt.org/directory --force --config-home $ACME_HOME &

# PID of the acme.sh process
ACME_PID=$!

# Wait for a few seconds to ensure challenge files are created
sleep 10

# Kill the acme.sh process to prevent verification
kill $ACME_PID

echo "Challenge files have been created in $WEBROOT/.well-known/acme-challenge/"

