-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsetup.sh
executable file
·97 lines (77 loc) · 2.45 KB
/
setup.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
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
# This script is the AWS CLI setup for the participants
echo -e 'Welcome to NovHack 2022!'
echo 'This script will set up your AWS credentials and check your connection'
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Download AWS CLI
echo 'Current AWS CLI version: '
aws --version
if [ $? -ne 0 ]; then
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
sudo ./aws/install
fi
echo 'Please provide your team name (team1 for example): '
echo 'Team name: '
read -r TEAM_NAME
echo 'Please provide your AWS credentials: '
echo 'AWS Access Key ID: '
read -r AWS_ACCESS_KEY_ID
echo 'AWS Secret Access Key: '
read -r AWS_SECRET_ACCESS_KEY
export AWS_REGION=eu-west-3
export AWS_OUTPUT=json
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
aws configure set region $AWS_REGION
aws configure set output $AWS_OUTPUT
# Use the default profile name
# Test if credentials are valid
aws sts get-caller-identity
if [ $? -eq 0 ]; then
echo "Success: AWS credentials correctly set up!"
else
echo "Failure: Invalid AWS credentials"
exit 1
fi
# Pull config file from s3
FILE_NAME="s3://novhack2022-application-configurations/application_properties_${TEAM_NAME}.properties"
aws s3 cp "${FILE_NAME}" ${SCRIPT_DIR}/applications/src/main/resources/application_properties.properties
if [ $? -eq 0 ]; then
echo "Success: Config file downloaded!"
else
echo "Failure: Invalid team name"
exit 1
fi
# Download historical data
aws s3 cp --recursive s3://novhack2022-client-data/prod/history ${SCRIPT_DIR}/data
if [ $? -eq 0 ]; then
echo "Success: Historical data downloaded!"
else
echo "Failure: failed to download the historical data"
exit 1
fi
# Get the sql script from S3
FILE_NAME="s3://novhack2022-sql-scripts/init_db.sql"
aws s3 cp "${FILE_NAME}" ${SCRIPT_DIR}/database/init_db.sql
if [ $? -eq 0 ]; then
echo "Success: init_db.sql script downloaded!"
else
echo "Failure: failed to download the init_db.sql script"
exit 1
fi
# Connexion with the database
# Connexion with the database
echo 'Current psql version: '
psql --version
if [ $? -ne 0 ]; then
sudo apt-get install postgresql
fi
./database/init-db.sh
if [ $? -eq 0 ]; then
echo "Success: Database initiated !"
else
echo "Failure: Failed to initiate the PostgreSQL database"
exit 1
fi
echo -e 'You are ready to use the code!\nGood luck! '