Created
May 23, 2019 09:43
-
-
Save tyluudinh/e4e3a7c6784d5b00cb147298495c116d to your computer and use it in GitHub Desktop.
Upload Image to AWS S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Define Color text | |
NONE='\033[00m' | |
RED='\033[01;31m' | |
GREEN='\033[01;32m' | |
YELLOW='\033[01;33m' | |
PURPLE='\033[01;35m' | |
CYAN='\033[01;36m' | |
WHITE='\033[01;37m' | |
BOLD='\033[1m' | |
UNDERLINE='\033[4m' | |
# Default DEV | |
bucket="jio-static-dev" | |
profile="" | |
# PROD | |
if [ "$1" == "prod" ]; then | |
bucket="jio-static" | |
profile="--profile prod" | |
fi | |
# QA | |
if [ "$1" == "qa" ]; then | |
bucket="jio-static-qa" | |
profile="--profile prod" | |
fi | |
# echo -e "${PURPLE}$url_aws_s3${NONE}" | |
total=0 | |
new_product=0 | |
old_product=0 | |
for i in a/* ; do | |
if [ -d "$i" ]; then | |
stockID=$(basename "$i") | |
total=$(( $total + 1 )) | |
url_aws_s3="s3://$bucket/pharmacy/product/$stockID/" | |
count=$(aws s3 ls $url_aws_s3 $profile | wc -l) | |
# echo -e "${RED}$url_aws_s3${NONE}: ${GREEN}$count${NONE}" | |
if [ $count -eq 0 ]; | |
then | |
new_product=$(( $new_product + 1 )) | |
# Upload File | |
echo -e "${BOLD}------------- Uploading file in stock $stockID -------------${NONE}" | |
aws s3 sync a/$stockID/. $url_aws_s3 --acl public-read $profile | |
echo -e "${GREEN}--------------------------DONE------------------------------${NONE}" | |
else | |
old_product=$(( $old_product + 1 )) | |
# Empty File | |
echo -e "${RED}------------- Empty file in stock $stockID -------------${NONE}" | |
aws s3 sync empty/. $url_aws_s3 --delete $profile | |
echo -e "${RED}--------------------------------------------------------${NONE}" | |
# # Upload File | |
echo -e "${YELLOW}------------- Uploading file in stock $stockID -------------${NONE}" | |
aws s3 sync a/$stockID/. $url_aws_s3 --acl public-read $profile | |
echo -e "${GREEN}--------------------------DONE------------------------------${NONE}" | |
fi | |
fi | |
done | |
echo -e "\n${GREEN}Upload successfully at `date` !${NONE} ${BOLD}Total Product = $total${NONE}; ${PURPLE}New = $new_product${NONE}; ${YELLOW}Overwrite = $old_product${NONE}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment