jonauman

ruby script

Jun 25th, 2014
236
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env ruby
  2.  
  3. URL='http://10.10.10.10:8081/nexus/service/local/artifact/maven/content'
  4. GROUP='com.daveops'
  5. REPO='main'
  6. USER='admin'
  7. PWD='admin123'
  8.  
  9. basedir = '.'
  10. files = Dir.glob('*.rpm')
  11.  
  12. files.each do |rpm|
  13.   # get RPM version
  14.   rev = /((\d+\.\d+\.?)(\d+)?)/
  15.   ver = rpm.match rev
  16.  
  17.   # get RPM name
  18.   ren =  /^.+?(?=-\d+)/
  19.   name = rpm.match ren
  20.  
  21.   # @ is causing problems in exec
  22.   file = "@" + rpm
  23.  
  24.   command = "curl --raw --noproxy 10.50.1.24 -v -F 'r=#{REPO}' -F 'hasPom=false' -F 'e=rpm' -F 'g=#{GROUP}' -F 'v=#{ver}' -F 'a=#{name}' -F 'p=pom'  -F 'file=#{file}' -u '#{USER}:#{PWD}' #{URL}"
  25.  
  26.   exec ( "#{command}" )
  27.  
  28. end
  29. ---
  30. # Output
  31.  
  32. $ ./test.rb
  33. * Adding handle: conn: 0x2203628
  34. * Adding handle: send: 0
  35. * Adding handle: recv: 0
  36. * Curl_addHandleToPipeline: length: 1
  37. * - Conn 0 (0x2203628) send_pipe: 1, recv_pipe: 0
  38. * About to connect() to proxy lon02-proxy-01.corp.monitise.net port 3128 (#0)
  39. *   Trying 10.75.193.97...
  40. * Connected to lon02-proxy-01.corp.monitise.net (10.75.193.97) port 3128 (#0)
  41. * Server auth using Basic with user ''admin'
  42. * couldn't open file "ant-1.8.2.rpm'"
  43. * Connection #0 to host lon02-proxy-01.corp.monitise.net left intact
  44. curl: (26) couldn't open file "ant-1.8.2.rpm'"
RAW Paste Data