Blame view

script/boxen 2.02 KB
e4ab3c55f   John Barnette   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
30
31
  #!/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")
    if system("which git > /dev/null") && File.directory?(".git")
      clean  = `git status --porcelain`.empty?
3b06d2616   Will Farrington   better error mess...
32
33
      current_branch = `git symbolic-ref HEAD`.chomp
      master = current_branch == "refs/heads/master"
e4ab3c55f   John Barnette   Stub auto-updatin...
34
      no_new_commits = system('git diff --exit-code --quiet origin/master master')
3b06d2616   Will Farrington   better error mess...
35
36
37
38
39
40
41
42
43
      short_branch = current_branch.split('/').last
  
      if !master
        warn "Boxen on a non-master branch '#{short_branch}', won't auto-update!"
      elsif !no_new_commits
        warn "Boxen has unpushed commits on master, won't auto-update!"
      elsif !clean
        warn "Boxen has a dirty tree, won't auto-update!"
      end
fdb27960f   Will Farrington   Update template w...
44

e4ab3c55f   John Barnette   Stub auto-updatin...
45
46
47
48
49
50
51
      if clean && master && no_new_commits
        quietly = "> /dev/null 2>&1"
        fetch   = "(git fetch origin #{quietly})"
        reset   = "(git reset --hard origin/master #{quietly})"
        reclean = "(git clean -df #{quietly})"
  
        unless system "#{fetch} && #{reset} && #{reclean}"
3b06d2616   Will Farrington   better error mess...
52
          warn "Auto-update of Boxen FAILED, continuing."
e4ab3c55f   John Barnette   Stub auto-updatin...
53
54
55
56
57
58
59
60
61
        end
      end
    end
  end
  
  # Make sure our local dependencies are up to date.
  
  strap = %w(script/bootstrap --deployment --local --without development:test)
  abort "Can't bootstrap, dependencies are outdated." unless system *strap
9554e58b4   John Barnette   Spike config/basic
62
63
64
65
  
  # Set up our local configuration, deps, and load path.
  
  load "config/basic.rb"
bacf7fd78   John Barnette   Boxen.run -> Boxe...
66
  require "boxen/cli"
cea2b22c9   John Barnette   Call Boxen.run
67
  # Okay, let's run this thing.
bacf7fd78   John Barnette   Boxen.run -> Boxe...
68
  exit Boxen::CLI.run ARGV