#!/usr/bin/env ruby require 'rbbt-util' require 'rbbt/util/simpleopt' require 'rbbt/workflow' $0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands options = SOPT.setup < [] Install a workflow, or a coma separated list of workflows, from its source. If repo is not specified then 'http://github.com/Rbbt-Workflows/' will be used. If the workflow is already installed it will be updated. If 'all' is specified instead of a particular workflow, all installed workflows will be updated. -h--help Print this help EOF if options[:help] if defined? rbbt_usage rbbt_usage else puts SOPT.usage end exit 0 end workflow = ARGV[0] base_repo = ARGV[1] raise "No workflow specified" if workflow.nil? workflow_dir = Rbbt.etc.workflow_dir.exists? ? Path.setup(Rbbt.etc.workflow_dir.read.strip) : Rbbt.workflows.find(:user) FileUtils.mkdir_p workflow_dir unless File.exist? workflow_dir all_workflows = workflow_dir.find.glob("*/.git").collect{|d| File.basename(File.dirname(d))} workflows = workflow == 'all' ? all_workflows : workflow.split(",") Misc.in_dir(workflow_dir) do workflows.each do |workflow| case when File.exist?(Misc.snake_case(workflow)) Log.info "Updating: " + workflow Misc.in_dir(Misc.snake_case(workflow)) do `git pull` `git submodule init` `git submodule update` end when File.exist?(workflow) Misc.in_dir(workflow) do Log.info "Updating: " + workflow `git pull` `git submodule init` `git submodule update` end else Log.info "Installing: " + workflow if base_repo.nil? repo_base_url = Rbbt.etc.workflow_repo.exists? ? Rbbt.etc.workflow_repo.read.strip : 'https://github.com/Rbbt-Workflows/' else repo_base_url = base_repo end if repo_base_url.include?(workflow) or repo_base_url.include?(Misc.snake_case(workflow)) repo = repo_base_url else begin repo = File.join(repo_base_url, workflow + '.git') CMD.cmd("wget '#{repo}' -O /dev/null").read rescue Log.debug "Workflow repo does not exist, trying snake_case: #{ repo }" begin repo = File.join(repo_base_url, Misc.snake_case(workflow) + '.git') CMD.cmd("wget '#{repo}' -O /dev/null").read rescue raise "Workflow repo does not exist: #{ repo }" end end end Log.warn "Cloning #{ repo }" Misc.insist do `git clone "#{repo}" #{ Misc.snake_case(workflow) }` raise unless $?.success? end Log.warn "Initializing and updating submodules for #{repo}. You might be prompted for passwords." Misc.in_dir(Misc.snake_case(workflow)) do `git submodule init` `git submodule update` end end end end