Blame view
script/boxen
2.18 KB
e4ab3c55f Stub auto-updatin... |
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 Refactor git hand... |
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 Stub auto-updatin... |
34 |
clean = `git status --porcelain`.empty? |
3b06d2616 better error mess... |
35 36 |
current_branch = `git symbolic-ref HEAD`.chomp master = current_branch == "refs/heads/master" |
e4ab3c55f Stub auto-updatin... |
37 |
|
0b590ebc4 Refactor git hand... |
38 39 40 41 |
upstream_changes = `git rev-list --count master..origin/master`.chomp != '0' fast_forwardable = `git rev-list --count origin/master..master`.chomp == '0' short_branch = current_branch.split('/')[2..-1].join('/') |
3b06d2616 better error mess... |
42 43 44 |
if !master warn "Boxen on a non-master branch '#{short_branch}', won't auto-update!" |
0b590ebc4 Refactor git hand... |
45 46 |
elsif !fast_forwardable warn "Boxen's master branch is out of sync, won't auto-update!" |
3b06d2616 better error mess... |
47 48 |
elsif !clean warn "Boxen has a dirty tree, won't auto-update!" |
0b590ebc4 Refactor git hand... |
49 50 |
elsif !upstream_changes warn "Boxen is up-to-date." |
3b06d2616 better error mess... |
51 |
end |
fdb27960f Update template w... |
52 |
|
0b590ebc4 Refactor git hand... |
53 |
if clean && master && fast_forwardable && upstream_changes |
e4ab3c55f Stub auto-updatin... |
54 |
reset = "(git reset --hard origin/master #{quietly})" |
0b590ebc4 Refactor git hand... |
55 |
reclean = "(git clean -qdf)" |
e4ab3c55f Stub auto-updatin... |
56 |
|
0b590ebc4 Refactor git hand... |
57 |
unless system "#{reset} && #{reclean}" |
3b06d2616 better error mess... |
58 |
warn "Auto-update of Boxen FAILED, continuing." |
e4ab3c55f Stub auto-updatin... |
59 60 61 62 63 64 |
end end end end # Make sure our local dependencies are up to date. |
bfe6c82f4 speed up all invo... |
65 |
strap = %w(script/bootstrap --deployment --local --without development:test --no-cache) |
e4ab3c55f Stub auto-updatin... |
66 |
abort "Can't bootstrap, dependencies are outdated." unless system *strap |
9554e58b4 Spike config/basic |
67 68 69 70 |
# Set up our local configuration, deps, and load path. load "config/basic.rb" |
bacf7fd78 Boxen.run -> Boxe... |
71 |
require "boxen/cli" |
cea2b22c9 Call Boxen.run |
72 |
# Okay, let's run this thing. |
bacf7fd78 Boxen.run -> Boxe... |
73 |
exit Boxen::CLI.run ARGV |