#!/usr/bin/env ruby # Upload a bunch of files to S3 with an index page; # send the index page to your friends! # # Note that your filename pattern will not upload directories, only files; # and that it doesn't yet recursively descend into directories require 'rubygems' require 'readline' require File.join(File.dirname(__FILE__), '../../lib/s33r') include S33r include Readline # AMAZON S3 KEYS!!! accesskey = 'accesskey' secretaccesskey = 'secretaccesskey' if 'accesskey' == accesskey config, _ = S33r.load_config('../fores33r/config/s3.yaml') accesskey = config[:access] secretaccesskey = config[:secret] end puts "****************************" # Get bucket name from the user. bucket_name = "elliotsmith-marvellous-bucket" entered_bucket = readline("Enter name of bucket to use (will be created if it doesn't exist) \n\ Press Enter to use default [#{bucket_name}]: ", true) bucket_name = entered_bucket if entered_bucket.size > 0 puts "" # Get a list of files to upload from the user. pattern = readline("Enter a pattern which matches the files you want to upload\n\ e.g. /home/pete/photos/*.jpg will upload all *.jpg files in /home/pete/photos\n\ (basically, its a Ruby glob pattern which will return files):\n", true) files = Dir[pattern] # Get an S3 client. client = Client.new(:access => accesskey, :secret => secretaccesskey, :persistent => true) # Create the bucket if it doesn't exist. unless client.bucket_exists?(bucket_name) puts "Creating new bucket #{bucket_name}" client.create_bucket(bucket_name) puts "" end # Start creating the download server. puts "****************************" puts "Your \"instant download server\" will be ready in a jiffy" puts "" # Get Bucket instance. bucket = client.get_bucket(bucket_name) # We're going to create an HTML listing from the list of files # (yes, I know it's broken HTML), then upload it. Self-reflexive! html = "