Last active
September 23, 2022 21:28
-
-
Save kyletaylored/b850e9c8c94b26b34ec54d5a564444c9 to your computer and use it in GitHub Desktop.
Check is sites in an organization have a primary domain assigned.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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