2012-10-02 14:54:27 -04:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
# Run Boxen.
|
|
|
|
|
|
|
|
require "pathname"
|
|
|
|
|
|
|
|
if ENV["USER"] == "root"
|
|
|
|
abort "Run this as a normal user, I'll sudo if I need to."
|
|
|
|
end
|
|
|
|
|
|
|
|
# Make sure only one boxen process runs at a time.
|
|
|
|
|
|
|
|
myself = File.new __FILE__
|
|
|
|
|
|
|
|
unless myself.flock File::LOCK_EX | File::LOCK_NB
|
|
|
|
abort "You're already running a boxen process! Know a patience."
|
|
|
|
end
|
|
|
|
|
|
|
|
# Yeah yeah, I like to be explicit.
|
|
|
|
|
|
|
|
at_exit { myself.flock File::LOCK_UN }
|
|
|
|
|
|
|
|
# Put us where we belong, in the root dir of our boxen repo.
|
|
|
|
|
|
|
|
Dir.chdir Pathname.new(__FILE__).realpath + "../.."
|
|
|
|
|
|
|
|
# Auto-update code. This is done as early as possible so that changes
|
|
|
|
# to boxen support code or dependencies can be grabbed.
|
2013-08-25 12:55:43 -04:00
|
|
|
NO_PULL_ARGS = %w[--no-pull -h -? --help]
|
|
|
|
unless ENV["BOXEN_NO_PULL"] || NO_PULL_ARGS.any? { |arg| ARGV.include?(arg) }
|
2013-02-27 22:24:10 -05:00
|
|
|
quietly = "> /dev/null 2>&1"
|
|
|
|
|
|
|
|
if system("which git > /dev/null") && File.directory?(".git") \
|
|
|
|
&& fetch = system("git fetch -q origin")
|
|
|
|
|
2012-10-02 14:54:27 -04:00
|
|
|
clean = `git status --porcelain`.empty?
|
2013-02-07 00:59:26 -05:00
|
|
|
current_branch = `git symbolic-ref HEAD`.chomp
|
|
|
|
master = current_branch == "refs/heads/master"
|
2012-10-02 14:54:27 -04:00
|
|
|
|
2013-02-27 22:24:10 -05:00
|
|
|
upstream_changes = `git rev-list --count master..origin/master`.chomp != '0'
|
|
|
|
fast_forwardable = `git rev-list --count origin/master..master`.chomp == '0'
|
|
|
|
|
2013-03-05 16:57:03 -05:00
|
|
|
if current_branch.empty?
|
|
|
|
ref = `git log -1 --pretty=format:%h`
|
|
|
|
warn "Boxen not currently on any branch (ref: #{ref}), won't auto-update!"
|
|
|
|
elsif !master
|
|
|
|
local_branch = current_branch.split('/')[2..-1].join('/')
|
|
|
|
warn "Boxen on a non-master branch '#{local_branch}', won't auto-update!"
|
2013-02-27 22:24:10 -05:00
|
|
|
elsif !fast_forwardable
|
|
|
|
warn "Boxen's master branch is out of sync, won't auto-update!"
|
2013-02-07 00:59:26 -05:00
|
|
|
elsif !clean
|
|
|
|
warn "Boxen has a dirty tree, won't auto-update!"
|
2013-02-27 22:24:10 -05:00
|
|
|
elsif !upstream_changes
|
|
|
|
warn "Boxen is up-to-date."
|
2013-02-07 00:59:26 -05:00
|
|
|
end
|
2013-01-08 23:03:34 -05:00
|
|
|
|
2013-02-27 22:24:10 -05:00
|
|
|
if clean && master && fast_forwardable && upstream_changes
|
2012-10-02 14:54:27 -04:00
|
|
|
reset = "(git reset --hard origin/master #{quietly})"
|
2013-02-27 22:24:10 -05:00
|
|
|
reclean = "(git clean -qdf)"
|
2012-10-02 14:54:27 -04:00
|
|
|
|
2013-02-27 22:24:10 -05:00
|
|
|
unless system "#{reset} && #{reclean}"
|
2013-02-07 00:59:26 -05:00
|
|
|
warn "Auto-update of Boxen FAILED, continuing."
|
2012-10-02 14:54:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Make sure our local dependencies are up to date.
|
|
|
|
|
2013-03-02 03:41:16 -05:00
|
|
|
strap = %w(script/bootstrap --deployment --local --without development:test --no-cache)
|
2012-10-02 14:54:27 -04:00
|
|
|
abort "Can't bootstrap, dependencies are outdated." unless system *strap
|
2012-10-02 15:16:25 -04:00
|
|
|
|
|
|
|
# Set up our local configuration, deps, and load path.
|
|
|
|
|
|
|
|
load "config/basic.rb"
|
2012-10-02 19:25:35 -04:00
|
|
|
require "boxen/cli"
|
|
|
|
|
2012-10-02 16:45:35 -04:00
|
|
|
# Okay, let's run this thing.
|
|
|
|
|
2012-10-02 19:25:35 -04:00
|
|
|
exit Boxen::CLI.run ARGV
|