Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
190 lines (176 loc) · 6.12 KB
/
Copy pathsetup.sh
File metadata and controls
190 lines (176 loc) · 6.12 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# 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
arch=$(uname -m)
if [[ $arch == 'x86_64' ]]; then
shortarch='x64'
else
shortarch=$arch
fi
if [[ $(uname -s) == 'Linux' ]]; then
os=linux
installer='sudo yum -y'
shellrc='.bashrc'
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID-$VERSION_ID" in
"amzn-2"*)
echo "error: Unsupported OS $(uname -s)"
return 1
;;
"centos-7"*)
echo "error: Unsupported OS $(uname -s)"
return 1
;;
"centos-8"*)
echo "error: Unsupported OS $(uname -s)"
return 1
;;
"rhel-7"*)
echo "error: Unsupported OS $(uname -s)"
return 1
;;
"rhel-8"*)
distro="rhel8"
;;
"rhel-9"*)
distro="rhel9"
;;
"rocky-8"*)
distro="rocky8"
;;
"rocky-9"*)
distro="rocky9"
;;
esac
else
echo "error: Unsupported OS $(uname -s)"
return 1
fi
elif [[ $(uname -s) == 'Darwin' ]]; then
os=macos
installer='brew'
shellrc='.zshrc'
else
echo "error: Unsupported OS $(uname -s)"
return 1
fi
if ! make --version &> /dev/null; then
echo -e "\nInstalling make"
if ! $installer install make; then
echo -e "\nwarning: Couldn't install make"
fi
fi
if ! wget --version &> /dev/null; then
echo -e "\nInstalling wget"
if ! $installer install wget; then
echo -e "\nwarning: Couldn't install wget"
fi
fi
if ! python3 --version &> /dev/null; then
echo -e "\nInstalling python3"
if ! $installer 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=20.19.0
# 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."
nodejs_version=None
else
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 to $required_nodejs_version"
fi
fi
if [[ $nodejs_version != $required_nodejs_version ]]; then
echo "Installing nodejs ${required_nodejs_version} in your home dir. Hit ctrl-c to abort"
pushd $HOME
if [[ $os == 'linux' ]]; then
nodedir=node-v${required_nodejs_version}-linux-${shortarch}
elif [[ $os == 'macos' ]]; then
nodedir=node-v${required_nodejs_version}-darwin-${shortarch}
fi
tarball=${nodedir}.tar.xz
if ! wget https://nodejs.org/dist/v${required_nodejs_version}/$tarball; then
echo "error: Couldn't download nodejs from https://nodejs.org/dist/v${required_nodejs_version}/$tarball."
return 1
fi
tar -xf $tarball
rm $tarball
cat >> ~/$shellrc << EOF
# Nodejs
export PATH=$HOME/$nodedir/bin:\$PATH
EOF
source ~/$shellrc
popd
nodejs_version=$required_nodejs_version
fi
echo "Using nodejs version $nodejs_version"
# Create a local installation of cdk
CDK_VERSION=2.179.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
cdk_version=$CDK_VERSION
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