-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathubuntu_setup_environment.sh
More file actions
executable file
·146 lines (118 loc) · 3.89 KB
/
ubuntu_setup_environment.sh
File metadata and controls
executable file
·146 lines (118 loc) · 3.89 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
#!/bin/bash -i
# Sets up dev-vm for APIM development
# Runs in interactive mode to enable environment activation testing
echo "Setting up environment for APIM development ..."
#Installing pyenv from pyenv-installer
echo "Installing pyenv from pyenv-installer ..."
if [[ ! -d $PYENV_ROOT ]] ; then
if curl https://pyenv.run | bash 2> /dev/null ; then
echo "Pyenv was installed correctly ..."
else
echo "Pyenv was NOT installed correctly ..."
exit 1
fi
else
echo "Pyenv already installed ..."
fi
BASHSTAMP="# APIM_DEV-VM"
#Adding pyenv configuration to .bashrc
#Prevents having users to logout/login during setup session
#Safe to be removed afterwards as bash_profile will take its place
echo "Adding pyenv configuration to .bashrc ..."
if ! grep -Fxq "$BASHSTAMP" $HOME/.bashrc ; then
cat <<EOF >> $HOME/.bashrc
$BASHSTAMP
export PYENV_ROOT="\$HOME/.pyenv"
export PATH="\$PYENV_ROOT/bin:\$PATH"
eval "\$(pyenv init --path)"
eval "\$(pyenv virtualenv-init -)"
eval "\$(pyenv init -)"
EOF
fi
source ~/.bashrc
#Checking if pyenv is installed
echo "Checking if pyenv is installed ..."
if pyenv -v > /dev/null ; then
echo "Pyenv is installed."
else
echo "Pyenv is NOT installed."
exit 1
fi
#Installing python dependencies
echo "Installing python dependencies ..."
sudo apt update
if sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev git ; then
echo "Python dependencies were installed successfully."
else
echo "Python dependencies were NOT installed successfully."
exit 1
fi
#Installing python 3.13 with pyenv
echo "Installing python 3.13 with pyenv ..."
if pyenv versions | grep -Fq "3.13" ; then
echo "Pyenv has already got Python 3.13 installed."
else
if pyenv install 3.13 ; then
echo "Pyenv installed Python 3.13 successfully."
else
echo "Pyenv did NOT install Python 3.13 successfully."
exit 1
fi
fi
#Creating Apigee environment with Python 3.13
echo "Creating Apigee environment with Python 3.13 ..."
if pyenv versions | grep -q ".*apigee" ; then
echo "A Python virtualenv named 'apigee' already exists."
else
if pyenv virtualenv 3.13 apigee ; then
echo "A Python 3.13 virtualenv named 'apigee' was created."
else
echo "A Python 3.13 virtualenv named 'apigee' was NOT created."
exit 1
fi
fi
#Activating apigee environment
echo "Activating apigee environment ..."
if pyenv local apigee ; then
echo "Apigee enviroment activated."
else
echo "Apigee enviroment NOT activated."
exit 1
fi
#Checking python version
echo "Checking python version ..."
version=$(python -V 2>&1)
if [[ $version = 'Python 3.13'* ]] ; then
echo "Python version is correct."
else
echo "Python version is NOT correct."
exit 1
fi
#Updating pip
if pip install --upgrade pip ; then
echo "Pip was updated."
else
echo "Pip was NOT updated."
exit 1
fi
#Installing poetry
echo "Installing poetry ..."
if poetry -V 2> /dev/null ; then
echo "Poetry is already installed on apigee environment."
else
if pip install poetry ; then
echo "Poetry was installed on apigee environment."
else
echo "Poetry was NOT installed on apigee environment."
exit 1
fi
fi
printf "\n\nSetup successfull! \n \
The apigee environment is now set with the .python-version file,\n \
\033[1mso there's no need to run $ pyenv activate apigee\033[0m,\n \
cd'ing to the repo should suffice.\n \
Please \033[1mopen another terminal\033[0m to update your \$PATH and run:\n \
\033[1m$ pyenv version\033[0m, which should output 'apigee'\n \
\033[1m$ make install\033[0m to finish environment setup.\n \
If something went wrong during the setup scripts, you can execute\n \
\033[1m$ make clean-environment\033[0m (N.B. This will remove the ~/.pyenv directory)\n\n"