-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-setup.sh
More file actions
executable file
·120 lines (98 loc) · 3.96 KB
/
Copy pathserver-setup.sh
File metadata and controls
executable file
·120 lines (98 loc) · 3.96 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
set -e
cd ~
# Install pyenv
if ! command -v pyenv &> /dev/null; then
echo -e "\nInstalling pre-prequisites for pyenv/python...\n----------------"
sudo apt update
sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl git libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
echo -e"\nInstalling pyenv...\n------------------"
curl -fsSL https://pyenv.run | bash
echo -e "\nSetting up pyenv in bashrc...\n----------------"
if ! grep -q 'export PATH="$HOME/.pyenv/bin:$PATH"' ~/.bashrc; then
echo -e '\n# Pyenv setup' >> ~/.bashrc
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
fi
source ~/.bashrc
else
echo -e "Pyenv is already installed\n--------------"
fi
echo -e "\nInstalling and setting global python to version 3.10.11 with pyenv...\n----------------"
pyenv install 3.10.11
pyenv global 3.10.11
# Install poetry
if ! command -v poetry &> /dev/null; then
echo -e "Installing pipx...\n-----------------"
sudo apt update
sudo apt install -y pipx
pipx ensurepath
source ~/.bashrc
echo -e "Installing poetry...\n-----------------"
pipx install poetry
else
echo -e "Poetry is already installed\n--------------"
fi
# Install cookiectter
if ! command -v cookiecutter &> /dev/null; then
echo -e "Setting cookiecutter path...\n-----------------"
echo -e '\n# cookiecutter setup' >> ~/.bashrc
echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc
echo -e "Installing cookiecutter...\n-----------------"
python3 -m pip install --user cookiecutter
else
echo -e "cookiecutter is already installed\n--------------"
fi
# Install AWS CLI
if ! command -v aws &> /dev/null; then
echo -e "Installing pre-requisites for AWS CLI...\n-----------------"
sudo apt update
sudo apt install -y groff less unzip
echo -e "Installing AWS CLI v2...\n-----------------"
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
rm ./awscliv2.zip
sudo ./aws/install
rm -rf ./aws/
else
echo -e "AWS CLI is already installed.\n-----------------"
fi
echo -e "Creating IAM profile...\n-----------------"
mkdir -p ~/.aws
cat > ~/.aws/config <<EOL
[default]
role_arn = arn:aws:iam::960710833509:role/ec2-instance-iam-role
credential_source = Ec2InstanceMetadata
region = us-west-2
EOL
# Generate SSH keys and setup GitHub
echo -e "Creating SSH keypair...\n-----------------"
ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa
echo -e "Prompting user to add public key to GitHub...\n-----------------"
echo "Add the following SSH key to https://github.com/settings/keys:"
cat ~/.ssh/id_rsa.pub
read -p "Press Enter after adding the key..."
echo -e "Configuring SSH agent in bashrc...\n-----------------"
echo -e '\n# Start SSH Agent' >> ~/.bashrc
echo 'eval `ssh-agent`' >> ~/.bashrc
echo 'ssh-add ~/.ssh/id_rsa' >> ~/.bashrc
source ~/.bashrc
echo "Cloning the cookiecutter GitHub repository...\n-----------------"
git clone git@github.com:RishabhMalviya/cookiecutter-kaggle.git
# Echo final steps
echo "Setup complete!"
cat << 'EOF'
-----------------
Now you just need to do two things:
1. The first is to attach the 'ec2-instance-iam-role' IAM role to this EC2 instance
2. The second is to update the IAM role's trust policy. You'll see an error message after this. Add the user in the that error message as a 'Principal' in the trust policy of the 'ec2-instance-iam-role' IAM role:
```
"Principal": {
"Service": "ec2.amazonaws.com",
"AWS": "arn:aws:sts::960710833509:assumed-role/ec2-instance-iam-role/i-0ebf3bb7d0d881d3d"
}
```
-----------------
EOF
aws s3 ls