Module: DHO

Included in:
PRM::Repo
Defined in:
lib/prm/repo.rb

Instance Method Summary collapse

Instance Method Details

#sync_to_dho(path, accesskey, secretkey, pcomponent, prelease) ⇒ Object



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/prm/repo.rb', line 266

def sync_to_dho(path, accesskey, secretkey,pcomponent,prelease)
    component = pcomponent.join
    release = prelease.join
    AWS::S3::Base.establish_connection!(
        :server             => 'objects.dreamhost.com',
        :use_ssl            => true,
        :access_key_id      => accesskey,
        :secret_access_key  => secretkey
    )

    AWS::S3::Service.buckets.each do |bucket|
        unless bucket == path
            AWS::S3::Bucket.create(path)
        end
    end

    new_content = Array.new
    Find.find(path + "/") do |object|
        object.slice!(path + "/")
        if (object =~ /deb$/) || (object =~ /Release$/) || (object =~ /Packages.gz$/) || (object =~ /Packages$/) || (object =~ /gpg$/)
            f = path + "/" + object
            new_content << object
            AWS::S3::S3Object.store(
                object,
                open(f),
                path
            )

            policy = AWS::S3::S3Object.acl(object, path)
            policy.grants = [ AWS::S3::ACL::Grant.grant(:public_read) ]
            AWS::S3::S3Object.acl(object,path,policy)
        end
    end

    bucket_info = AWS::S3::Bucket.find(path)
    bucket_info.each do |obj|
        o = obj.key
        if (o =~ /deb$/) || (o =~ /Release$/) || (o =~ /Packages.gz$/) || (o =~ /Packages$/) || (o =~ /gpg$/)
            unless new_content.include?(o)
                AWS::S3::S3Object.delete(o,path)
            end
        end
    end
    puts "Your apt repository is located at http://objects.dreamhost.com/#{path}/"
    puts "Add the following to your apt sources.list"
    puts "deb http://objects.dreamhost.com/#{path}/ #{release} #{component}"
end