Commit e4ab3c55f7ef586880f36ec55bf57fa03834d928

Authored by John Barnette
1 parent 9d3e514b92

Stub auto-updating script/boxen

Showing 1 changed file with 51 additions and 0 deletions Side-by-side Diff

  1 +#!/usr/bin/ruby
  2 +# Run Boxen.
  3 +
  4 +require "pathname"
  5 +
  6 +if ENV["USER"] == "root"
  7 + abort "Run this as a normal user, I'll sudo if I need to."
  8 +end
  9 +
  10 +# Make sure only one boxen process runs at a time.
  11 +
  12 +myself = File.new __FILE__
  13 +
  14 +unless myself.flock File::LOCK_EX | File::LOCK_NB
  15 + abort "You're already running a boxen process! Know a patience."
  16 +end
  17 +
  18 +# Yeah yeah, I like to be explicit.
  19 +
  20 +at_exit { myself.flock File::LOCK_UN }
  21 +
  22 +# Put us where we belong, in the root dir of our boxen repo.
  23 +
  24 +Dir.chdir Pathname.new(__FILE__).realpath + "../.."
  25 +
  26 +# Auto-update code. This is done as early as possible so that changes
  27 +# to boxen support code or dependencies can be grabbed.
  28 +
  29 +unless ENV["BOXEN_NO_PULL"] || ARGV.include?("--no-pull")
  30 + if system("which git > /dev/null") && File.directory?(".git")
  31 + clean = `git status --porcelain`.empty?
  32 + master = `git symbolic-ref HEAD`.chomp == "refs/heads/master"
  33 + no_new_commits = system('git diff --exit-code --quiet origin/master master')
  34 +
  35 + if clean && master && no_new_commits
  36 + quietly = "> /dev/null 2>&1"
  37 + fetch = "(git fetch origin #{quietly})"
  38 + reset = "(git reset --hard origin/master #{quietly})"
  39 + reclean = "(git clean -df #{quietly})"
  40 +
  41 + unless system "#{fetch} && #{reset} && #{reclean}"
  42 + warn "Couldn't auto-update, continuing."
  43 + end
  44 + end
  45 + end
  46 +end
  47 +
  48 +# Make sure our local dependencies are up to date.
  49 +
  50 +strap = %w(script/bootstrap --deployment --local --without development:test)
  51 +abort "Can't bootstrap, dependencies are outdated." unless system *strap