Created
November 19, 2024 14:51
-
-
Save decagondev/ba2430f133a21a745f5efbf5a43da1cd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
BUCKET_NAME="your-bucket-name" | |
FILE_NAME="myfile" | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 [on|off]" | |
exit 1 | |
fi | |
ACTION=$1 | |
if [ "$ACTION" == "on" ]; then | |
echo "Making $FILE_NAME public..." | |
aws s3api put-object-acl --bucket "$BUCKET_NAME" --key "$FILE_NAME" --acl public-read | |
if [ $? -eq 0 ]; then | |
echo "$FILE_NAME is now public." | |
else | |
echo "Failed to make $FILE_NAME public." | |
fi | |
elif [ "$ACTION" == "off" ]; then | |
echo "Making $FILE_NAME private..." | |
aws s3api put-object-acl --bucket "$BUCKET_NAME" --key "$FILE_NAME" --acl private | |
if [ $? -eq 0 ]; then | |
echo "$FILE_NAME is now private." | |
else | |
echo "Failed to make $FILE_NAME private." | |
fi | |
else | |
echo "Invalid argument. Use 'on' to make the file public or 'off' to make it private." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment