#!/bin/sh

set -xe

function usage() {
  echo "Usage: <netlify_auth_token> <site_name>"
  exit 1
}

function slug() {
  echo $1 | sed -E s/[^a-zA-Z0-9]+/-/g | sed -E s/^-+\|-+$//g | tr A-Z a-z
}

function get_site_id() {
  netlify sites:list --json | jq --raw-output ".[] | select(.name==\"$1\") | .id"
}

if [ -z "$1" ] || [ -z "$2" ]; then
  usage
fi

export NETLIFY_AUTH_TOKEN=$1
site_name=$2


echo "searching site ${site_name}"

clean_site_name=$(slug $site_name)
site_id=$(get_site_id $clean_site_name)

echo "deleting site"

netlify sites:delete --force "${site_id}"

#!/bin/sh

set -xe

function usage() {
  echo "Usage: <netlify_auth_token> <site_name>"
  exit 1
}

function slug() {
  echo $1 | sed -E s/[^a-zA-Z0-9]+/-/g | sed -E s/^-+\|-+$//g | tr A-Z a-z
}

function get_site_id() {
  netlify sites:list --json | jq --raw-output ".[] | select(.name==\"$1\") | .id"
}

if [ -z "$1" ] || [ -z "$2" ]; then
  usage
fi

export NETLIFY_AUTH_TOKEN=$1
site_name=$2


echo "searching site ${site_name}"

clean_site_name=$(slug $site_name)
site_id=$(get_site_id $clean_site_name)

if [ -z "$site_id" ]; then
  echo "site already deleted"
else
  echo "deleting site"

  netlify sites:delete --force "${site_id}"
fi

Check if site_id is empty and skip delete command
Check if site_id is empty and skip delete command

Signed-off-by: Stefan Scherer <c4a78f471cbb65d3c8ad267a930132b89ad6d2ce@docker.com>
