-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·86 lines (63 loc) · 1.4 KB
/
entrypoint.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
warn () {
text=$1
echo -e "\e[1;33m $text \e[0m"
}
fail () {
text=$1
echo -e "\e[1;31m $text \e[0m"
exit 1
}
success () {
text=$1
echo -e "\e[1;32m $text \e[0m"
}
info () {
text=$1
echo -e "\e[1;34m $text \e[0m"
}
debug () {
text=$1
echo -e "\e[1;40m $text \e[0m"
}
set_auth() {
local s3cnf="$HOME/.s3cfg"
if [ -e "$s3cnf" ]; then
warn '.s3cfg file already exists in home directory and will be overwritten'
fi
echo '[default]' > "$s3cnf"
echo "access_key=$ACCESS_KEY" >> "$s3cnf"
echo "secret_key=$SECRET_KEY" >> "$s3cnf"
if [ -n "$ENDPOINT" ]; then
echo "host_base=$ENDPOINT" >> "$s3cnf"
echo "host_bucket=%(bucket)s.$ENDPOINT" >> "$s3cnf"
fi
echo "use_https=True" >> "$s3cnf"
echo "Generated .s3cfg for key $ACCESS_KEY"
}
main() {
set_auth
info 'Starting S3 Synchronisation'
info 'Check s3cmd version'
info $(s3cmd --version)
if [ -z "$ACCESS_KEY" ]; then
fail 'ACCESS_KEY is not set. Quitting.'
fi
if [ -z "$SECRET_KEY" ]; then
fail 'AWS_SECRET_ACCESS_KEY is not set. Quitting.'
fi
if [ -z "$BUCKET" ]; then
fail 'BUCKET is not set. Quitting.'
fi
if [ -z "$SOURCES" ]; then
fail 'SOURCES is not set. Quitting.'
fi
if [ -z "$OPTIONS" ]; then
OPTIONS=""
fi
RESULT=$(s3cmd put $SOURCES s3://$BUCKET/$TARGET/ $OPTIONS)
echo $RESULT;
warn 'Removing .s3cfg credentials'
rm "$HOME/.s3cfg"
}
main