This file is indexed.

/usr/sbin/obs_mirror_project is in obs-utils 2.7.4-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/ruby

# This script mirrors a base distribution from the opensuse.org Build Service.
# You can use it to create initial base projects in your build service to build for.
#
# This script does mirror only build packages, not the sources. 
#

require 'optparse'

# This hash will hold all of the options
# parsed from the command-line by OptionParser.
options = {}

optparse = OptionParser.new do |opts|
  # Set a banner, displayed at the top of the help screen.
  opts.banner = "-------------------------------------------------------------------------------------------
Usage: obs_mirror_project.rb -p PROJECT -r REPOSITORY
                            [-a ARCHITECTURE] [-d DESTINATION] [-A APIURL] [-t] [-v]

Example: (mirror openSUSE 13.1 as base distro)
obs_mirror_project -p openSUSE:13.1 -r standard -a i586,x86_64
-------------------------------------------------------------------------------------------
Options help:
"

  # Define the options, and what they do
  options[:proj] = ""
  opts.on( '-p', '--proj PROJECT',
           "Project Name:      eg. openSUSE:13.1,Ubuntu:14.04,etc." ) do|f|
    options[:proj] = f
  end

  options[:repo] = ""
  opts.on( '-r', '--repo REPOSITORY',
           "Repository Name:   eg. standard,qemu,etc." ) do|f|
    options[:repo] = f
  end

  options[:arch] = ""
  opts.on( '-a', '--arch Architecture',
           "Architecture Name: eg. i586,x86_64,etc.") do|f|
    options[:arch] = f
  end

  options[:dest] = ""
  opts.on( '-d', '--dest DESTINATION',
           "Destination Path:  eg. /obs          Default: PWD (current working directory)" ) do|f|
    options[:dest] = f
  end

  options[:apiurl] = ""
  opts.on( '-A', '--api APIURL',
           "OSC API URL:                         Default: https://api.opensuse.org" ) do|f|
    options[:apiurl] = f
  end

  options[:trialrun] = false
  opts.on( '-t', '--trialrun', "Trial run: not executing actions" ) do
    options[:trialrun] = true
  end

  options[:verbose] = false
  opts.on( '-v', '--verbose', "Verbose" ) do
    options[:verbose] = true
  end

  # This displays the help screen, all programs are
  # assumed to have this option.
  opts.on( '-h', '--help', 'Display this screen' ) do
    puts opts
    exit
  end
end

# Parse the command-line. Remember there are two forms of the parse method:
# 1. 'parse' method simply parses ARGV,
# 2.  'parse!' method parses ARGV and removes any options found there,
#     as well as any parameters for the options.
#     What's left is the list of files to resize.
optparse.parse!
proj = options[:proj]
repo = options[:repo]
arch = options[:arch]
!options[:dest].empty?    ? dest=options[:dest]     : dest=Dir.pwd
!options[:apiurl].empty?  ? apiurl=options[:apiurl] : apiurl="https://api.opensuse.org"
trialrun  = options[:trialrun]
verbose = options[:verbose]

if verbose
  puts Options: options
  puts ARGC: ARGV
  puts proj: proj
  puts repo: repo
  puts arch: arch
  puts dest: dest
  puts apiurl:  apiurl
  puts trialrun:  trialrun
  puts verbose: verbose
end


puts "
#####################
# Data Verification #
#####################"
# proj and repo are mandatory
if proj.empty? || repo.empty? || arch.empty?
  puts "ERROR! Miss mandatory options: '-p' or '-r' or '-a'"
  puts "Options: #{options}"
  puts optparse.help()
  exit(1)
end

# verify apiurl
puts "\nVerify API URL '#{apiurl}':
osc -A #{apiurl} api -m GET /about > /dev/null" if verbose
if !system("osc -A #{apiurl} api -m GET /about > /dev/null")
  puts "Verify API URL '#{apiurl}': failed"
  exit(1)
else
  puts "Verify API URL '#{apiurl}': ok"
end

# verify proj
puts "\nVerify proj '#{proj}':
osc -A #{apiurl} api -m GET /build/#{proj} > /dev/null" if verbose
if !system("osc -A #{apiurl} api -m GET /build/#{proj} > /dev/null")
  puts "Verify proj '#{proj}': failed"
  exit(1)
else
  puts "Verify proj '#{proj}': ok"
end

# verify repo
puts "\nVerify repo '#{repo}':
osc -A #{apiurl} api -m GET /build/#{proj}/#{repo} > /dev/null" if verbose
if !system("osc -A #{apiurl} api -m GET /build/#{proj}/#{repo} > /dev/null")
  puts "Verify repo '#{repo}': failed"
  exit(1)
else
  puts "Verify repo '#{repo}': ok"
end

# verify arch
puts "\nVerify arch '#{arch}':
osc -A #{apiurl} api -m GET /build/#{proj}/#{repo}/#{arch} > /dev/null" if verbose
if !system("osc -A #{apiurl} api -m GET /build/#{proj}/#{repo}/#{arch} > /dev/null")
  puts "Verify arch '#{arch}': failed"
  exit(1)
