Skip to content

Instantly share code, notes, and snippets.

@kyletaylored
Last active September 23, 2022 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyletaylored/b850e9c8c94b26b34ec54d5a564444c9 to your computer and use it in GitHub Desktop.
Save kyletaylored/b850e9c8c94b26b34ec54d5a564444c9 to your computer and use it in GitHub Desktop.
Check is sites in an organization have a primary domain assigned.
#!/bin/bash
# Example
# ./terminus-org-primary-domain.sh <ORG_ID>
# Exit on error
set -e
ORG_ID=$1
TEMP_FILE=$(echo "/tmp/$ORG_ID-primary-domains.csv")
SITES=$(terminus org:site:list $ORG_ID --format list --field name | sort -V)
echo "site_id,primary_set" > $TEMP_FILE
# Loop through sites
for SITE in $SITES; do
echo "Processing... $SITE"
# Set default
HAS_PRIMARY_DOMAIN="false"
# Get domains
DOMAINS=$(terminus domain:list $SITE.live --format json)
DOMAIN_PARTS=$(echo $DOMAINS | jq -c '.[]')
# Process domains
while read i; do
domain=$(echo $i | jq -r '.id')
primary_check=$(echo $i | jq -r 'select(.primary)')
if [[ -n $primary_check ]]; then
HAS_PRIMARY_DOMAIN="true"
fi
done <<<$(echo $DOMAIN_PARTS)
echo "$SITE,$HAS_PRIMARY_DOMAIN" >> $TEMP_FILE
done
echo "Complete: $TEMP_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment