From 6cbaaf4ac7698ed82aa15c9c28a707a1e00f8018 Mon Sep 17 00:00:00 2001 From: shockrah Date: Sun, 8 Oct 2023 16:55:37 -0700 Subject: [PATCH] Useful script for storing huge media files and things in S3 --- main-site/scripts/inject-s3.sh | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 main-site/scripts/inject-s3.sh diff --git a/main-site/scripts/inject-s3.sh b/main-site/scripts/inject-s3.sh new file mode 100644 index 0000000..ae9813f --- /dev/null +++ b/main-site/scripts/inject-s3.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# This script is a cheesy way of injecting "large" files that I don't want to +# track with LFS into S3. +# > Why? +# Example is I have an image that is huge ( think dozens of MB large ) that I +# shrink down for the purpose of + +set -e + +usage() { + cat <<- EOF + $1 + Required: + Always make sure this is ran from the PROJECT_ROOT/main-site folder + + Usage: + bash scripts/inject-s3.sh my-file.ext /path/to/s3/destination + + Example: + bash scripts/inject-s3.sh ~/Downloads/big-vid.webm /video/cool-vid.webm + EOF +} +[[ $(basename $PWD) != main-site ]] && usage && exit 1 + +# Ensure the target local file is real +[[ ! -f "$1" ]] && usage "ERROR: Target file is not readable" && exit 1 + +# Ensure we are a given a destination in s3 +[[ -z "$2" ]] && usage "ERROR: No S3 destination given" && exit 1 + +# Next check to see if we are going to overwrite the file in s3 +bucket=temper.tv +if aws s3api head-object --bucket $bucket --key "$2"; then + echo "Found file at \"$2\", are you sure you want to overwrite? y/n" + read resp + if echo $resp | grep -i y; then + aws s3 cp "$1" "s3://${bucket}${2}" + else + echo "No overwrite requested, exiting (0) now" + fi +else + echo File location free, uploading now... + aws s3 cp "$1" "s3://${bucket}${2}" +fi + +# If we get this far it's because we found a file in place and want to ensure +# we don't overwrite on accident + + + +