-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup.sh
129 lines (116 loc) · 4.68 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# This file should be sourced, not executed, to set up the environment.
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
scriptdir=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
repodir=$scriptdir
pushd $repodir
if ! yum list installed make &> /dev/null; then
echo -e "\nInstalling make"
if ! sudo yum -y install make; then
echo -e "\nwarning: Couldn't install make"
fi
fi
if ! yum list installed wget &> /dev/null; then
echo -e "\nInstalling wget"
if ! sudo yum -y install wget; then
echo -e "\nwarning: Couldn't install wget"
fi
fi
if ! python3 --version &> /dev/null; then
echo -e "\nInstalling python3"
if ! sudo yum -y install python3; then
echo -e "\nerror: Couldn't find python3 in the path or install it. This is required."
return 1
fi
fi
# Check python version
python_version=$(python3 --version 2>&1 | awk '{print $2}')
python_major_version=$(echo $python_version | cut -d '.' -f 1)
python_minor_version=$(echo $python_version | cut -d '.' -f 2)
if [[ $python_minor_version -lt 7 ]]; then
echo "error: CDK requires python 3.7 or later. You have $python_version. Update your python3 version."
return 1
fi
echo "Using python $python_version"
# Check nodejs version
# https://nodejs.org/en/about/previous-releases
required_nodejs_version=16.20.2
# required_nodejs_version=18.20.2
# On Amazon Linux 2 and nodejs 18.20.2 I get the following errors:
# node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
# node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
# required_nodejs_version=20.13.1
# On Amazon Linux 2 and nodejs 20.13.1 I get the following errors:
# node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
# node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
export JSII_SILENCE_WARNING_DEPRECATED_NODE_VERSION=1
if ! which node &> /dev/null; then
echo -e "\nnode not found in your path."
echo "Installing nodejs in your home dir. Hit ctrl-c to abort"
pushd $HOME
wget https://nodejs.org/dist/v${required_nodejs_version}/node-v${required_nodejs_version}-linux-x64.tar.xz
tar -xf node-v${required_nodejs_version}-linux-x64.tar.xz
rm node-v${required_nodejs_version}-linux-x64.tar.xz
cat >> ~/.bashrc << EOF
# Nodejs
export PATH=$HOME/node-v${required_nodejs_version}-linux-x64/bin:\$PATH
EOF
source ~/.bashrc
popd
fi
nodejs_version=$(node -v 2>&1 | awk '{print $1}')
nodejs_version=${nodejs_version:1}
node_major_version=$(echo $nodejs_version | cut -d '.' -f 1)
node_minor_version=$(echo $nodejs_version | cut -d '.' -f 2)
if [[ $node_major_version -lt 14 ]]; then
echo "error: CDK requires node 14.15.0 or later. You have $nodejs_version. Update your node version."
return 1
fi
if [[ $node_major_version -eq 14 ]] && [[ $node_minor_version -lt 6 ]]; then
echo "error: CDK requires node 14.15.0 or later. You have $nodejs_version. Update your node version."
return 1
fi
if [[ $nodejs_version != $required_nodejs_version ]]; then
echo "Updating nodejs version from $nodejs_version toe $required_nodejs_version"
pushd $HOME
wget https://nodejs.org/dist/v${required_nodejs_version}/node-v${required_nodejs_version}-linux-x64.tar.xz
tar -xf node-v${required_nodejs_version}-linux-x64.tar.xz
rm node-v${required_nodejs_version}-linux-x64.tar.xz
cat >> ~/.bashrc << EOF
# Nodejs
export PATH=$HOME/node-v${required_nodejs_version}-linux-x64/bin:\$PATH
EOF
source ~/.bashrc
popd
fi
echo "Using nodejs version $nodejs_version"
# Create a local installation of cdk
CDK_VERSION=2.111.0 # When you change the CDK version here, make sure to also change it in source/requirements.txt
if ! cdk --version &> /dev/null; then
echo "CDK not installed. Installing global version of cdk@$CDK_VERSION."
if ! npm install -g aws-cdk@$CDK_VERSION; then
sudo npm install -g aws-cdk@$CDK_VERSION
fi
fi
cdk_version=$(cdk --version | awk '{print $1}')
if [[ $cdk_version != $CDK_VERSION ]]; then
echo "Updating the global version of aws-cdk from version $cdk_version to $CDK_VERSION"
echo "Uninstalling old version: npm uninstall -g aws-cdk"
npm uninstall -g aws-cdk
echo "npm install -g aws-cdk@$CDK_VERSION"
if ! npm install -g --force aws-cdk@$CDK_VERSION; then
sudo npm install -g --force aws-cdk@$CDK_VERSION
fi
fi
echo "Using CDK $cdk_version"
# Create python virtual environment
cd $repodir/source
if [ ! -e $repodir/source/.venv/bin/activate ]; then
rm -f .requirements_installed
python3 -m pip install --upgrade virtualenv
python3 -m venv .venv
fi
source .venv/bin/activate
make .requirements_installed
popd