summaryrefslogtreecommitdiffstats
path: root/configure
blob: a4403d38d44854f2fc63d7dda4d54743b0692e3d (plain)
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
#!/bin/sh

PREFIX="/usr/local"
BINDIR="${PREFIX}/bin"
BINDIR_SET=0
PLUGINDIR="${PREFIX}/lib/eurephia"
PLUGINDIR_SET=0
XSLTPATH="${PREFIX}/share/eurephia/xslt"
XSLTPATH_SET=0
EUREPHIADM_XSLT="${XSLTPATH}/eurephiadm"
EUREPHIADM_XSLT_SET=0
SQLITE3PREFIX="/etc/openvpn"

usage() {
    cat <<EOF
configure help for eurephia

          --help               | -h        -- This help screen

   ** Main paths
          --prefix <path>                  -- Root directory of installation
                                              (default: ${PREFIX})
          --bin-dir                        -- Directory where to place binaries
                                              (default: ${BINDIR})
          --xslt-path          | -X        -- Default XSLT path
                                              (default: ${XSLTPATH})

   ** Debug options
          --debug              | -D        -- Enable verbose debug logging
          --show-secrets       | -S        -- Log passwords as clear text in log files
                               |              (only available when debug is enabled)

   ** Plug-in options
          --plug-in            | -p        -- Build the eurephia plug-in for OpenVPN
          --plug-in-dir        | -P        -- Destination path for the plug-ins and other modules
                                              (default: ${PLUGINDIR})
          --openvpn-src <path> | -s <path> -- OpenVPN source directory (needed when building plug-in)
          --fw-iptables        |           -- Build iptables firewall module

   ** Database options
          --db-sqlite3         |           -- Build SQLite3 database module
          --sqlite3-path       | -sp       -- Root directory of SQLite3 eurephia database file
                                              (default: ${SQLITE3PREFIX})
   ** Administration utility options
          --eurephiadm         | -A        -- Build command line admin utility
          --eurephiadm-fw                  -- Include the firewall info even without any
                                              firewall interface being built
          --eurephiadm-xslt                -- eurephiadm XSLT root path
                                              (default: ${EUREPHIADM_XSLT})
EOF
}

PARAMS=""
DB=""
FW=""
ADMIN="";
OPENVPN_SRC_DIR=""
PLUGIN=""
CONFIGUREPARAMS="$*"

while [ ! -z "$1" ]; do
      case $1 in 
          -h|--help)
              usage
              exit 0
              ;;
          --prefix)
              PREFIX="$2";
              shift
              if [ "${BINDIR_SET}" = "0" ]; then
                  BINDIR="${PREFIX}/bin";
              fi
              if [ "${PLUGINDIR_SET}" = "0" ]; then
                  PLUGINDIR="${PREFIX}/lib/eurephia"
              fi
              if [ "${XSLTPATH_SET}" = "0" ]; then
                  XSLTPATH="${PREFIX}/share/eurephia/xslt"
                  if [ "${EUREPHIADM_XSLT_SET}" = "0" ]; then
                      EUREPHIADM_XSLT="${XSLTPATH}/eurephiadm"
                  fi
              fi
              ;;
          --bin-dir)
              BINDIR="$2"
              BINDIR_SET=1
              shift
              ;;
          -X|--xslt-path)
              XSLTPATH="$2"
              if [ "${EUREPHIADM_XSLT_SET}" = "0" ]; then
                  EUREPHIADM_XSLT="${XSLTPATH}/eurephiadm"
              fi
              shift
              ;;
          -D|--debug)
              PARAMS="${PARAMS} -DDEBUG=ON"
              DEBUG_WARN=1
              ;;
          -S|--show-secrets)
              PARAMS="${PARAMS} -DSHOW_SECRETS=ON"
              SECRETS_WARN=1
              ;;
          -p|--plug-in)
              PARAMS="${PARAMS} -DPLUGIN=ON"
              PLUGIN="eurephia-auth"
              ;;
          -P|--plug-in-dir)
              PLUGINDIR="$2"
              PLUGINDIR_SET=1
              shift
              ;;
          -s|--openvpn-src)
              OPENVPN_SRC_DIR="$2"
              PARAMS="${PARAMS} -DOPENVPN_SRC:STRING=$2"
              shift
              ;;
          --fw-iptables)
              PARAMS="${PARAMS} -DFW_IPTABLES=ON"
              FW="iptables "
              ;;
          --db-sqlite3)
              PARAMS="${PARAMS} -DSQLITE3=ON"
              DB="SQLite3 "
              ;;
          --sp|--sqlite3-path)
              SQLITE3PREFIX="$2"
              shift
              ;;
          --eurephiadm|-A)
              PARAMS="${PARAMS} -DEUREPHIADM=ON"
              ADMIN="${ADMIN}eurephiadm "
              ;;
          --eurephiadm-fw)
              PARAMS="${PARAMS} -DFIREWALL=ON"
              ;;
          --eurephiadm-xslt)
                      EUREPHIADM_XSLT="$2"
              EUREPHIADM_XSLT_SET=1
              shift
              ;;
          *)
              echo "Unkown option: $1"
              exit 2
              ;;
      esac
      shift