else
  puts "Verify arch '#{arch}': ok"
end

# method for verify directory
def directory_verify (path, name, verbose, trialrun)
  puts "\nVerify #{name} directory '#{path}':" if verbose
  if !FileTest.directory?("#{path}")
    puts "Creating #{name} directory: #{path}"
    system("mkdir -p #{path}") if !trialrun
  end
  if FileTest.directory?("#{path}") && FileTest.writable?("#{path}")
    puts "Verify #{name} directory '#{path}': ok"
  else
    puts "Verify #{name} directory '#{path}': failed"
    exit(1) if !trialrun
  end
  return
end

# verify dest dir
directory_verify("#{dest}", "dest", verbose, trialrun)

# verify project dir
directory_verify("#{dest}/projects", "projects", verbose, trialrun)

# verify :full dir
directory_verify("#{dest}/build/#{proj}/#{repo}/#{arch}/:full", ":full", verbose, trialrun)


puts "
################
# Project meta #
################"
# retrieve project meta and configuration data
puts "\nRetrieve project meta data:
osc -A #{apiurl} meta prj     #{proj} > #{dest}/projects/#{proj}.xml" if verbose
system("
osc -A #{apiurl} meta prj     #{proj} > #{dest}/projects/#{proj}.xml") if !trialrun

puts "\nRetrieve project configuration data:
osc -A #{apiurl} meta prjconf #{proj} > #{dest}/projects/#{proj}.conf" if verbose
system("
osc -A #{apiurl} meta prjconf #{proj} > #{dest}/projects/#{proj}.conf") if !trialrun


puts "
####################
# Project binaries #
####################"
require 'rexml/document'
include REXML

# retrieve full binary lists
if !trialrun
  puts "\nRetrieve full binary list:
osc -A #{apiurl} api -m GET /build/#{proj}/#{repo}/#{arch}/_repository > #{dest}/build/#{proj}/#{repo}/#{arch}/binarylist.lst"
  system("
osc -A #{apiurl} api -m GET /build/#{proj}/#{repo}/#{arch}/_repository > #{dest}/build/#{proj}/#{repo}/#{arch}/binarylist.lst")
end

# open full binary list file
if File.file?("#{dest}/build/#{proj}/#{repo}/#{arch}/binarylist.lst")
  puts "\nOpen full binary list file:
File::open(\"#{dest}/build/#{proj}/#{repo}/#{arch}/binarylist.lst\", \"r\")"
  process = File::open("#{dest}/build/#{proj}/#{repo}/#{arch}/binarylist.lst", "r")
else
  puts "\nOpen full binary list file:
File::popen(\"osc -A #{apiurl} api -m GET /build/#{proj}/#{repo}/#{arch}/_repository\", \"r\")"
  process = File::popen("osc -A #{apiurl} api -m GET /build/#{proj}/#{repo}/#{arch}/_repository", "r")
end

# process full binary list file
puts ""
filelist = Document.new(process)
filelist.elements.each("binarylist/binary") { |binary| 
  fname  = binary.attributes["filename"]
  fsize  = binary.attributes["size"]
  fmtime = binary.attributes["mtime"]
  puts "Process: #{fname} (#{fsize})"

  # skip src, nosrc, debuginfo, and debugsource packages
  if fname[-7..-1]=="src.rpm" || fname.include?("-debuginfo") || fname.include?("-debugsource")
    puts "  skip debug: #{fname}"
    next
  end

  # check for existing files
  if File.file?("#{dest}/build/#{proj}/#{repo}/#{arch}/:full/#{fname}")
    puts "  #{dest}/build/#{proj}/#{repo}/#{arch}/:full/#{fname} already exists!"

    tsize = File.size?("#{dest}/build/#{proj}/#{repo}/#{arch}/:full/#{fname}")
    puts "  size from existing target: #{tsize}" if verbose
    puts "  size from original source: #{fsize}" if verbose

    if tsize.to_i == fsize.to_i
      puts "  skip download: size identical"
      next
    else
      puts "  remove: size differnt"
      puts "  remove: #{dest}/build/#{proj}/#{repo}/#{arch}/:full/#{fname}"
      File.delete("#{dest}/build/#{proj}/#{repo}/#{arch}/:full/#{fname}") if !trialrun
    end
  end

  puts "  download:
  osc -A #{apiurl} api -m GET /build/#{proj}/#{repo}/#{arch}/_repository/#{fname} > #{dest}/build/#{proj}/#{repo}/#{arch}/:full/#{fname}" if verbose
  if trialrun
    puts "  trialrun: skip download"
  else
    # re-try download 3 times
    for i in 0..2
      unless system("osc -A #{apiurl} api -m GET /build/#{proj}/#{repo}/#{arch}/_repository/#{fname} > #{dest}/build/#{proj}/#{repo}/#{arch}/:full/#{fname}")
        puts "  retry #{i}: download failure" if verbose
        puts "  failure: download failure" if i == 2
        next
      else
        puts "  success: download finished" if verbose
        break
      end
    end
  end
}