| 1 |
#!/usr/bin/env bash |
| 2 |
# |
| 3 |
# Simple cmake wrapper script to make it behave more like autotools |
| 4 |
# |
| 5 |
# GPLv2 only - Copyright (C) 2008 - 2019 |
| 6 |
# David Sommerseth <[email protected]> |
| 7 |
# |
| 8 |
# This program is free software; you can redistribute it and/or |
| 9 |
# modify it under the terms of the GNU General Public License |
| 10 |
# as published by the Free Software Foundation; version 2 |
| 11 |
# of the License. |
| 12 |
# |
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program; if not, write to the Free Software |
| 20 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 |
# |
| 22 |
|
| 23 |
|
| 24 |
# Some default variables |
| 25 |
PREFIX="/usr/local" |
| 26 |
BINDIR="${PREFIX}/bin" |
| 27 |
BINDIR_SET=0 |
| 28 |
PLUGINDIR="${PREFIX}/lib/eurephia" |
| 29 |
PLUGINDIR_SET=0 |
| 30 |
XSLTPATH="${PREFIX}/share/eurephia/xslt" |
| 31 |
XSLTPATH_SET=0 |
| 32 |
EUREPHIADM_XSLT="${XSLTPATH}/eurephiadm" |
| 33 |
EUREPHIADM_XSLT_SET=0 |
| 34 |
MANDIR="${PREFIX}/share/man" |
| 35 |
MANDIR_SET=0 |
| 36 |
SQLITE3PREFIX="/var/lib/eurephia" |
| 37 |
CMAKE_BIN="cmake" |
| 38 |
|
| 39 |
|
| 40 |
# |
| 41 |
# Misc functions |
| 42 |
# |
| 43 |
usage() { |
| 44 |
cat <<EOF |
| 45 |
configure help for eurephia |
| 46 |
|
| 47 |
--help | -h -- This help screen |
| 48 |
|
| 49 |
** Main paths |
| 50 |
--prefix <path> -- Root directory of installation |
| 51 |
(default: ${PREFIX}) |
| 52 |
--bin-dir -- Directory where to place binaries |
| 53 |
(default: ${BINDIR}) |
| 54 |
--xslt-path | -X -- Default XSLT path |
| 55 |
(default: ${XSLTPATH}) |
| 56 |
|
| 57 |
** Debug options |
| 58 |
--debug | -D -- Enable verbose debug logging |
| 59 |
--show-secrets | -S -- Log passwords as clear text in log files |
| 60 |
| (only available when debug is enabled) |
| 61 |
--gcov | -- Enable gcov during building |
| 62 |
|
| 63 |
** Plug-in options |
| 64 |
--plug-in | -p -- Build the eurephia plug-in for OpenVPN |
| 65 |
--plug-in-dir | -P -- Destination path for the plug-ins and other modules |
| 66 |
(default: ${PLUGINDIR}) |
| 67 |
--openvpn-src <path> | -s <path> -- OpenVPN source directory (needed when building plug-in) |
| 68 |
--fw-iptables | -- Build iptables firewall module |
| 69 |
|
| 70 |
** Database options |
| 71 |
--db-sqlite3 | -- Build SQLite3 database module |
| 72 |
--sqlite3-path | -sp -- Root directory of SQLite3 eurephia database file |
| 73 |
(default: ${SQLITE3PREFIX}) |
| 74 |
** Administration utility options |
| 75 |
--eurephiadm | -A -- Build command line admin utility |
| 76 |
--eurephiadm-fw -- Include the firewall info even without any |
| 77 |
firewall interface being built |
| 78 |
--eurephiadm-xslt -- eurephiadm XSLT root path |
| 79 |
(default: ${EUREPHIADM_XSLT}) |
| 80 |
** Documentation |
| 81 |
--doxygen -- Compile Doxygen developer documentation |
| 82 |
--man-prefix -- Installation prefix for man pages |
| 83 |
|
| 84 |
** Build settings |
| 85 |
--cmake-bin -- CMake binary to use (default: ${CMAKE_BIN}) |
| 86 |
|
| 87 |
EOF |
| 88 |
} |
| 89 |
|
| 90 |
# Initialise variables which we will use later on |
| 91 |
PARAMS="" |
| 92 |
DB="" |
| 93 |
FW="" |
| 94 |
ADMIN=""; |
| 95 |
OPENVPN_SRC_DIR="" |
| 96 |
PLUGIN="" |
| 97 |
CONFIGUREPARAMS="$*" |
| 98 |
CFLAGS="$CFLAGS -std=gnu99 -fno-delete-null-pointer-checks -g -Wall -Wpointer-arith -fPIC" |
| 99 |
|
| 100 |
# Parse all arguments |
| 101 |
while [ ! -z "$1" ]; do |
| 102 |
case $1 in |
| 103 |
-h|--help) |
| 104 |
usage |
| 105 |
exit 0 |
| 106 |
;; |
| 107 |
--prefix) |
| 108 |
PREFIX="$2"; |
| 109 |
shift |
| 110 |
# Apply prefix to BINDIR only if it's not been set explicitly earlier |
| 111 |
if [ "${BINDIR_SET}" = "0" ]; then |
| 112 |
BINDIR="${PREFIX}/bin"; |
| 113 |
fi |
| 114 |
# Apply prefix to PLUGINDIR only if it's not been set explicitly earlier |
| 115 |
if [ "${PLUGINDIR_SET}" = "0" ]; then |
| 116 |
PLUGINDIR="${PREFIX}/lib/eurephia" |
| 117 |
fi |
| 118 |
# Apply prefix to XSLTPATHs only if it's not been set explicitly earlier |
| 119 |
if [ "${XSLTPATH_SET}" = "0" ]; then |
| 120 |
XSLTPATH="${PREFIX}/share/eurephia/xslt" |
| 121 |
if [ "${EUREPHIADM_XSLT_SET}" = "0" ]; then |
| 122 |
EUREPHIADM_XSLT="${XSLTPATH}/eurephiadm" |
| 123 |
fi |
| 124 |
fi |
| 125 |
# Apply prefix to man page directory only if not been set explicitly earlier |
| 126 |
if [ "${MANDIR_SET}" = "0" ]; then |
| 127 |
MANDIR="${PREFIX}/share/man" |
| 128 |
fi |
| 129 |
;; |
| 130 |
--bin-dir) |
| 131 |
BINDIR="$2" |
| 132 |
BINDIR_SET=1 |
| 133 |
shift |
| 134 |
;; |
| 135 |
-X|--xslt-path) |
| 136 |
XSLTPATH="$2" |
| 137 |
# Apply prefix to EUREPJIADM_XSLT path only if it's not been set explicitly earlier |
| 138 |
if [ "${EUREPHIADM_XSLT_SET}" = "0" ]; then |
| 139 |
EUREPHIADM_XSLT="${XSLTPATH}/eurephiadm" |
| 140 |
fi |
| 141 |
shift |
| 142 |
;; |
| 143 |
-D|--debug) |
| 144 |
PARAMS="${PARAMS} -DDEBUG=ON" |
| 145 |
DEBUG_WARN=1 |
| 146 |
;; |
| 147 |
-S|--show-secrets) |
| 148 |
PARAMS="${PARAMS} -DSHOW_SECRETS=ON" |
| 149 |
SECRETS_WARN=1 |
| 150 |
;; |
| 151 |
--gcov) |
| 152 |
CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage" |
| 153 |
;; |
| 154 |
-p|--plug-in) |
| 155 |
PARAMS="${PARAMS} -DPLUGIN=ON" |
| 156 |
PLUGIN="eurephia-auth" |
| 157 |
;; |
| 158 |
-P|--plug-in-dir) |
| 159 |
PLUGINDIR="$2" |
| 160 |
PLUGINDIR_SET=1 |
| 161 |
shift |
| 162 |
;; |
| 163 |
-s|--openvpn-src) |
| 164 |
# Needs to point at at directory with the openvpn source code |
| 165 |
OPENVPN_SRC_DIR="$2" |
| 166 |
PARAMS="${PARAMS} -DOPENVPN_SRC:STRING=$2" |
| 167 |
shift |
| 168 |
;; |
| 169 |
--fw-iptables) |
| 170 |
# Enable iptables support |
| 171 |
PARAMS="${PARAMS} -DFW_IPTABLES=ON" |
| 172 |
FW="iptables " |
| 173 |
;; |
| 174 |
--db-sqlite3) |
| 175 |
# Enable the SQLite3 database driver |
| 176 |
PARAMS="${PARAMS} -DSQLITE3=ON" |
| 177 |
DB="SQLite3 " |
| 178 |
;; |
| 179 |
--sp|--sqlite3-path) |
| 180 |
# Sets the install directory of the SQLite3 eurephia database file |
| 181 |
SQLITE3PREFIX="$2" |
| 182 |
shift |
| 183 |
;; |
| 184 |
--eurephiadm|-A) |
| 185 |
# Enable the eurephiadm console admin utility |
| 186 |
PARAMS="${PARAMS} -DEUREPHIADM=ON" |
| 187 |
ADMIN="${ADMIN}eurephiadm " |
| 188 |
;; |
| 189 |
--eurephiadm-fw) |
| 190 |
# Enable firewall features of the eurephiadm console utility |
| 191 |
PARAMS="${PARAMS} -DFIREWALL=ON" |
| 192 |
;; |
| 193 |
--eurephiadm-xslt) |
| 194 |
# Set the path where XSLT files used by eurephiadm will be installed |
| 195 |
EUREPHIADM_XSLT="$2" |
| 196 |
EUREPHIADM_XSLT_SET=1 |
| 197 |
shift |
| 198 |
;; |
| 199 |
--doxygen) |
| 200 |
PARAMS="${PARAMS} -DDOXYGEN=ON" |
| 201 |
DOXY_DISTCLEAN="rm -r doxygen/eurephia-devel" |
| 202 |
;; |
| 203 |
--man-dir) |
| 204 |
MANDIR="$2" |
| 205 |
shift |
| 206 |
;; |
| 207 |
--cmake-bin) |
| 208 |
CMAKE_BIN="$2" |
| 209 |
shift |
| 210 |
;; |
| 211 |
*) |
| •212 |
echo "Unknown option: $1" |
| 213 |
exit 2 |
| 214 |
;; |
| 215 |
esac |
| 216 |
shift |
| 217 |
done |
| 218 |
|
| 219 |
# Make sure we have cmake available |
| 220 |
if [ -z "$(which ${CMAKE_BIN})" ]; then |
| 221 |
echo "To build eurephia, you need to install ${CMAKE_BIN} (at least version 3.x)" |
| 222 |
exit 1; |
| 223 |
fi |
| 224 |
|
| 225 |
# If we're building the openvpn plug-in, we need the openvpn source code too. |
| 226 |
if [ ! -z "${PLUGIN}" -a -z "${OPENVPN_SRC_DIR}" ]; then |
| 227 |
echo "You need to give the --openvpn-src <path> option when building the eurephia plug-in" |
| 228 |
exit 1; |
| 229 |
fi |
| 230 |
|
| 231 |
# Make sure at least one database driver is enabled. |
| 232 |
if [ -z "${DB}" ]; then |
| 233 |
if [ -n "${PLUGIN}" -o -n "${ADMIN}" ]; then |
| 234 |
echo "You need to activate at least one database driver when OpenVPN plug-in or eurephiadm is enabled" |
| 235 |
exit 1; |
| 236 |
fi |
| 237 |
fi |
| 238 |
|
| 239 |
# Set default parameters for the SQLite3 database |
| 240 |
if [[ ${DB} == *SQLite3* ]]; then |
| 241 |
PARAMS="${PARAMS} -DSQLITE3PREFIX:STIRNG=${SQLITE3PREFIX}" |
| 242 |
fi |
| 243 |
|
| 244 |
# Run cmake with our parameters, and create a configure.log file at the same time |
| 245 |
rm -f CMakeCache.txt |
| 246 |
{ |
| 247 |
cat <<EOF |
| 248 |
# |
| 249 |
# Configure run at `date` |
| 250 |
# `uname -a` |
| 251 |
# |
| 252 |
# ./configure ${CONFIGUREPARAMS} |
| 253 |
|
| 254 |
EOF |
| 255 |
echo -n "Using " |
| 256 |
${CMAKE_BIN} --version |
| 257 |
${CMAKE_BIN} . -Wno-dev ${PARAMS} -DPREFIX:STRING=${PREFIX} -DCMAKE_INSTALL_PREFIX:STRING=${PREFIX} \ |
| 258 |
-DPLUGINDIR:STRING=${PLUGINDIR} -DBINDIR:STRING=${BINDIR} \ |
| 259 |
-DEUREPHIADM_XSLT_PATH:STRING=${EUREPHIADM_XSLT} -DXSLTROOT:STRING=${XSLTPATH} \ |
| 260 |
-DMANDIR:STRING=${MANDIR} -DCFLAGS:STRING="${CFLAGS}" |
| 261 |
export ec=$? |
| 262 |
|
| 263 |
# If cmake exited without failure, provide some info about the configuration |
| 264 |
if [ "$ec" = "0" ]; then |
| 265 |
echo |
| 266 |
echo "Building options:" |
| 267 |
echo " CFLAGS: $CFLAGS" |
| 268 |
echo |
| 269 |
echo "eurephia will be built with support for: " |
| 270 |
echo |
| 271 |
if [ -n "${DB}" ]; then |
| 272 |
echo " Database: ${DB}" |
| 273 |
fi |
| 274 |
echo " Firewall: ${FW:-"None"}" |
| 275 |
echo " OpenVPN plug-in: ${PLUGIN:-"No plug-ins requested"}" |
| 276 |
echo " Admin tools: ${ADMIN:-"None"}" |
| 277 |
echo |
| 278 |
echo " Install prefix: ${PREFIX}" |
| 279 |
echo " Binaries dir: ${BINDIR}" |
| 280 |
echo " Man pages dir: ${MANDIR}" |
| 281 |
echo " Plug-in path: ${PLUGINDIR}" |
| 282 |
if [ ! -z "${ADMIN}" ]; then |
| 283 |
echo " XSLT base path: ${XSLTPATH}" |
| 284 |
echo " eurephiadm XSLT path: ${EUREPHIADM_XSLT}" |
| 285 |
fi |
| 286 |
if [[ ${DB} == *SQLite3* ]]; then |
| 287 |
echo " SQLite3 database path: ${SQLITE3PREFIX}" |
| 288 |
fi |
| 289 |
|
| 290 |
if [ "$GCOV" = "1" ]; then |
| 291 |
echo |
| 292 |
echo " eurephia will be built with gcov. This may have a performance impact" |
| 293 |
fi |
| 294 |
if [ -n "${DOXY_DISTCLEAN}" ]; then |
| 295 |
echo |
| 296 |
echo " eurephia developers documentation will be compiled under ./doxygen/eurephia-devel/" |
| 297 |
fi |
| 298 |
echo |
| 299 |
echo |
| 300 |
# Make sure user is aware of enabled debug features. |
| 301 |
if [ "$DEBUG_WARN" = 1 ]; then |
| 302 |
echo |
| 303 |
echo " ******* DEBUG is enabled. This might be a security issue *******" |
| 304 |
echo |
| 305 |
if [ "$SECRETS_WARN" = 1 ]; then |
| 306 |
echo |
| 307 |
echo " ******* SHOW_SECRETS is enabled. THIS WILL LOG PASSWORDS IN CLEAR TEXT IN LOG FILES *******" |
| 308 |
echo |
| 309 |
fi |
| 310 |
fi |
| 311 |
|
| 312 |
# Update Makefile with distclean and uninstall rules |
| 313 |
cat >> Makefile <<EOF |
| 314 |
distclean : clean |
| 315 |
find . -type d -name "CMakeFiles" | xargs rm -rf |
| 316 |
find . -type f -name "cmake_install.cmake" | xargs rm -rf |
| 317 |
find . -type f -name CMakeCache.txt | xargs rm -rf |
| 318 |
find . -type f -name install_manifest.txt | xargs rm -rf |
| 319 |
find . -type f -name Makefile | xargs rm -rf |
| 320 |
find . -type f -name "*~" | xargs rm -f |
| 321 |
rm -f CMakeCache.txt |
| 322 |
${DOXY_DISTCLEAN} |
| 323 |
|
| 324 |
uninstall : |
| 325 |
@echo "Uninstalling eurephia: " |
| 326 |
cat install_manifest.txt | xargs rm -vf |
| 327 |
EOF |
| 328 |
# If SQLite3 driver is enabled, add some extra clean up rules for the uninstall rules |
| 329 |
if [ ! -z ${DB} ]; then |
| 330 |
if [ ${SQLITE3PREFIX} != ${PREFIX} ]; then |
| 331 |
cat >> Makefile <<EOF |
| 332 |
rmdir -v ${SQLITE3PREFIX} |
| 333 |
EOF |
| 334 |
fi |
| 335 |
fi |
| 336 |
cat >> Makefile <<EOF |
| 337 |
rmdir -v ${PREFIX} |
| 338 |
EOF |
| 339 |
|
| 340 |
fi |
| 341 |
exit $ec |
| 342 |
} 2>&1 | tee ./configure.log |