namespace :website do namespace :domains do desc <<-DESC Attach a domain to the current website. This can be one of: * A domain of your own: setup instructions will be displayed after successful attachment. For example: "foobar.com". * A free subdomain: choose one ending with ".flucti.com": immediately available, setup required. For example: "foobar.flucti.com". * A subdomain of either a domain of your own or a free subdomain. For example: "blog.foobar.com" or "blog.foobar.flucti.com". * A wildcard subdomain. For example: "*.foobar.com" or "*.foobar.flucti.com" Environment variables: $DOMAIN: the domain name. DESC task :attach do site = website.fetch_current! name = require_name! domain = site.domains.build(:name => name) examples = [] try_save domain do puts_title("Request sent") puts_long <<-INFO * Domain #{q domain} has been scheduled for attachment to website #{q site}. INFO if domain.attribute_set?(:cname_domain_name) puts puts_long <<-INFO * For #{q domain} to point to your VPS's, you must go to your registrar's control panel, clear any previous A or CNAME records, and add a CNAME record to #{q domain.cname_domain_name}. INFO end end end desc "Alias for `attach'." task(:add) { attach } desc <<-DESC Detach a domain from the current website. By doing so, the website will cease to be available at the specified domain. Environment variables: $DOMAIN: the domain name. DESC task :detach do site = website.fetch_current! name = require_name! domain = site.domains.find(name) domain.destroy puts_title("Request sent") puts "Domain #{q domain} has been scheduled for detachment from website #{q site}." end desc "Alias for `attach'." task(:remove) { detach } desc <<-DESC List all domains that need a CNAME record. In order for the domains you own to point to the VPS hosting a site, you need to declare a CNAME record on the DNS server of the domains, most likely managed by the registrar they have been bought from. Please note that it can take up to 48 hours for the changes to propagate. Free subdomains don't need such a declaration since they are handled on our side. That is why they are not listed. As a consequence, they are functional immediately. DESC task :cnames do site = website.fetch_current! domains_with_cname = site.domains.select { |dom| dom.cname_domain_name } if domains_with_cname.any? puts_list(domains_with_cname, :id => false, :table => true) do |t| t.col("Domain", :name) t.col("CNAME", :cname_domain_name) end else puts "No domain needs to be declared CNAME records." end end def require_name! ENV["DOMAIN"] or error! <<-MSG The domain name to deal with must be specified by setting the $DOMAIN environment variable. To list all domains currently attached to the current website, run #{qcommand "website"}. MSG end end end