Blame view
script/boxen
2.28 KB
|
e4ab3c55f
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#!/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.
unless ENV["BOXEN_NO_PULL"] || ARGV.include?("--no-pull")
|
|
0b590ebc4
|
30 31 32 33 |
quietly = "> /dev/null 2>&1"
if system("which git > /dev/null") && File.directory?(".git") \
&& fetch = system("git fetch -q origin")
|
|
e4ab3c55f
|
34 |
clean = `git status --porcelain`.empty? |
|
3b06d2616
|
35 36 |
current_branch = `git symbolic-ref HEAD`.chomp
master = current_branch == "refs/heads/master"
|
|
e4ab3c55f
|
37 |
|
|
0b590ebc4
|
38 39 |
upstream_changes = `git rev-list --count master..origin/master`.chomp != '0'
fast_forwardable = `git rev-list --count origin/master..master`.chomp == '0'
|
|
3b06d2616
|
40 |
if !master |
|
549f11393
|
41 42 43 44 45 |
short_branch = if current_branch.empty?
`git log -1 --pretty=format:%h`
else
current_branch.split('/')[2..-1].join('/')
end
|
|
3b06d2616
|
46 |
warn "Boxen on a non-master branch '#{short_branch}', won't auto-update!"
|
|
0b590ebc4
|
47 48 |
elsif !fast_forwardable
warn "Boxen's master branch is out of sync, won't auto-update!"
|
|
3b06d2616
|
49 50 |
elsif !clean
warn "Boxen has a dirty tree, won't auto-update!"
|
|
0b590ebc4
|
51 52 |
elsif !upstream_changes
warn "Boxen is up-to-date."
|
|
3b06d2616
|
53 |
end |
|
fdb27960f
|
54 |
|
|
0b590ebc4
|
55 |
if clean && master && fast_forwardable && upstream_changes |
|
e4ab3c55f
|
56 |
reset = "(git reset --hard origin/master #{quietly})"
|
|
0b590ebc4
|
57 |
reclean = "(git clean -qdf)" |
|
e4ab3c55f
|
58 |
|
|
0b590ebc4
|
59 |
unless system "#{reset} && #{reclean}"
|
|
3b06d2616
|
60 |
warn "Auto-update of Boxen FAILED, continuing." |
|
e4ab3c55f
|
61 62 63 64 65 66 |
end
end
end
end
# Make sure our local dependencies are up to date.
|
|
bfe6c82f4
|
67 |
strap = %w(script/bootstrap --deployment --local --without development:test --no-cache) |
|
e4ab3c55f
|
68 |
abort "Can't bootstrap, dependencies are outdated." unless system *strap |
|
9554e58b4
|
69 70 71 72 |
# Set up our local configuration, deps, and load path. load "config/basic.rb" |
|
bacf7fd78
|
73 |
require "boxen/cli" |
|
cea2b22c9
|
74 |
# Okay, let's run this thing. |
|
bacf7fd78
|
75 |
exit Boxen::CLI.run ARGV |