-
Notifications
You must be signed in to change notification settings - Fork 11
/
deploy.sh
executable file
·262 lines (228 loc) · 8.53 KB
/
deploy.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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/env bash
set -e # fail on errors
#set -x # echo commands run
while [[ $# > 1 ]]
do
key="$1"
case $key in
-o|--owner)
REPOSITORY_OWNER="$2"
shift
;;
-r|--repo)
REPOSITORY_NAME="$2"
shift
;;
-b|--branch)
GITHUB_BRANCH="$2"
shift
;;
-w|--workspace)
WORKSPACE_PATH="$2"
shift
;;
-v|--rosversion)
ROS_VERSION="$2"
shift
;;
-i|--installfile)
INSTALL_FILE="$2"
shift
;;
-l|--githublogin)
GITHUB_LOGIN="$2"
shift
;;
-p|--githubpassword)
GITHUB_PASSWORD="$2"
shift
;;
-s|--usesshuri)
USE_SSH_URI="$2"
shift
;;
-c|--configbranch)
SR_CONFIG_BRANCH="$2"
shift
;;
-t|--tagslist)
TAGS_LIST="$2"
shift
;;
*)
# ignore unknown option
;;
esac
shift
done
if [ -z "${REPOSITORY_OWNER}" ]; then
REPOSITORY_OWNER="shadow-robot"
fi
if [ -z "${REPOSITORY_NAME}" ]; then
REPOSITORY_NAME="sr_interface"
fi
export PROJECT_NAME=${REPOSITORY_NAME}
if [ -n "${INSTALL_FILE}" ];
then
PROJECT_NAME=$(basename $INSTALL_FILE)
PROJECT_NAME=${PROJECT_NAME%.*}
fi
if [ -z "${WORKSPACE_PATH}" ];
then
WORKSPACE_PATH="~{{ ros_user }}/workspace/${PROJECT_NAME}/base"
fi
if [ -z "${ROS_VERSION}" ];
then
ROS_VERSION="indigo"
fi
if [ -z "${SR_CONFIG_BRANCH}" ];
then
SR_CONFIG_BRANCH="${ROS_VERSION}-devel"
fi
echo "================================================================="
echo "| |"
echo "| Shadow default installation tool |"
echo "| |"
echo "================================================================="
echo ""
echo "possible options: "
echo " * -o or --owner name of the GitHub repository owner (shadow-robot by default)"
echo " * -r or --repo name of the owners repository (sr-interface by default)"
echo " * -w or --workspace path you want to use for the ROS workspace. The directory will be created. (~<current_user>/workspace/<project_name>/base by default)"
echo " * -v or --rosversion ROS version name (indigo by default)"
echo " * -b or --branch repository branch"
echo " * -i or --installfile relative path to rosintall file. When specified then sources from this rosintall file are installed not repository itself"
echo " * -l or --githublogin github login for private repositories."
echo " * -p or --githubpassword github password for private repositories."
echo " * -s or --usesshuri flag informing that ssh format github uris will be used. Set true to enable, set false or do not set to disable"
echo ""
echo "example: ./deploy.sh -o shadow-robot -r sr_interface -w ~{{ros_user}}/workspace/shadow/base -l mygithublogin -p mysupersecretpassword"
echo ""
echo "owner = ${REPOSITORY_OWNER}"
echo "repo = ${REPOSITORY_NAME}"
echo "ROS = ${ROS_VERSION}"
echo "workspace = ${WORKSPACE_PATH}"
echo "branch = ${GITHUB_BRANCH:-'default'}"
echo "install file = ${INSTALL_FILE}"
echo "project name = ${PROJECT_NAME}"
echo "tags list = ${TAGS_LIST}"
if [ -z "${GITHUB_PASSWORD}" ] && [ -n "${GITHUB_LOGIN}" ]; then
echo "git user = ${GITHUB_LOGIN}"
echo -n "${GITHUB_LOGIN}'s GitHub password:"
read -s GITHUB_PASSWORD
echo
fi
export SR_BUILD_TOOLS_HOME=/tmp/sr-build-tools
export PROJECT_HOME_DIR=/tmp/my_project
export SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
export ANSIBLE_INVENTORY="${SR_BUILD_TOOLS_HOME}/ansible/hosts"
export PLAYBOOKS_DIR="${SR_BUILD_TOOLS_HOME}/ansible"
export ANSIBLE_ROLES_PATH="${SR_BUILD_TOOLS_HOME}/ansible/roles"
export ANSIBLE_CALLBACK_PLUGINS="${SR_BUILD_TOOLS_HOME}/ansible/callback_plugins"
export ANSIBLE_HOST_KEY_CHECKING=False
export ANSIBLE_SSH_ARGS=" -o UserKnownHostsFile=/dev/null "
export ANSIBLE_LOG_PATH=~/build_tools_ansible.log
ROSINTSTALL_FILE_CONTENT="- git: {local-name: \"${PROJECT_NAME}\", uri: "
if [ -z "${USE_SSH_URI}" ] || [ "${USE_SSH_URI}" = false ]; then
if [ -z "${GITHUB_LOGIN}" ]; then
REPOSITORY_URL="https://github.com/${REPOSITORY_OWNER}/${REPOSITORY_NAME}.git"
ROSINTSTALL_FILE_CONTENT="${ROSINTSTALL_FILE_CONTENT}\"${REPOSITORY_URL}\""
GITHUB_CREDENTIALS=""
else
REPOSITORY_URL="https://${GITHUB_LOGIN}:${GITHUB_PASSWORD}@github.com/${REPOSITORY_OWNER}/${REPOSITORY_NAME}.git"
ROSINTSTALL_FILE_CONTENT="${ROSINTSTALL_FILE_CONTENT}\"https://{{github_login}}:{{github_password}}@github.com/${REPOSITORY_OWNER}/${REPOSITORY_NAME}.git\""
GITHUB_CREDENTIALS=" \"github_login\":\"${GITHUB_LOGIN}\", \"github_password\":\"${GITHUB_PASSWORD}\", "
fi
elif [ "${USE_SSH_URI}" = true ]; then
echo "Using ssh github uri format"
REPOSITORY_URL="[email protected]:${REPOSITORY_OWNER}/${REPOSITORY_NAME}.git"
ROSINTSTALL_FILE_CONTENT="${ROSINTSTALL_FILE_CONTENT}\"${REPOSITORY_URL}\""
GITHUB_CREDENTIALS=" \"use_ssh_uri\":\"true\", "
else
echo "Incorrect ssh key flag value"
exit 1
fi
if [ -z "${TAGS_LIST}" ]; then
export MY_ANSIBLE_PARAMETERS="-vvv --ask-become-pass ${PLAYBOOKS_DIR}/vagrant_site.yml --tags default"
else
export MY_ANSIBLE_PARAMETERS="-vvv --ask-become-pass ${PLAYBOOKS_DIR}/vagrant_site.yml --tags default,${TAGS_LIST}"
fi
export EXTRA_ANSIBLE_PARAMETER_ROS_USER=" \"ros_user\":\"`whoami`\", \"ros_group\":\"`whoami`\", "
echo ""
echo " ---------------------------------"
echo " | Installing needed packages |"
echo " ---------------------------------"
echo ""
# Wait for apt-get update lock file to be released
while (sudo fuser /var/lib/apt/lists/lock >/dev/null 2>&1) || (sudo fuser /var/lib/dpkg/lock >/dev/null 2>&1) do
echo "Waiting for apt-get update file lock..."
sleep 1
done
sudo apt-get update
# Wait for apt-get install lock file to be released
while sudo fuser /var/lib/dpkg/lock >/dev/null 2>&1; do
echo "Waiting for apt-get install file lock..."
sleep 1
done
sudo apt-get install -y python3-pip git subversion libyaml-dev libpython3-dev python3-crypto libssl-dev libffi-dev python3-dev sshpass &
rm -rf ${SR_BUILD_TOOLS_HOME} &
rm -rf ${PROJECT_HOME_DIR} &
wait
echo ""
echo " -------------------"
echo " | Cloning repo |"
echo " -------------------"
echo ""
git clone --depth 1 -b ${SR_BUILD_TOOLS_BRANCH:-"master"} https://github.com/shadow-robot/sr-build-tools.git ${SR_BUILD_TOOLS_HOME}
echo ""
echo " ----------------------------------"
echo " | Setting up requirements |"
echo " ----------------------------------"
echo ""
sudo pip3 install -r "${SR_BUILD_TOOLS_HOME}/ansible/data/requirements.txt"
sudo pip3 install --upgrade setuptools==51.1.1
echo ""
echo " ------------------------------------"
echo " | Creating repository.rosinstall |"
echo " ------------------------------------"
echo ""
ROS_WORKSPACE_INSTALL_FILE="${SR_BUILD_TOOLS_HOME}/repository.rosinstall"
if [ -z "${INSTALL_FILE}" ];
then
if [ -z "${GITHUB_BRANCH}" ]; then
ROSINTSTALL_FILE_CONTENT="${ROSINTSTALL_FILE_CONTENT} }"
else
ROSINTSTALL_FILE_CONTENT="${ROSINTSTALL_FILE_CONTENT}, version: \"${GITHUB_BRANCH}\" }"
fi
echo ${ROSINTSTALL_FILE_CONTENT} > ${ROS_WORKSPACE_INSTALL_FILE}
else
if [ -z "${GITHUB_BRANCH}" ]; then
git clone --depth 1 ${REPOSITORY_URL} ${PROJECT_HOME_DIR}
else
git clone --depth 1 -b ${GITHUB_BRANCH} ${REPOSITORY_URL} ${PROJECT_HOME_DIR}
fi
cp "${PROJECT_HOME_DIR}/${INSTALL_FILE}" ${ROS_WORKSPACE_INSTALL_FILE}
if [ "${USE_SSH_URI}" = true ]; then
sed -i "s|https://{{github_login}}:{{github_password}}@github.com/|[email protected]:|g" ${ROS_WORKSPACE_INSTALL_FILE}
fi
fi
echo ""
echo " -------------------"
echo " | Running Ansible |"
echo " -------------------"
echo ""
sudo sh -c "echo \"[dev-machine]
localhost ansible_connection=local\" > ${ANSIBLE_INVENTORY}"
export ROS_RELEASE_SETTINGS=" \"ros_release\":\"${ROS_VERSION}\", "
if [ "${ROS_VERSION}" != "indigo" ]; then
ROS_RELEASE_SETTINGS="${ROS_RELEASE_SETTINGS} \"ros_packages\":[], "
fi
export SR_CONFIG_BRANCH=" \"config_branch\":\"${SR_CONFIG_BRANCH}\", "
export WORKSPACE_SETTINGS="\"ros_workspace\":\"${WORKSPACE_PATH}\", \"ros_workspace_install\":\"${ROS_WORKSPACE_INSTALL_FILE}\" "
export EXTERNAL_VARIABLES_JSON="{ ${GITHUB_CREDENTIALS} ${EXTRA_ANSIBLE_PARAMETER_ROS_USER} ${ROS_RELEASE_SETTINGS} ${SR_CONFIG_BRANCH} ${WORKSPACE_SETTINGS}}"
ansible-playbook ${MY_ANSIBLE_PARAMETERS} --extra-vars "${EXTERNAL_VARIABLES_JSON}"
echo ""
echo " ------------------------------------------------"
echo " | Operation completed |"
echo " ------------------------------------------------"
echo ""