done

if [ -z "$(which cmake)" ]; then
    echo "To build eurephia, you need to install cmake (at least version 2.6)"
    exit 1;
fi

if [ ! -z "${PLUGIN}" -a -z "${OPENVPN_SRC_DIR}" ]; then
    echo "You need to give the --openvpn-src <path> option when building the eurephia plug-in"
    exit 1;
fi

if [ -z "${DB}" ]; then
    echo "You need to activate at least one database driver"
    exit 1;
fi

if [ ${DB} = "SQLite3" ]; then
    PARAMS="${PARAMS} -DSQLITE3PREFIX:STIRNG=${SQLITE3PREFIX}"
fi

rm -f CMakeCache.txt
{
    cat <<EOF
#
# Configure run at `date`
# `uname -a`
#
# ./configure ${CONFIGUREPARAMS}

EOF
    cmake . ${PARAMS} -DPREFIX:STRING=${PREFIX} -DCMAKE_INSTALL_PREFIX:STRING=${PREFIX} \
        -DPLUGINDIR:STRING=${PLUGINDIR} -DBINDIR:STRING=${BINDIR} \
        -DEUREPHIADM_XSLT_PATH:STRING=${EUREPHIADM_XSLT} -DXSLTROOT:STRING=${XSLTPATH}
    export ec=$?

    if [ "$ec" = "0" ]; then
        echo
        echo
        echo "eurephia will be built with support for: "
        echo
        echo "               Database: ${DB}"
        echo "               Firewall: ${FW:-"None"}"
        echo "        OpenVPN plug-in: ${PLUGIN:-"No plug-ins requested"}"
        echo "            Admin tools: ${ADMIN:-"None"}"
        echo
        echo "         Install prefix: ${PREFIX}"
        echo "           Binaries dir: ${BINDIR}"
        echo "           Plug-in path: ${PLUGINDIR}"
        if [ ! -z "${ADMIN}" ]; then
            echo "         XSLT base path: ${XSLTPATH}"
            echo "   eurephiadm XSLT path: ${EUREPHIADM_XSLT}"
        fi
        if [ ${DB} = "SQLite3" ]; then
            echo "  SQLite3 database path: ${SQLITE3PREFIX}"
        fi

        echo
        echo
        if [ "$DEBUG_WARN" = 1 ]; then
            echo
            echo "     *******   DEBUG is enabled.  This might be a security issue   *******"
            echo
            if [ "$SECRETS_WARN" = 1 ]; then
                echo
                echo "     *******   SHOW_SECRETS is enabled.  THIS WILL LOG PASSWORDS IN CLEAR TEXT IN LOG FILES   *******"
                echo
            fi
        fi

        # Update Makefile with distclean and uninstall rules
        cat >> Makefile <<EOF
distclean : clean
	find -type d -name "CMakeFiles" | xargs rm -rf
	find -type f -name "cmake_install.cmake" | xargs rm -rf
	find -type f -name CMakeCache.txt | xargs rm -rf
	find -type f -name install_manifest.txt | xargs rm -rf
	find -type f -name Makefile | xargs rm -rf
	find -type f -name "*~" | xargs rm -f
	rm -f CMakeCache.txt

uninstall :
	@echo "Uninstalling eurephia: "
	cat install_manifest.txt | xargs rm -vf
EOF
        if [ ! -z ${DB} ]; then
            if [ ${SQLITE3PREFIX} != ${PREFIX} ]; then
                cat >> Makefile <<EOF
	rmdir -v ${SQLITE3PREFIX}
EOF
            fi
        fi
        cat >> Makefile <<EOF
	rmdir -v ${PREFIX}
EOF

    fi
    exit $ec
} 2>&1 | tee ./configure.log