thewoolleyman / cinabox
- Source
- Commits
- Network (1)
- Issues (1)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
8e91885
cinabox / setup_ci.rb
| e436c5d7 » | thewoolleyman | 2008-07-21 | 1 | #!/usr/bin/env ruby | |
| 15dee89f » | thewoolleyman | 2008-06-22 | 2 | ||
| 3 | class Cinabox | ||||
| 4 | def self.setup | ||||
| 5 | require 'fileutils' | ||||
| 2cf6ccb3 » | thewoolleyman | 2008-07-19 | 6 | require 'socket' | |
| 15dee89f » | thewoolleyman | 2008-06-22 | 7 | ||
| 432e641b » | thewoolleyman | 2008-07-19 | 8 | # Settings | |
| a03786c5 » | thewoolleyman | 2009-08-18 | 9 | cruise_user = ENV['CRUISE_USER'] || ENV['USER'] | |
| 10 | cruise_home = ENV['CRUISE_HOME'] || "#{ENV['HOME']}/ccrb" | ||||
| 4e6c5ab1 » | thewoolleyman | 2009-08-18 | 11 | cruise_branch = ENV['CRUISE_BRANCH'] || "git://github.com/thoughtworks/cruisecontrol.rb.git" | |
| 12 | # cruise_tag = ENV['CRUISE_TAG'] | ||||
| e1311e5f » | thewoolleyman | 2009-09-16 | 13 | cruise_tag = ENV['CRUISE_TAG'] | |
| 27881877 » | thewoolleyman | 2008-07-18 | 14 | cinabox_dir = File.expand_path(File.dirname(__FILE__)) | |
| 4e6c5ab1 » | thewoolleyman | 2009-08-18 | 15 | cruise_daemon_template = ENV['CRUISE_DAEMON_TEMPLATE'] || "#{cruise_home}/daemon/cruise" | |
| e1311e5f » | thewoolleyman | 2009-09-16 | 16 | hostname = ENV['HOSTNAME'] | |
| 17 | |||||
| 18 | # set hostname | ||||
| 19 | run "sudo echo '#{hostname}' > /etc/hostname" if hostname | ||||
| 27881877 » | thewoolleyman | 2008-07-18 | 20 | ||
| 432e641b » | thewoolleyman | 2008-07-19 | 21 | # Build/download dir | |
| 22 | build_dir = ENV['BUILD_DIR'] || "#{ENV['HOME']}/build" | ||||
| 23 | FileUtils.mkdir_p(build_dir) | ||||
| 24 | |||||
| 25 | # warning - the '--force' option will blow away any existing settings | ||||
| 26 | force = ARGV[0] == '--force' ? true : false | ||||
| 27 | |||||
| 3176d7ae » | thewoolleyman | 2009-09-05 | 28 | # Install important packages | |
| db8f3b0f » | thewoolleyman | 2009-09-16 | 29 | run "sudo aptitude install -y subversion" if !((run "dpkg -l subversion", false) =~ /ii subversion/) || force | |
| 30 | run "sudo aptitude install -y git-core" if !((run "dpkg -l git-core", false) =~ /ii git-core/) || force | ||||
| 31 | run "sudo aptitude install -y git-svn" if !((run "dpkg -l git-svn", false) =~ /ii git-svn/) || force | ||||
| 15dee89f » | thewoolleyman | 2008-06-22 | 32 | ||
| 4e6c5ab1 » | thewoolleyman | 2009-08-18 | 33 | # Install cruisecontrol.rb via git and dependencies | |
| a03786c5 » | thewoolleyman | 2009-08-18 | 34 | if !File.exist?(cruise_home) || force | |
| 35 | run "rm -rf #{cruise_home}" | ||||
| 4e6c5ab1 » | thewoolleyman | 2009-08-18 | 36 | run "git clone #{cruise_branch} #{cruise_home}" | |
| 37 | run "cd #{cruise_home} && git checkout -b #{cruise_tag} refs/tags/#{cruise_tag}" if cruise_tag | ||||
| 5edcbbfb » | thewoolleyman | 2009-08-30 | 38 | run "sudo gem install --bindir /usr/bin rake rack thin" | |
| 39 | unless RUBY_VERSION =~ /^1.9/ | ||||
| 40 | run "sudo gem install --bindir /usr/bin mongrel mongrel_cluster" | ||||
| 41 | end | ||||
| 15dee89f » | thewoolleyman | 2008-06-22 | 42 | end | |
| 1603ffad » | thewoolleyman | 2008-07-18 | 43 | ||
| 4e6c5ab1 » | thewoolleyman | 2009-08-18 | 44 | # Always update cruisecontrol.rb | |
| 22b902a3 » | thewoolleyman | 2009-07-22 | 45 | # TODO: disabled for now, it will break if we are on a tag | |
| a03786c5 » | thewoolleyman | 2009-08-18 | 46 | # run "cd #{cruise_home} && git pull" | |
| 1f322147 » | thewoolleyman | 2008-07-18 | 47 | ||
| 4a28e965 » | thewoolleyman | 2008-08-09 | 48 | # Write out init script daemon based on template | |
| 841c21db » | thewoolleyman | 2008-07-26 | 49 | if !File.exist?('/etc/init.d/cruise') || force | |
| 33967f74 » | thewoolleyman | 2009-08-18 | 50 | run "sudo rm -f /etc/init.d/cruise" | |
| 276e3321 » | thewoolleyman | 2008-08-09 | 51 | run "sudo touch /etc/init.d/cruise" | |
| a03786c5 » | thewoolleyman | 2009-08-18 | 52 | run "sudo chown #{cruise_user} /etc/init.d/cruise" | |
| f533839a » | thewoolleyman | 2008-08-09 | 53 | run "chmod a+x /etc/init.d/cruise" | |
| 4e6c5ab1 » | thewoolleyman | 2009-08-18 | 54 | File.open(cruise_daemon_template, "r") do |input| | |
| 276e3321 » | thewoolleyman | 2008-08-09 | 55 | File.open("/etc/init.d/cruise", "w") do |output| | |
| 56 | input.each_line do |line| | ||||
| a03786c5 » | thewoolleyman | 2009-08-18 | 57 | line = "CRUISE_USER = '#{cruise_user}'\n" if line =~ /CRUISE_USER =/ | |
| 58 | line = "CRUISE_HOME = '#{cruise_home}'\n" if line =~ /CRUISE_HOME =/ | ||||
| 276e3321 » | thewoolleyman | 2008-08-09 | 59 | output.print(line) | |
| 60 | end | ||||
| 61 | end | ||||
| 62 | end | ||||
| 29a201cb » | thewoolleyman | 2008-07-18 | 63 | end | |
| 64 | |||||
| 0f4d8356 » | thewoolleyman | 2008-07-19 | 65 | # Enable on system reboot | |
| 2b9ab6ed » | thewoolleyman | 2008-07-21 | 66 | if !File.exist?('/etc/rc3.d/S20cruise') || force | |
| db8f3b0f » | thewoolleyman | 2009-09-16 | 67 | run "sudo update-rc.d -f cruise defaults" | |
| 60f612ac » | thewoolleyman | 2008-07-18 | 68 | end | |
| 0f4d8356 » | thewoolleyman | 2008-07-19 | 69 | ||
| 2cf6ccb3 » | thewoolleyman | 2008-07-19 | 70 | # Install and configure postfix | |
| db8f3b0f » | thewoolleyman | 2009-09-16 | 71 | if !((run "dpkg -l postfix", false) =~ /ii postfix/) || force | |
| 72 | run "sudo aptitude install debconf-utils -y" | ||||
| 73 | run "echo 'postfix\tpostfix/mailname\tstring\t#{Socket.gethostbyname(Socket.gethostname)[0]}' > #{build_dir}/postfix-selections" | ||||
| 74 | run "echo 'postfix\tpostfix/main_mailer_type\tselect\tInternet Site' >> #{build_dir}/postfix-selections" | ||||
| 75 | run "sudo debconf-set-selections #{build_dir}/postfix-selections" | ||||
| 76 | run "sudo aptitude install postfix -y" | ||||
| 2cf6ccb3 » | thewoolleyman | 2008-07-19 | 77 | end | |
| 55526000 » | thewoolleyman | 2009-06-25 | 78 | ||
| 43d2e12a » | thewoolleyman | 2009-09-05 | 79 | # TODO: when run via 'su -l ci' from another user, this doesn't always drop a pid file, even though it starts | |
| 415a32c5 » | thewoolleyman | 2009-08-27 | 80 | run "/etc/init.d/cruise start" unless ENV['NO_DAEMON_START'] | |
| 61416eef » | thewoolleyman | 2008-07-21 | 81 | ||
| 2b9ab6ed » | thewoolleyman | 2008-07-21 | 82 | print "\n\nSetup script completed.\n" | |
| 15dee89f » | thewoolleyman | 2008-06-22 | 83 | end | |
| 32096535 » | thewoolleyman | 2008-07-19 | 84 | ||
| 4053dced » | thewoolleyman | 2008-07-21 | 85 | def self.run(cmd, fail_on_error = true) | |
| 32096535 » | thewoolleyman | 2008-07-19 | 86 | puts "Running command: #{cmd}" | |
| 2113de5c » | thewoolleyman | 2008-07-19 | 87 | output = `#{cmd}` | |
| 88 | puts output | ||||
| 61416eef » | thewoolleyman | 2008-07-21 | 89 | if !$?.success? and fail_on_error | |
| 2b9ab6ed » | thewoolleyman | 2008-07-21 | 90 | print "\n\nCommand failed: #{cmd}\n" | |
| 61416eef » | thewoolleyman | 2008-07-21 | 91 | exit $?.to_i | |
| 92 | end | ||||
| 2113de5c » | thewoolleyman | 2008-07-19 | 93 | output | |
| 32096535 » | thewoolleyman | 2008-07-19 | 94 | end | |
| 15dee89f » | thewoolleyman | 2008-06-22 | 95 | end | |
| 96 | |||||
| 97 | Cinabox.setup | ||||
