desc 'Creates and uploads apt and rpm repos.' task "build:repos" => ['build:deb', 'build:rpm'] do require 'find' require 'fileutils' # CONSTANTS PKG_DIR = '/packages' BETA_PKG_DIR = '/beta-packages' BUCKET = '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| puts "File: #{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 = 0 pkg_dir = PKG_DIR Find.find("#{PKG_DIR}/#{dir}") do |file| if File.extname(file) =~ /deb|rpm/ file =~ /.*beta.*/ ? beta += 1 : beta = beta pkg_dir = BETA_PKG_DIR 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 end #if end #do cmd "sudo cp -rf #{PKG_DIR}/#{dir} #{BETA_PKG_DIR}/#{dir}" cmd "sudo ruby ./installer/utils/package_upload/s3_upload.rb #{pkg_dir}/#{dir} #{BUCKET} #{@raked}" end #do end #build:repos