Skip to content

Instantly share code, notes, and snippets.

@mindfullsilence
Created July 10, 2024 16:25
Show Gist options
  • Save mindfullsilence/c91123b4eec76d4a4c259e2fb973f0d7 to your computer and use it in GitHub Desktop.
Save mindfullsilence/c91123b4eec76d4a4c259e2fb973f0d7 to your computer and use it in GitHub Desktop.
Mac: Send a text and notification when a domain has propagated

Propagate

A very simple script to add to your bash/zsh profile that shows a notification on your mac, and sends you a text message when a domain has propagated. Let's you know when to issue an SSL certificate. Great for LetsEncrypt SSL as you cannot pass the LetsEncrypt challenge until a domain has propagated.

Requirements

  • Only works on MacOS.
  • Requires alerter to be installed for sending notifications.
  • Requires dig - but this comes with macos so you shouldn't need to do anything there.

Installation

Add the above script to your ~/.profile or ~/.zprofile or wherever you store your terminal profile. Then close and re-open your terminal, or simply call source ~/.profile to load in the new functionality.

Usage

Usage is very simple, call the propagate in your terminal function with 3 arguments: the bare domain, the IP address it should point to, and your Messages id (usually your apple account email).

propagate somedomain.com 123.456.789.10 [email protected]

Recommendations:

Always launch to the same server? Add it as a variable to your bash profile for easy reference. Do the same for your iCloud ID as well:

# ~/.profile
shared_server="123.456.789.10"
icloud_id="[email protected]"

Much easier to remember when calling the command:

propagate somedomain.com $shared_server $icloud_id

Alternatively, just hardcode these values into the propagate function itself so you only have to add 1 argument:

propagate somedomain.com

I have multiple servers, so I just check them within the propagate function (just before the while loop) and reassign as necessary. E.g.:

if [[ "$server" == "shared_server" ]]; then
  server="123.456.789.10"
fi

With my Messages ID hardcoded, and my server IPs aliased via multiple if statement like above, my command beomes thus:

propagate somedomain.com shared_server

function sms() {
message="$1"
recipient="$2"
final_message="tell application \"Messages\" to send \"$message\" to buddy \"$recipient\""
osascript -e "$final_message";
}
function propagate() {
site="$1"
server="$2"
recipient="$3"
ip=$(dig +short "$site")
title="$site is propagated!"
message="Go issue a TLS certificate in $server"
while [[ "$ip" != "$server" ]]; do
ip=$(dig +short "$site")
sleep 1;
done
sms "$message for $site" "$recipient";
alertAnswer="$(alerter -title "$title" -message "$message" -sound Sonar)"
case $alertAnswer in
"@TIMEOUT") ;;
"@CLOSED") ;;
"@CONTENTCLICKED") open "https://$1" ;;
"@ACTIONCLICKED") open "https://$1" ;;
**) echo "? --> $ANSWER" ;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment