-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-s3.sh
65 lines (50 loc) · 1.06 KB
/
create-s3.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
#!/bin/bash
# Set endpoint
mc alias set s3 $ENDPOINT $MINIO_ROOT_USER $MINIO_ROOT_PASSWORD
lifecycle_days () {
# If set lifecycle
mc ilm import s3/$1 <<EOF
{
"Rules": [
{
"Expiration": {
"Days": $2
},
"ID": "OldFiles",
"Filter": {
"Prefix": "$3"
},
"Status": "Enabled"
}
]
}
EOF
}
## Create user
mc admin user add s3 $access_key $secret_key
if [ $? -gt 0 ];
then
echo "Error with create account"
exit 1
fi
# Set Policy readwrite
mc admin policy set s3 $POLICY_NAME user=$access_key
# Create buckets
for i in {1..1000}; do
var=INITIAL_BUCKET_NAME_$i
value=${!var}
if [ ${#value} -gt 0 ]; then
echo "Creating bucket ${value}"
mc mb s3/${value}
if [ $? -gt 0 ];
then
echo "Error with create bucket"
exit 1
fi
if [ ${#BUCKET_LIFECYCLE_DAYS} -gt 0 ];
then
lifecycle_days ${value} ${BUCKET_LIFECYCLE_DAYS} ${BUCKET_LIFECYCLE_PREFIX}
fi
fi
done
exit 0