Skip to content

Instantly share code, notes, and snippets.

@krakatoa
Created July 25, 2017 03:19
Show Gist options
  • Save krakatoa/4fd8fa9ede4b2b7141f521985e273ae1 to your computer and use it in GitHub Desktop.
Save krakatoa/4fd8fa9ede4b2b7141f521985e273ae1 to your computer and use it in GitHub Desktop.
Storj.io bulk download & upload bash scripts
#!/bin/bash
export STORJ_KEYPASS=$STORJ_KEYPASS
bucket_name=$1
base_path=$2
function show_help {
echo "Usage: STORJ_KEYPASS=<YOUR-KEYPASS> $0 <bucket-name> <base-path>"
}
if [[ $# -lt 2 ]]; then
echo "Wrong parameters"
show_help
exit 1
fi
function get_bucket_id {
bucket_name=$1
out=$(storj list-buckets | grep "$bucket_name\$" | awk '{print $2}')
if [[ $out ]]; then
echo $out
fi
}
bucket_id=$(get_bucket_id $bucket_name)
if ! [[ $bucket_id ]]; then
echo "Bucket '$bucket_name' not found!"
exit 1
fi
mkdir -p $base_path
storj list-files $bucket_id | awk '{print $2 ":" $13}' | while IFS=: read id name; do
echo "id=$id name=$name"
storj download-file $bucket_id $id $base_path/$name
done
#!/bin/bash
export STORJ_KEYPASS=$STORJ_KEYPASS
bucket_name=$1
shift
function show_help {
echo "Usage: $0 <bucket-name> <path>"
}
if [[ $# -lt 2 ]]; then
echo "Wrong parameters"
show_help
exit 1
fi
function proceed_upload {
bucket_id=$1
shift
for f in "$@"; do
echo "Uploading $f"
storj upload-file $bucket_id "$f"
done
}
function fetch_bucket_id {
bucket_name=$1
bucket_id=$(get_bucket_id $bucket_name)
if [[ $bucket_id ]]; then
echo $bucket_id
else
echo $(create_bucket $bucket_name)
fi
}
function get_bucket_id {
bucket_name=$1
out=$(storj list-buckets | grep "$bucket_name\$" | awk '{print $2}')
if [[ $out ]]; then
echo $out
fi
}
function create_bucket {
echo "Creating bucket..."
out=$(storj add-bucket $bucket_name)
echo $(get_bucket_id $bucket_name)
}
bucket_id=$(fetch_bucket_id $bucket_name)
echo "Using bucket: $bucket_name ($bucket_id)"
proceed_upload $bucket_id "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment