Skip to content

Instantly share code, notes, and snippets.

@unacceptable
Last active February 27, 2019 08:19
Show Gist options
  • Save unacceptable/8e7c189acbe1ba6b523fef5de97adb54 to your computer and use it in GitHub Desktop.
Save unacceptable/8e7c189acbe1ba6b523fef5de97adb54 to your computer and use it in GitHub Desktop.
This leverages the AWS CLI to easily check availability and order a domain.

Order domain.sh

Description

Have you ever wished that there was an easy way to order domains via the command line? Look no further! You can check a domain's availability and order it via this utility.

Prerequisits

Install the AWS CLI

macOS

brew install awscli

RHEL based Systems

yum install awscli

Debian based Systems

apt install awscli

Congifure creds (or you could attach a role if on an EC2 instance)

aws configure

Usage examples

Unavailable Domain

20:39 Mac Shell: Downloads/>$ order_domain example.com
UNAVAILABLE

Error Encountered:
------------------
Domain is not for sale
20:39 Mac Shell: Downloads/>$

Available Domain

20:39 Mac Shell: Downloads/>$ order_domain SuperAwesomeDomainThatIWouldLikeToBuy.io

It would seem that the following domain is for sale:
----------------------------------------------------
SuperAwesomeDomainThatIWouldLikeToBuy.io

Would you like to buy SuperAwesomeDomainThatIWouldLikeToBuy.io? [y/n] n

Error Encountered:
------------------
Canceling domain registration
20:41 Mac Shell: Downloads/>$
#!/bin/bash
set -e
# Written by: Robert J.
#######################################
### Info Function #####################
#######################################
AWS_DEFAULT_REGION=us-east-1
domain="$1"
Contact_Info="FirstName="'"Robert"'", \
LastName="'"J."'", \
ContactType="'"PERSON"'", \
OrganizationName="'"Script My Job"'", \
AddressLine1="'"1600 Pennsylvania Ave."'", \
AddressLine2="'"#1234"'", \
City="'"Washington"'", \
State="'"DC"'", \
CountryCode="'"US"'", \
ZipCode=20006, \
PhoneNumber="'"+1.1234567890"'", \
Email="'"email@email.com"'"
"
#######################################
### Main Function #####################
#######################################
main_function(){
domain_check;
domain_validation;
}
#######################################
### Generic Functions #################
#######################################
helpcheck(){
for arg in "$@"; do
[[ "$arg" == "--help" || "$arg" == "-h" ]] && {
disphelp;
die "" 0 --nosep
};
done
[[ -z "${1}" ]] && {
disphelp &&
die "Invalid Syntax" 1;
} || {
return 0;
};
};
print(){
# opted against $_ and $! for this usage
last="${!#}"
output="$1";
size="${#output}";
# Colors pulled from ansi-color script
######################################
case "$2" in
red)
color="196"
;;
orange)
color="202"
;;
yellow)
color="226"
;;
green)
color="46"
;;
blue)
color="27"
;;
indigo)
color="21"
;;
violet)
color="54"
;;
grey)
color="8"
;;
*)
color="0"
;;
esac
printf -v sep "%${size}s" "-";
[[ "$last" == "--nosep" ]] && {
printf "\e[38;5;%dm%s\e[0m\n" "$color" "$output";
return;
};
printf "\n\e[38;5;%dm%s\e[0m\n%s\n" "$color" "$output" "${sep// /-}";
};
die(){
message="${1}"
exit_code="${2}"
[[ -z "$exit_code" ]] && {
exit_code=1;
};
# determine if exit code is an integer
[[ -z ${exit_code//[0-9]/} ]] || {
print "Invalid exit code specified in script: $exit_code\n" yellow --nosep
exit_code=255;
};
[[ "$exit_code" -gt 0 ]] && {
print "Error Encountered:" "red";
};
print "${message}" "yellow" "--nosep";
exit "$exit_code";
};
#######################################
### Program Specific Functions ########
#######################################
domain_check(){
availability=$(
aws route53domains check-domain-availability \
--domain-name "$domain"
)
printf "%s" "$availability" | grep "UNAVAILABLE" &&
die "Domain is not for sale" 1;
return 0;
};
domain_registration(){
aws route53domains register-domain \
--domain-name "$domain" \
--duration-in-years 1 \
--auto-renew \
--admin-contact "$Contact_Info" \
--registrant-contact "$Contact_Info" \
--tech-contact "$Contact_Info" \
--privacy-protect-admin-contact \
--privacy-protect-registrant-contact
}
domain_validation(){
print "It would seem that the following domain is for sale:" green
print "$domain" grey --nosep
print "" --nosep
read -rp "Would you like to buy $domain? [y/n] " bool_logic;
printf "%s" "$bool_logic" | grep -i "y" ||
die "Canceling domain registration" 2
domain_registration ||
die "There seems to have been an error with this script" 128
}
#######################################
### Execution #########################
#######################################
# variable deliberately not quoted to keep arguments independent
main_function $@;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment