diff --git a/contrib/dokku-installer.rb b/contrib/dokku-installer.rb new file mode 100755 index 000000000..bbd1c5c4d --- /dev/null +++ b/contrib/dokku-installer.rb @@ -0,0 +1,121 @@ +#!/usr/bin/env ruby +require "sinatra" +require "open3" + +if ARGV[0] == "onboot" + File.open("/etc/init/dokku-installer.conf", "w") do |f| + f.puts "start on runlevel [2345]" + f.puts "exec #{File.absolute_path(__FILE__)} selfdestruct" + end + File.open("/etc/nginx/conf.d/dokku-installer.conf", "w") do |f| + f.puts "upstream dokku-installer { server 127.0.0.1:2000; }" + f.puts "server {" + f.puts " listen 80;" + f.puts " location / {" + f.puts " proxy_pass http://dokku-installer;" + f.puts " }" + f.puts "}" + end + puts "Installed Upstart service and default Nginx virtualhost for installer to run on boot." + exit +end + +version = "v0.2.0" +dokku_root = ENV["DOKKU_ROOT"] || "/home/dokku" +admin_key = `cat /root/.ssh/authorized_keys`.split("\n").first +hostname = `bash -c '[[ $(dig +short $HOSTNAME) ]] && echo $HOSTNAME || curl icanhazip.com'`.strip +template = DATA.read + +set :port, 2000 +set :environment, :production +disable :protection + +get "/" do + ERB.new(template).result binding +end + +post "/setup" do + if params[:vhost] == "true" + File.open("#{dokku_root}/VHOST", "w") {|f| f.write params[:hostname] } + else + `rm #{dokku_root}/VHOST` + end + File.open("#{dokku_root}/HOSTNAME", "w") {|f| f.write params[:hostname] } + Open3.capture2("sshcommand acl-add dokku admin", :stdin_data => params[:key]) + Thread.new { + `rm /etc/nginx/conf.d/dokku-installer.conf && /etc/init.d/nginx stop && /etc/init.d/nginx start` + `rm /etc/init/dokku-installer.conf && stop dokku-installer` + }.run if ARGV[0] == "selfdestruct" +end + +__END__ + + + Dokku Setup + + + + +
+
+

Dokku Setup <%= version %>

+
+

Admin Access

+
+ +
+
+

Hostname Configuration

+
+ + +
+
+ +
+

Your app URLs will look like:

+
http://hostname:port
+
+ +
+
+
+ + + \ No newline at end of file