Created
April 13, 2024 13:08
-
-
Save Iheanacho-ai/2b7965f7e4fc393fb52678f586c90083 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
cloudUploader() { | |
if [ -f "$FILEPATH" ]; then | |
if aws s3 ls "$DESTINATION_PATH"/"$file_name"; then # Check if file exists on cloud | |
while true; do | |
echo "File already exists on cloud. Choose an action: (o)verwrite, (s)kip, (r)ename:" | |
read action | |
case "$action" in | |
o) | |
# Overwrite: Proceed with upload | |
if aws s3 cp "$FILEPATH" "$DESTINATION_PATH"/"$file_name"; then | |
echo "File overwritten successfully." | |
else | |
echo "Upload failed." | |
fi | |
break | |
;; | |
s) | |
echo "File skipped." | |
break | |
;; | |
r) | |
echo "Enter a new name for the file:" | |
# receive the variable from the terminal | |
read new_name | |
# create a new destination file name | |
new_destination="$DESTINATION_PATH/$new_name" # Append new name to destination | |
if aws s3 cp "$FILEPATH" "$new_destination"; then | |
echo "File renamed and uploaded successfully." | |
else | |
echo "Renaming and upload failed." | |
fi | |
break | |
;; | |
*) | |
echo "Invalid action." | |
;; | |
esac | |
done | |
else | |
# File doesn't exist on cloud, proceed with upload | |
if aws s3 cp "$FILEPATH" "$DESTINATION_PATH"; then | |
echo "Upload successful." | |
else | |
echo "Upload failed." | |
fi | |
fi | |
else | |
echo "File does not exist." | |
fi | |
} | |
cloudUploader |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment