#!/usr/bin/env ruby $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib') require "s3ranger/exceptions" require "s3ranger/config" require "s3ranger/cmd" conf = S3Ranger::Config.new # Time to load config and see if we've got everything we need to cook our salad begin conf.read rescue S3Ranger::NoConfigFound => exc # We can't proceed without having those two vars set if not (conf.has_key? "AWS_ACCESS_KEY_ID" and conf.has_key? "AWS_SECRET_ACCESS_KEY") $stderr.puts "You didn't set up your environment variables :(" $stderr.puts "I tried the following paths:" exc.paths_checked.each {|path| $stderr.puts " * #{path}/s3config.yml"} $stderr.puts "You could try to set the `S3CONF' environment variable." $stderr.puts "Learn how to do that here: https://github.com/clarete/s3ranger" exit end end # Step aside, the star of this show is here. Let's try to create the # environment to run the requested command. And feed the user back if # information needed was not enough begin S3Ranger::Cmd.new(conf) rescue S3Ranger::FailureFeedback => exc $stderr.puts exc.message exit 1 rescue S3Ranger::WrongUsage => exc name = $0.split('/').last $stderr.puts <<"ENDUSAGE" Usage: #{name} [options] [arg(s)] Global Options: -h, --help -v, --verbose -n, --dryrun -d, --debug --progress #{name} listbuckets List all available buckets #{name} createbucket Creates a new bucket Options: -a , --acl=(private|public_read|public_read_write) #{name} deletebucket [options] Removes an existing bucket Options: -f, --force Deletes non-empty buckets (BE CAREFUL) #{name} list [:prefix] List content inside of bucket if `prefix' is present, only content under `prefix' will be listed. #{name} delete : Removes `key` from `bucket` #{name} url [options] : Generates a presigned URL for an operation on the object named `key' found on `bucket'. Options: --no-ssl --expires-in=(<# of seconds> | [#d|#h|#m|#s]) #{name} get : Retrieves the remote `key` object from `bucket` and saves to the local path specified in `file` #{name} put [:] Uploads the file `file` to the `bucket` under the path `key` #{name} sync One of source or destination must be remote and the other must be local, where local points to a folder in the file system and remote conform to the format `[:]`. Options: -e , --exclude= -k, --keep -d, --dry-run ENDUSAGE $stderr.puts "\nCurrent error:\n #{exc.msg}\n" if exc.msg exit exc.error_code end