Skip to content

Instantly share code, notes, and snippets.

@josephfusco
Created November 18, 2017 15:52
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 josephfusco/734135c51b9ea2f2b3c9fd489b60d72a to your computer and use it in GitHub Desktop.
Save josephfusco/734135c51b9ea2f2b3c9fd489b60d72a to your computer and use it in GitHub Desktop.
Script that creates a new CNAME entry on a domain in DigitalOcean & creates a new ServerPilot application.
#!/bin/bash -e
DO_TOKEN_KEY="" # DigitalOcean token key
SP_CLIENTID="" # ServerPilot API Client ID
SP_APIKEY="" # ServerPilot API Key
SP_SYSUSERID="" # Systemuser ID for the specific server
PRODUCTION_ADMIN_USER="" # Your WordPress admin username
PRODUCTION_ADMIN_PASSWORD="" # Your WordPress admin user password
PRODUCTION_ADMIN_EMAIL="" # Your WordPress admin user email
PRODUCTION_PHP_VERSION="7.1" # PHP Version for site
PRODUCTION_DOMAIN="" # Domain that exists in DigitalOcean networking area that we are making a CNAME entry on.
# --------------------------------------------------------------------------------------------------------------------
clear
# accept the name of our website
echo "Choose a name for the site (one word all lowercase): "
read -e SITENAME
# add cname in digitalocean
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $DO_TOKEN_KEY" -d "{\"type\":\"CNAME\",\"name\":\"${SITENAME}\",\"data\":\"@\",\"priority\":null,\"port\":null,\"ttl\":1800,\"weight\":null}" "https://api.digitalocean.com/v2/domains/$PRODUCTION_DOMAIN/records"
# create serverpilot app based on sitename
curl https://api.serverpilot.io/v1/apps \
-u $SP_CLIENTID:$SP_APIKEY \
-H "Content-Type: application/json" \
-d "
{
\"name\": \"$SITENAME\",
\"sysuserid\": \"DRKhObMyNB5ei5L1\",
\"runtime\": \"php$PRODUCTION_PHP_VERSION\",
\"domains\": [\"$SITENAME.$PRODUCTION_DOMAIN\"],
\"wordpress\": {
\"site_title\": \"$SITENAME\",
\"admin_user\": \"$PRODUCTION_ADMIN_USER\",
\"admin_password\": \"$PRODUCTION_ADMIN_PASSWORD\",
\"admin_email\": \"$PRODUCTION_ADMIN_EMAIL\"
}
}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment