Skip to content

Fix domain and subdomain extraction logic.#2

Open
th0mcat wants to merge 2 commits intopradoh97:mainfrom
th0mcat:main
Open

Fix domain and subdomain extraction logic.#2
th0mcat wants to merge 2 commits intopradoh97:mainfrom
th0mcat:main

Conversation

@th0mcat
Copy link
Copy Markdown

@th0mcat th0mcat commented Jan 14, 2026

Thank you very much for creating this script!

Tl;dr: The extraction logic apparently doesn't work for a base domain

I wasn't sure how it worked, so I tried setting a CERTBOT_DOMAIN environment variable and then a global variable directly into the script, which obviously didn't work. I threw it into Gemini (:sigh: sorry!) to have it explain it to me, where it told me this was for Certbot itself and to use the --manual-auth-hook. It also said:

⚠ Important Warning: The Script Logic

There is a logic issue in the specific script you pasted. The lines that extract the domain and subdomain are written in a way that only works for subdomains (e.g., www.example.com).

If you try to use this script for a root domain (e.g., example.com), the variables will fail to populate correctly because the expr match regex expects at least two dots in the string.

The problematic lines:

Bash

# This fails if CERTBOT_DOMAIN is just "example.com"
domain=$(expr match "$CERTBOT_DOMAIN" '.*\.\(.*\..*\)') 
subdomain=$(expr match "$CERTBOT_DOMAIN" '\(.*\)\..*\..*')

How to fix it: If you need this script to work for both example.com and www.example.com, you should replace those two lines with logic that detects the domain structure more intelligently.

Then it provided the following fixes. Feel free to ignore since it's AI slop, but this worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant