#!/bin/bash # Simple script to upload all files in current folder to S3 bucket "commutenation.com" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color print_error() { echo -e "${RED}ERROR: $1${NC}" >&2; } print_success() { echo -e "${GREEN}$1${NC}"; } print_info() { echo -e "${YELLOW}$1${NC}"; } # ============================================ # BUCKET CONFIGURATION # ============================================ BUCKET_NAME="commutenation.com" print_info "Target bucket: s3://$BUCKET_NAME" # ============================================ # Check if AWS CLI is installed if ! command -v aws &> /dev/null; then print_error "AWS CLI is not installed. Please install it first." exit 1 fi # Check if we're in a commutenation directory CURRENT_DIR=$(pwd) if [[ ! "$CURRENT_DIR" =~ /commutenation ]]; then print_error "Current directory is not a 'commutenation' folder or subfolder" print_info "Current path: $CURRENT_DIR" exit 1 fi # Extract the path relative to the commutenation folder RELATIVE_PATH=$(echo "$CURRENT_DIR" | sed -n 's/.*\/commutenation\///p') # Determine the S3 target path if [ -z "$RELATIVE_PATH" ]; then S3_TARGET_PATH="" print_info "Uploading from the 'commutenation' folder to bucket root" else S3_TARGET_PATH="$RELATIVE_PATH" print_info "Uploading subfolder: $RELATIVE_PATH" fi # Show files that will be uploaded echo "" echo "Files in current folder:" ls -la echo "" # Build file list (exclude hidden files, swp, tmp, log, pyc) FILES="" FILE_COUNT=0 for file in *; do if [ -f "$file" ]; then if [[ ! "$file" =~ ^\. ]] && [[ ! "$file" =~ \.(swp|tmp|log|pyc)$ ]]; then FILES="$FILES $file" ((FILE_COUNT++)) fi fi done if [ $FILE_COUNT -eq 0 ]; then print_error "No files found to upload." exit 1 fi echo "Files to upload: $FILES" echo "Total files: $FILE_COUNT" echo "" # Show what will happen echo "=== DRY RUN ===" for file in $FILES; do if [ -z "$S3_TARGET_PATH" ]; then echo " s3://$BUCKET_NAME/$file" else echo " s3://$BUCKET_NAME/$S3_TARGET_PATH/$file" fi done echo "" # Ask for confirmation read -p "Upload these $FILE_COUNT files? (y/N) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then print_info "Upload cancelled." exit 0 fi # Verify bucket exists if ! aws s3 ls "s3://$BUCKET_NAME" &> /dev/null; then print_error "Bucket '$BUCKET_NAME' does not exist or you don't have access." exit 1 fi # Upload using wildcard - THIS WILL UPLOAD ALL FILES echo "" print_info "Uploading all files..." if [ -z "$S3_TARGET_PATH" ]; then # Upload to root using wildcard aws s3 cp * "s3://$BUCKET_NAME/" --exclude ".*" --exclude "*.swp" --exclude "*.tmp" --exclude "*.log" --exclude "*.pyc" --recursive else # Upload to subfolder using wildcard aws s3 cp * "s3://$BUCKET_NAME/$S3_TARGET_PATH/" --exclude ".*" --exclude "*.swp" --exclude "*.tmp" --exclude "*.log" --exclude "*.pyc" --recursive fi if [ $? -eq 0 ]; then print_success "Upload completed successfully!" echo "" if [ -z "$S3_TARGET_PATH" ]; then print_info "Files uploaded to: s3://$BUCKET_NAME/" echo " https://$BUCKET_NAME.s3.amazonaws.com/" else print_info "Files uploaded to: s3://$BUCKET_NAME/$S3_TARGET_PATH/" echo " https://$BUCKET_NAME.s3.amazonaws.com/$S3_TARGET_PATH/" fi else print_error "Upload failed!" exit 1 fi