Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A quick and dirty script to CNAME a Heroku app using PointHQ
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
* text=auto
source 'https://rubygems.org'
gem 'point'
GEM
remote: https://rubygems.org/
specs:
json (1.8.0)
point (1.0.1)
json (>= 1.1.5)
PLATFORMS
ruby
DEPENDENCIES
point
# USERNAME=[PointHQ username]
# APITOKEN=[PointHQ API token]
# DOMAIN=[Primary domain name]
# PREFIX=[Prefix for Heroku app names]
# Copyright 2012 Tom Vincent <http://tlvince.com/contact>
require 'point'
for i in ['USERNAME', 'APITOKEN', 'DOMAIN', 'RECORD_NAME', 'RECORD_DATA']
unless ENV.has_key?(i)
$stderr.puts "Please pass '#{i}' as an environment variable"
exit 1
end
end
Point.username = ENV['USERNAME']
Point.apitoken = ENV['APITOKEN']
for zone in Point::Zone.find(:all)
if zone.name == ENV['DOMAIN'] then
record = zone.build_record
record.record_type = 'CNAME'
record.name = ENV['RECORD_NAME']
record.data = ENV['RECORD_DATA']
if record.save then
puts "Added record '#{record.name}' with data '#{record.data}' to '#{zone.name}'"
else
$stderr.puts record.errors
end
end
end
#!/bin/sh
# Copyright 2012 Tom Vincent <http://tlvince.com/contact>
usage() { echo "$0 subdomain"; exit 1; }
error() { echo "$0: $1"; exit 1; }
prompt() { read -p "$0: $1 [y/n] "; [ $REPLY == "y" ]; }
[ "$1" ] || usage
NAME="$1"
secrets="${XDG_CONFIG_HOME:-$HOME/.config}/point-secrets.sh"
[ -f "$secrets" ] || error "Please create a secrets file in '$secrets'"
source "$secrets"
RECORD_NAME="$NAME.$DOMAIN."
RECORD_DATA="$PREFIX-$NAME.herokuapp.com."
readlink="readlink"
[ $(uname) == "Darwin" ] && readlink="greadlink"
cwd="$(dirname "$("$readlink" --canonicalize "$0")")"
USERNAME="$USERNAME" APITOKEN="$APITOKEN" DOMAIN="$DOMAIN" \
RECORD_NAME="$RECORD_NAME" RECORD_DATA="$RECORD_DATA" ruby "$cwd/point.rb"
prompt "Create Heroku app?" || exit
heroku apps:create "$PREFIX-$NAME"
heroku domains:add "$NAME.DOMAIN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment