-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup
executable file
·207 lines (180 loc) · 5.57 KB
/
setup
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
#!/bin/bash
#Useful functions for setup script
function easyread() {
if [[ $MINGW_CHECK == false ]]
then
read -e -p "$1:" -i "$2"
else
read -e -p "$1 [$2]:"
fi
#Copy default value into return field
if [[ $REPLY == '' ]]
then
REPLY=$2
fi
}
function check-if-gitrepo()
{
#From http://stackoverflow.com/a/2185353/2059564
if git rev-parse --git-dir > /dev/null 2>&1; then
: # This is a valid git repository (but the current working
# directory may not be the top level.
# Check the output of the git rev-parse command if you care)
return 0
else
echo "The current folder is not a git repository! Until github adds"
echo "submodule archiving to their tags, the source folder must be a git repository."
echo
read -p "Would you like to clone the openhubo repository to continue [Y/n]?" CLONE_NEW_REPO
if [[ $CLONE_NEW_REPO == 'n' || $CLONE_NEW_REPO == 'N' ]]
then
echo "Exiting..."
exit 1
fi
local DEF_PATH=$HOME/openHubo
easyread "Type a destination path for repository:" "$DEF_PATH"; eval DEST_PATH=$REPLY
if git clone --recursive git://github.com/daslrobotics/openHubo.git "$DEST_PATH"
then
cd $DEST_PATH
return 0
else
exit 1
fi
fi
}
function verify-dep()
{
local RESULT=`dpkg-query -l $1 | grep "ii"`
local INSTALL_MISSING_DEP=''
if [[ ${#RESULT} == 0 ]]
then
read -p "Install missing dependent package/library $1 [Y/n]?" INSTALL_MISSING_DEP
if [[ $INSTALL_MISSING_DEP == 'n' || $INSTALL_MISSING_DEP == 'N' ]]
then
echo "WARNING: skipping dependent package/library $1..."
else
sudo apt-get install $1
fi
else
echo "package/library $1 is installed"
fi
}
function check-submodules()
{
#Check if submodules have changed and ask user to decide whether to checkout
#specified version in parent repository.
git submodule init
OLD_IFS=$IFS
IFS=$'\n'
for stat in `git submodule status`
do
local PLUGIN_STATUS=`echo $stat | cut -c 1`
local PLUGIN_NAME=`echo $stat | awk '{print $2}'`
if [[ $PLUGIN_STATUS == '-' ]]
then
git submodule update $PLUGIN_NAME
fi
if [[ $PLUGIN_STATUS == '+' ]]
then
echo "-----------------------------------------------------"
echo "Submodule $PLUGIN_NAME has been changed from the default commit specified in this repository."
echo "Would you like to revert from the current state to the default commit?"
echo "Choose No (n) if you are making your own changes and want to build the plugins as-is"
read -p "Enter your choice [Y/n]?" SUBMODULE_UPDATE
if [[ $SUBMODULE_UPDATE == 'n' || $SUBMODULE_UPDATE == 'N' ]]
then
echo "Submodule update skipped..."
else
echo "Updating plugin $PLUGIN_NAME to match the current openHubo commit..."
git submodule update --init $PLUGIN_NAME
fi
fi
done
IFS=$OLD_IFS
}
#Install script starts here
check-if-gitrepo
if [[ $1 == "clean" ]]
then
./util/clean-all.sh
else
read -p "Clean up previous plugins (do this if there are any major changes to openhubo, like pulling a new version) [y/N]?" CLEANUP_PLUGINS
if [[ $CLEANUP_PLUGINS == 'Y' || $CLEANUP_PLUGINS == 'y' ]]
then
./util/clean-all.sh
fi
fi
#Check if python dependencies are installed (may not work for older Ubuntu versions)
for dep in ipython python-matplotlib python-scipy python-pip
do
verify-dep $dep
done
BASE_DIR=`git rev-parse --show-toplevel`
#Remove known old plugins that cause conflicts
rm $BASE_DIR/plugins/libopenmr.so
check-submodules
for p in servocontroller forceSensor
do
echo ""
echo "Building $p Plugin..."
echo ""
cd $BASE_DIR/$p/
[ -d build ] || mkdir build
cd build
cmake ../src/
make install
done
echo ""
echo "Building CoMPS plugins..."
echo ""
#CoMPS prereqs and build steps
for dep in libqhull-dev libqhull5 libnewmat10-dev libnewmat10ldbl libboost-regex-dev
do
verify-dep $dep
done
for pkg in generalik cbirrt2 manipulation2
do
cd $BASE_DIR/comps-code/$pkg
[ -d build ] || mkdir build
cd build
cmake ../
make install
done
cd $BASE_DIR
ENV_SOURCED_SEARCH=`grep $BASE_DIR/env.sh ~/.bashrc`
if [[ ${#ENV_SOURCED_SEARCH} == 0 ]]
then
echo "source $BASE_DIR/env.sh" >> ~/.bashrc
fi
#Strip out base folder definition and update with current
sed "s,\( OPENHUBO_DIR=\),\1$BASE_DIR," .env.template > env.sh
echo ""
echo "OpenHubo base folder is $BASE_DIR"
source env.sh
PLUGINS_LIST=`openrave.py --listplugins`
for f in `ls plugins/*.so`
do
PLUGIN_CHECK=`echo $PLUGINS_LIST | grep $f`
if [[ ${#PLUGIN_CHECK} == 0 ]]
then
echo "$f NOT found by OpenRAVE, please check the build log above!"
else
echo "$f found by OpenRAVE"
fi
done
# Canonicalize symlink path to be installed
OPENHUBO_LOCAL_EXEC_PATH=`readlink -f "$BASE_DIR/openhubo/bin/openhubo"`
OPENHUBO_BIN_PATH=$(which openhubo)
if [[ ${#OPENHUBO_BIN_PATH} > 0 ]]
then
OPENHUBO_CURRENT_LINK_TARGET=$(readlink $OPENHUBO_BIN_PATH)
fi
#TODO: simplify this part
if [[ ! $OPENHUBO_LOCAL_EXEC_PATH == $OPENHUBO_CURRENT_LINK_TARGET ]]
then
OPENHUBO_LINK='/usr/local/bin/openhubo'
echo -e "\nCreating openhubo symlink at $OPENHUBO_LINK"
sudo ln -sf $BASE_DIR/openhubo/bin/openhubo $OPENHUBO_LINK
else
echo -e "\nopenhubo symlink found at $OPENHUBO_CURRENT_LINK_TARGET"
fi