require 'rake' desc 'Creates and uploads apt and rpm repos.' task "build:repos", :build_type do |t, args| # Run dependent rake jobs first Rake::Task['build:deb'].invoke Rake::Task['build:rpm'].invoke args.with_defaults :build_type => 'nightly-build' puts args # Exit if args are not valid args exit 1 if !args[:build_type].eql? "nightly-build" and !args[:build_type].eql? "release-build" require 'find' require 'fileutils' # CONSTANTS PKG_DIR = '/packages' BETA_PKG_DIR = '/beta-packages' BUCKET = args[:build_type].eql?('release-build') ? 'rhoconnect-test' : 'rhoconnect' def cmd(cmd) puts cmd unless @raked system(cmd) end #cmd # METHODS def prepare_destination # Prompt to remove the /deb directory if it exists if File.directory?("#{PKG_DIR}/deb") if !@raked puts "Remove #{PKG_DIR}/deb?" remove = STDIN.gets.strip.downcase.chars.first else remove = 'y' end #if if remove == 'y' cmd "sudo rm -rf #{PKG_DIR}/deb" end #if end #if # Create deb directory if it does not already exist cmd "sudo mkdir -p #{PKG_DIR}/deb" unless File.directory?("#{PKG_DIR}/deb") # Create configuration file "ditributions" in deb directory filename = "#{PKG_DIR}/deb/conf" cmd "sudo mkdir -p #{filename}" distributions = "Origin: Rhomobile, Inc.\n" + "Label: Rhomobile, Inc.\n" + "Codename: rhoconnect\n" + "Architectures: i386 amd64\n" + "Components: main\n" + "Description: Rhoconnect APT Repository\n" cmd "sudo touch #{filename}/distributions" cmd "sudo chmod 777 #{filename}/distributions" # Write distributions string to corresponding file dist_file = File.new("#{filename}/distributions", "w") dist_file.write(distributions) dist_file.close # Create rpm directory if it does not already exist cmd "sudo mkdir -p #{PKG_DIR}/rpm" unless File.directory?("#{PKG_DIR}/rpm") end #prepare_destination def copy_files # Copy the packages to their respective directory Find.find('./pkg') do |file| if !FileTest.directory?(file) dest_dir = File.extname(file) dest_dir[0] = '' #get rid of '.' before extension name if dest_dir == 'deb' || dest_dir == 'rpm' if dest_dir == 'deb' @deb_pkg = File.basename(file) end #if file_path = File.expand_path(file) cmd "sudo cp -r #{file_path} #{PKG_DIR}/#{dest_dir}" end #if end #if end #do end #copy_files @raked = true prepare_destination copy_files # REPOIFY! cmd "sudo reprepro -b #{PKG_DIR}/deb includedeb rhoconnect #{PKG_DIR}/deb/#{@deb_pkg}" cmd "sudo createrepo #{PKG_DIR}/rpm" # Call S3 upload script ['deb', 'rpm'].each do |dir| beta = false pkg_dir = PKG_DIR Find.find("#{PKG_DIR}/#{dir}") do |file| if File.extname(file) =~ /deb|rpm/ beta = file.include?('beta') ? true : false pkg_dir = BETA_PKG_DIR if beta cmd "sudo mkdir #{BETA_PKG_DIR}" unless File.directory? BETA_PKG_DIR cmd "sudo chmod 777 #{BETA_PKG_DIR}" # If one beta pkg is found, break. break if beta end #if end #do cmd "sudo cp -rf #{PKG_DIR}/#{dir} #{BETA_PKG_DIR}/#{dir}" if pkg_dir == BETA_PKG_DIR cmd "sudo ruby ./installer/utils/package_upload/s3_upload.rb #{pkg_dir}/#{dir} #{BUCKET} #{@raked}" end #do end #build:repos