forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
download-programs
executable file
·61 lines (51 loc) · 1.24 KB
/
download-programs
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
#!/bin/bash
set -eu
scriptdir=$(cd $(dirname $0) && pwd)
if ! type aws > /dev/null; then
echo "Install the AWS CLI before running this script." >&2
exit 1
fi
if ! grep '\[hedy-logs-viewer\]' ~/.aws/credentials > /dev/null; then
echo "Add the following block to your ~/.aws/credentials file:" >&2
echo "" >&2
echo "[hedy-logs-viewer]" >&2
echo "aws_access_key_id = AKIA***********" >&2
echo "aws_secret_access_key = **************" >&2
echo ""
echo "(Ask someone from the team for the actual keys)" >&2
exit 1
fi
#----------------------------------------------------------------------
hedy_env=""
prefix=""
usage() {
echo "download-programs -e <ENVIRONMENT> [-d <YYYY-MM-DD>] <DIRECTORY>" >&2
}
while getopts "he:d:" OPTION
do
case $OPTION in
e)
hedy_env="$OPTARG"
;;
d)
prefix="/$OPTARG"
;;
h)
usage
exit 0
;;
esac
done
shift $((OPTIND -1))
dir="${1:-}"
if [[ "${dir}" == "" ]]; then
usage
exit 1
fi
#----------------------------------------------------------------------
mkdir -p "$dir"
export AWS_DEFAULT_REGION=eu-west-1
export AWS_PROFILE=hedy-logs-viewer
bucket=hedy-parse-logs
set -x
aws s3 sync s3://${bucket}/${hedy_env}${prefix} $dir