-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3-uploader.sh
68 lines (54 loc) · 1.79 KB
/
s3-uploader.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
# Check if the search filter argument is provided
if [ -z "$1" ]; then
echo "Please provide a search filter as an argument."
exit 1
fi
# Set the search filter from the command-line argument
SEARCH_FILTER="$1"
# Check if the destination bucket environment variable is set
if [ -z "$DESTINATION_BUCKET" ]; then
echo "Please set the DESTINATION_BUCKET environment variable."
exit 1
fi
# Check if the destination directory environment variable is set
if [ -z "$DESTINATION_DIRECTORY" ]; then
echo "Please set the DESTINATION_DIRECTORY environment variable."
exit 1
fi
# Check if the S3 access key environment variable is set
if [ -z "$S3_ACCESS_KEY" ]; then
echo "Please set the S3_ACCESS_KEY environment variable."
exit 1
fi
# Check if the S3 secret key environment variable is set
if [ -z "$S3_SECRET_KEY" ]; then
echo "Please set the S3_SECRET_KEY environment variable."
exit 1
fi
# Check if the S3 endpoint environment variable is set
if [ -z "$S3_ENDPOINT" ]; then
echo "Please set the S3_ENDPOINT environment variable."
exit 1
fi
# Set the S3 alias
mc alias set mys3 "$S3_ENDPOINT" "$S3_ACCESS_KEY" "$S3_SECRET_KEY"
# Find files matching the search filter and store them in a temporary file
find "/sharedvolume" -name "*$SEARCH_FILTER*.mp4" >temp.txt
# Check if any matching files were found
if [ ! -s "temp.txt" ]; then
echo "No matching files found."
rm temp.txt
exit 1
fi
echo "Uploading files..."
# Upload files matching the search filter to S3 storage using the MinIO Client (mc)
while IFS= read -r file_path; do
mc cp "$file_path" "mys3/$DESTINATION_BUCKET/$DESTINATION_DIRECTORY/"
done <temp.txt
# Delete the uploaded files
while IFS= read -r file_path; do
rm "$file_path"
done <temp.txt
# Remove the temporary file
rm temp.txt