|
#!/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 $@; |