#!/bin/bash
if ! [[ "$1" =~ -v([[:digit:]]+)$ ]]; then
echo "Usage: $0 -vN"
exit 1
fi
version_pat="v?${BASH_REMATCH[1]}(\.[0-9]{1,}){1,}$"
curr_branch="$(git branch | pcregrep -o1 '^\*\s+(.+)$')"
# fetch the latest releases
echo -e "\tRetrieving latest changes from upstream..." && git pull --tags
echo -e "\n\tDone"
version="$(git tag | egrep $version_pat | sort --version-sort -r | head -n1)"
if [ -z "$version" ]; then
echo "That version number does not exist: ${1/-/}"
exit 1
fi
# See if we already have this release checked out
for v in $(echo -n "$curr_branch" "$(git branch | egrep -o $version_pat)"); do
if [[ "$v" =~ "$version" ]]; then
if [[ "$v" == "$curr_branch" ]]; then
echo "You are already on the latest release: $curr_branch"
else
echo "You already have the latest version: $v"
fi
exit 0
fi
done
echo "Found a more recent release: $version"
git checkout "$version" -b "v$version"
echo -e "\nUse the following command to build and install opencv:\n"
cat <<'END'
1. mkdir -p release && pushd release
2. cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local \
-D PYTHON2_EXECUTABLE=/usr/bin/python2 \
-D PYTHON2_INCLUDE_DIR=/usr/include/python2.7/ \
-D PYTHON2_INCLUDE_DIR2=/usr/include/x86_64-linux-gnu/python2.7/ \
-D PYTHON2_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so \
-D PYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/python2.7/dist-packages/numpy/core/include/ \
-D PYTHON3_EXECUTABLE=/usr/bin/python3 \
-D PYTHON3_INCLUDE_DIR=/usr/include/python3.5/ \
-D PYTHON3_INCLUDE_DIR2=/usr/include/x86_64-linux-gnu/python3.5m/ \
-D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so \
-D CMAKE_PREFIX_PATH=/opt/Qt/5.7/gcc_64/lib/cmake ..
3. make -j7 # runs 7 jobs in parallel
4. sudo make install
5. popd
END
echo -e "\n\t** Make sure to replace the paths with\n\tones corresponding to your machine **"