-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
35 lines (33 loc) · 1.11 KB
/
run.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
#!/usr/bin/env sh
resource="/${S3_BUCKET}/${S3_CONF_SOURCE_FILE}"
contentType="text/plain"
while true
do
dateValue=`date -R`
stringToSign="GET\n\n${contentType}\n${dateValue}\n${resource}"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${AWS_SECRET_ACCESS_KEY} -binary | base64`
curl -H "Host: ${S3_BUCKET}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${AWS_ACCESS_KEY_ID}:${signature}" \
https://${S3_BUCKET}.s3.amazonaws.com/${S3_CONF_SOURCE_FILE} > /tmp/${S3_CONF_DEST_FILE}
if grep "<Error><Code>" /tmp/${S3_CONF_DEST_FILE}
then
exit 1
fi
if [ -f /conf/${S3_CONF_DEST_FILE} ]
then
chmod 600 /conf/${S3_CONF_DEST_FILE}
fi
cp -f /tmp/${S3_CONF_DEST_FILE} /conf/${S3_CONF_DEST_FILE}
chmod 400 /conf/${S3_CONF_DEST_FILE}
chown root:nobody /conf/${S3_CONF_DEST_FILE}
echo "Configuration downloaded okay"
if [ -n "$S3_CONF_AUTO_UPDATE_DELAY" ]
then
sleep "$S3_CONF_AUTO_UPDATE_DELAY"
else
#update after one hour
sleep 3600
fi
done