#!/usr/bin/env ruby require "rubygems" require "active_scripts" require "commander/import" program :name, "ActiveScripts" program :version, ActiveScripts::VERSION program :description, "Deployment scripts for commonly used server setups" ActiveScripts::Preparations::Base::COMMANDS.each do |exec| command exec do |c| c.syntax = "active_scripts #{exec} [options]" c.description = "#{exec.capitalize} operating system packages" c.option "--dry-run", "Print out commands but not execute" c.option "--verbose", "#{exec.capitalize} available packages verbosely" c.action do |args, options| options.default(dry_run: false, verbose: false) say("Select #{exec} options [hit enter to skip]:") begin $operating_system = ActiveScripts::OperatingSystem.find preparation = ActiveScripts::Preparation.find($operating_system) say(" - #{(exec == :setup) ? 'Setting up' : 'Updating'} #{preparation}...") "ActiveScripts::Preparations::#{preparation.to_s.camelize}".constantize.execute(exec, { dry_run: options.dry_run, verbose: options.verbose }) rescue => error say_error(" [!] #{error.class}") say_error(" - #{error.message}") end end end end ActiveScripts::Packages::Base::COMMANDS.each do |exec| command exec do |c| c.syntax = "active_scripts #{exec} [options]" c.description = "#{exec.capitalize} recipes and packages" c.option "--dry-run", "Print out commands but not execute" c.option "--verbose", "#{exec.capitalize} available packages verbosely" c.action do |args, options| options.default(dry_run: false, verbose: false) say("Select #{exec} options [hit enter to skip]:") begin $operating_system = ActiveScripts::OperatingSystem.find recipes = ask("== Which recipies? ", lambda { |str| str.strip.split(/,\s*/) }) recipes = ActiveScripts::Recipe.find(recipes) packages = ask("== Which #{'additional ' unless recipes.blank?}packages? ", lambda { |str| str.strip.split(/,\s*/) }) packages = ActiveScripts::Package.find(packages) packages = recipes.push(packages).flatten.uniq if packages.blank? say_error("== 0 #{$operating_system} recipes or packages #{exec}#{(exec == :upgade) ? 'd' : 'ed'}!") else packages.each do |package| say(" - #{(exec == :upgrade) ? 'Upgrading' : (exec.to_s.capitalize + 'ing')} #{package}...") "ActiveScripts::Packages::#{package.to_s.camelize}".constantize.execute(exec, { dry_run: options.dry_run, verbose: options.verbose }) end say_ok("== #{packages.count} #{$operating_system} recipes and packages #{exec}#{(exec == :upgade) ? 'd' : 'ed'}!") end rescue => error say_error(" [!] #{error.class}") say_error(" - #{error.message}") end end end end