File: configure

package info (click to toggle)
gophernicus 3.1.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 492 kB
  • sloc: ansic: 2,326; sh: 718; makefile: 173
file content (354 lines) | stat: -rwxr-xr-x 12,351 bytes parent folder | download | duplicates (2)
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/bin/sh

# Is similar to an autoconf configure script, but is written by hand

usage() {
    printf "Usage: %s [options]\\n\\n" "$0"
    printf "  --prefix=/usr/local         Prefix for all files\\n"
    printf "  --bindir=PREFIX/bin         Prefix for binaries\\n"
    printf "  --sbindir=PREFIX/sbin       Prefix for system binaries\\n"
    printf "  --mandir=PREFIX/share/man   Prefix for manpages\\n"
    printf "  --man8dir=MANDIR/man8       Prefix for section 8 manpages\\n"
    printf "  --gopherroot=/var/gopher    Path to gopher root\\n"
    printf "  --sysconfig=/etc/sysconfig  Path to sysconfig directory\\n"
    printf "  --default=/etc/default      Path to 'default' configuration directory\\n"
    printf "  --launchd=/Library/LaunchDaemons                  Path to launchd for MacOS\\n"
    printf "  --haikusrv=/boot/common/settings/network/services Path to services directory in Haiku\\n"
    printf "  --systemd=/lib/systemd/system			Path to systemd directory when using systemd listener\\n"
    printf "  --os=autodetected        Your target OS, one of linux, mac, haiku, netbsd, openbsd or freebsd\\n"
    printf "  --listener=somelistener   Program to recieve and pass network requests; one or more of systemd, inetd, xinetd, comma-seperated, or autodetect, mac or haiku (parameter required, mac/haiku required on respective OSes)\\n"
    printf "  --hostname=autodetected  Desired hostname for gophernicus to identify as\\n"
}

# Set values for each option
while [ "$#" -gt 0 ] ; do
    opt="${1%%=*}"
    opt="${opt##--}"
    value="${1##*=}"
    case "${opt}" in
        prefix) PREFIX="${value}"; shift ;;
        bindir) BINDIR="${value}"; shift ;;
        sbindir) SBINDIR="${value}"; shift ;;
        docdir) DOCDIR="${value}"; shift ;;
        mandir) MANDIR="${value}"; shift ;;
        man8dir) MAN8DIR="${value}"; shift ;;
        gopherroot) GOPHERROOT="${value}"; shift ;;
        sysconfig) SYSCONFIG="${value}"; shift ;;
        default) DEFAULTCONF="${value}"; shift ;;
        os) OS="${value}"; shift ;;
        launchd) LAUNCHD="${value}"; shift ;;
        haikusrv) HAIKUSRV="${value}"; shift ;;
        systemd) SYSTEMD="${value}"; shift ;;
        listener) LISTENERS="${value}"; shift ;;
        hostname) HOSTNAME="${value}"; shift ;;
        help) usage; exit 0 ;;
        *) usage; exit 2 ;;
    esac
done

# Set default values
: ${PREFIX:=/usr/local}
: ${BINDIR:=${PREFIX}/bin}
: ${SBINDIR:=${PREFIX}/sbin}
: ${DOCDIR:=${PREFIX}/share/doc}
: ${MANDIR:=${PREFIX}/share/man}
: ${MAN8DIR:=${MANDIR}/man8}
: ${GOPHERROOT:=/var/gopher}
: ${SYSCONFIG:=/etc/sysconfig}
: ${DEFAULTCONF:=/etc/default}
: ${LAUNCHD:=/Library/LaunchDaemons}
: ${HAIKUSRV:=/boot/common/settings/network/services}
: ${SYSTEMD:=/lib/systemd/system}
: ${CC:=cc}
: ${HOSTCC:=${CC}}
: ${CFLAGS:=-O2}
: ${HOSTNAME:=autodetect}

# Check for a compiler that actually works
printf "checking for working compiler... "
cat > conftest.c <<EOF
#include <stdlib.h>
int main() { return 0; }
EOF
if ! ${CC} -o conftest conftest.c; then
    printf "no\\n"
    exit 1
else
    printf "${CC}\\n"
fi

# Autodetect the OS
if [ -z "${OS}" ]; then
    # If it can't find uname, it needs to be manually specified
    printf "checking for uname... "
    if ! UNAME="$(command -v uname)"; then
        printf "please provide OS in options\\n"
        exit 1
    else
        printf "%s\\n" "${UNAME}"
    fi

    # If it can, it presses on
    printf "checking for OS... "
    case "$(${UNAME})" in
        Linux) OS=linux ;;
        Haiku) OS=haiku
            INSTALL_HAIKU="install-haiku" ;;
        Darwin) OS=mac
            INSTALL_OSX="install-osx" ;;
        NetBSD) OS=netbsd ;;
        OpenBSD) OS=openbsd ;;
        FreeBSD) OS=freebsd ;;
        *) printf "unknown, pressing on anyway\\n" ;;
    esac
    printf "%s\\n" "${OS}"
fi

# Checks for an install command and falls back to install-sh
printf "checking for install... "
if ! INSTALL="$(command -v install)"; then
    printf "install-sh"
    INSTALL=build-aux/install-sh
else
    # Check it has required features (*cough* macos)
    mkdir testconf
    touch testfile
    ${INSTALL} -t testconf testfile 2>&1 >/dev/null || INSTALL=build-aux/install-sh
    rm testconf/testfile
    ${INSTALL} -T testfile testconf/testfile 2>&1 >/dev/null || INSTALL=build-aux/install-sh
    rm -r testconf testfile
    printf "%s" "${INSTALL}"
fi
printf "\\n"

listeners="$(echo ${LISTENERS} | tr ',' ' ')"
for listener in ${listeners}; do
    # Check for listener validity and autodetect if required
    # Checks that take place:
    # mac OS = mac listener (both ways)
    # haiku OS = haiku listener (both ways)
    # systemd listener = linux OS
    printf "checking for listener... "
    if [ -z "${listener}" ]; then
        printf "not given\\n"
        exit 1
    elif [ "${listener}" = "mac" ] && [ "${OS}" != "mac" ]; then
        printf "mac listener only valid with macos\\n"
        exit 1
    elif [ "${listener}" = "haiku" ] && [ "${OS}" != "haiku" ]; then
        printf "haiku listener only valid with haiku\\n"
        exit 1
    elif [ "${listener}" = "systemd" ] && [ "${OS}" != "linux" ]; then
        printf "systemd listener only valid with linux\\n"
        exit 1
    elif [ "${listener}" = "autodetect" ]; then
        # OS-specific listeners
        case "${OS}" in
            mac)
                listener=mac
                printf "mac\\n"
                break ;;
            haiku)
                listener=haiku
                printf "haiku\\n"
                break ;;
        esac

        if [ -d "/lib/systemd/system" ] ; then
            listener=systemd
            printf "systemd\\n"
        fi

        printf "checking for inetd... "
        if command -v update-inetd && [ "${listener}" = "autodetect" ]; then
            listener=inetd
            printf "inetd\\n"
        fi

        printf "checking for xinetd... "
        if XINETD="$(command -v xinetd)" && [ "${listener}" = "autodetect" ]; then
            listener=xinetd
            printf "xinetd\\n"
        fi

        # Ensure we detected something
        if [ "${listener}" = "autodetect" ]; then
            printf "unable to autodetect, please manually specify\\n"
            exit 1
        fi
    elif [ "${OS}" = "haiku" ] && [ "${listener}" != "haiku" ]; then
        printf "only haiku listener supported on haiku\\n"
        exit 1
    elif [ "${OS}" = "mac" ] && [ "${listener}" != "mac" ]; then
        printf "only mac listener supported on mac\\n"
        exit 1
    else
        printf "%s\\n" "${listener}"
    fi

    # Act accordingly based on whichever listener we are given
    case "${listener}" in
        systemd)
            INSTALL_SYSTEMD="install-systemd"
            UNINSTALL_SYSTEMD="uninstall-systemd"
            INSTALL_MSG_SYSTEMD='$(MAKE) install-msg-systemd' ;;
        xinetd)
            INSTALL_XINETD="install-xinetd"
            UNINSTALL_XINETD="uninstall-xinetd"
            XINETD_CONF="/etc/xinetd.d/gophernicus"
            INSTALL_MSG_XINETD='$(MAKE) install-msg-xinetd' ;;
        inetd)
            INSTALL_INETD="install-inetd"
            INETD_CONF="/etc/inetd.conf"
            printf "checking for update-inetd... "
            if ! UPDATE_INETD="$(command -v update-inetd)"; then
                printf "not found\\n"
                INSTALL_INETD_MANUAL="install-inetd-manual"
                UNINSTALL_INETD_UPDATE="uninstall-inetd-manual"
            else
                printf "%s\\n" "${UPDATE_INETD}"
                INSTALL_INETD_UPDATE="install-inetd-update"
                UNINSTALL_INETD_UPDATE="uninstall-inetd-update"
            fi
            INSTALL_MSG_INETD='$(MAKE) install-msg-inetd'
            ;;
        mac)
            INSTALL_OSX="install-osx"
            UNINSTALL_OSX="uninstall-osx"
            INSTALL_MSG_OSX='$(MAKE) install-msg-osx' ;;
        haiku)
            INSTALL_HAIKU="install-haiku"
            UNINSTALL_HAIKU="uninstall-haiku"
            INSTALL_MSG_HAIKU='$(MAKE) install-msg-haiku' ;;
        *) printf "The listener %s is not offically supported; continuing anyway.\\n" "${listener}" ;;
    esac
done

# Try to detect hostname
printf "checking current hostname... "
if [ "${HOSTNAME}" = "autodetect" ]; then
    HOSTNAME="$(hostname)"
    # If no hostname then we couldn't autodetect
    if [ $? != 0 ] || [ -z "${HOSTNAME}" ]; then
        printf "unable to detect hostname\\n"
        exit 1
    fi
fi
printf "%s\\n" "${HOSTNAME}"

# Use libwrap when it is avaliable
printf "checking for libwrap... "
cat > conftest.c <<EOF
#include <tcpd.h>
int main() {}
EOF
if ${CC} -o conftest -lwrap conftest.c 2>/dev/null; then
    LIBWRAP="-DHAVE_LIBWRAP -lwrap"
    printf "yes"
else
    LIBWRAP=
    printf "no, but program will still work"
fi
printf "\\n"

# Check and use SHM if avaliable
printf "checking for ipcrm (SHM management)... "
if ! IPCRM="$(command -v ipcrm)"; then
    printf "not found"
else
    printf "%s" "${IPCRM}"
    CLEAN_SHM="clean-shm"
fi
printf "\\n"

# Trying to autodetect make
printf "checking for make... "
if ! MAKE="$(command -v make)"; then
    printf "not found, please pass MAKE=/path/to/make to make invocation"
    MAKE="make"
else
    printf "%s" "${MAKE}"
fi
printf "\\n"

# Don't replace an existing root
printf "checking for existing gopher root... "
if [ -d "${GOPHERROOT}" ] || [ -f "${GOPHERROOT}/gophermap" ]; then
    INSTALL_ROOT="install-root"
    printf "yes"
else
    printf "no"
fi
printf "\\n"

# Sub in values
cp Makefile.in Makefile

printf "creating Makefile... "
sed -i -e "s:@CC@:${CC}:" Makefile
sed -i -e "s:@HOSTCC@:${HOSTCC}:" Makefile
sed -i -e "s:@LIBWRAP@:${LIBWRAP}:" Makefile
sed -i -e "s:@INSTALL@:${INSTALL}:" Makefile
sed -i -e "s:@MAKE@:${MAKE}:" Makefile

sed -i -e "s:@PREFIX@:${PREFIX}:" Makefile
sed -i -e "s:@BINDIR@:${BINDIR}:" Makefile
sed -i -e "s:@SBINDIR@:${SBINDIR}:" Makefile
sed -i -e "s:@DOCDIR@:${DOCDIR}:" Makefile
sed -i -e "s:@MANDIR@:${MANDIR}:" Makefile
sed -i -e "s:@MAN8DIR@:${MAN8DIR}:" Makefile

sed -i -e "s:@IPCRM@:${IPCRM}:" Makefile
sed -i -e "s:@CLEAN_SHM@:${CLEAN_SHM}:" Makefile

sed -i -e "s:@SYSCONF@:${SYSCONFIG}:" Makefile
sed -i -e "s:@DEFAULT@:${DEFAULTCONF}:" Makefile
sed -i -e "s:@HOSTNAME@:${HOSTNAME}:" Makefile
sed -i -e "s:@ROOT@:${GOPHERROOT}:" Makefile

sed -i -e "s:@HAIKUSRV@:${HAIKUSRV}:" Makefile
sed -i -e "s:@LAUNCHD@:${LAUNCHD}:" Makefile
sed -i -e "s:@SYSTEMD@:${SYSTEMD}:" Makefile
sed -i -e "s:@INSTALL_ROOT@:${INSTALL_ROOT}:" Makefile

sed -i -e "s:@INSTALL_OSX@:${INSTALL_OSX}:" Makefile
sed -i -e "s:@INSTALL_INETD_MANUAL@:${INSTALL_INETD_MANUAL}:" Makefile
sed -i -e "s:@INSTALL_INETD_UPDATE@:${INSTALL_INETD_UPDATE}:" Makefile
sed -i -e "s:@INSTALL_XINETD@:${INSTALL_XINETD}:" Makefile
sed -i -e "s:@INSTALL_SYSTEMD@:${INSTALL_SYSTEMD}:" Makefile
sed -i -e "s:@INSTALL_HAIKU@:${INSTALL_HAIKU}:" Makefile
sed -i -e "s:@INSTALL_MSG_INETD@:${INSTALL_MSG_INETD}:" Makefile
sed -i -e "s:@INSTALL_MSG_XINETD@:${INSTALL_MSG_XINETD}:" Makefile
sed -i -e "s:@INSTALL_MSG_SYSTEMD@:${INSTALL_MSG_SYSTEMD}:" Makefile
sed -i -e "s:@INSTALL_MSG_OSX@:${INSTALL_MSG_OSX}:" Makefile
sed -i -e "s:@INSTALL_MSG_HAIKU@:${INSTALL_MSG_HAIKU}:" Makefile
sed -i -e "s:@UNINSTALL_OSX@:${UNINSTALL_OSX}:" Makefile
sed -i -e "s:@UNINSTALL_INETD_MANUAL@:${UNINSTALL_INETD_MANUAL}:" Makefile
sed -i -e "s:@UNINSTALL_INETD_UPDATE@:${UNINSTALL_INETD_UPDATE}:" Makefile
sed -i -e "s:@UNINSTALL_XINETD@:${UNINSTALL_XINETD}:" Makefile
sed -i -e "s:@UNINSTALL_SYSTEMD@:${UNINSTALL_SYSTEMD}:" Makefile
sed -i -e "s:@UNINSTALL_HAIKU@:${UNINSTALL_HAIKU}:" Makefile

sed -i -e "s:@INETD_CONF@:${INETD_CONF}:" Makefile
sed -i -e "s:@XINETD_CONF@:${XINETD_CONF}:" Makefile

printf "done\\n"

# Also sub in $HOSTNAME to the various init systems (whether or not we really
# use them, its just easier)
for f in gophernicus.env haiku_snippet org.gophernicus.server.plist \
    gophernicus.xinetd; do
    printf "creating init/${f}... "
    sed -e "s:@HOSTNAME@:${HOSTNAME}:" "init/${f}.in" > "init/${f}"
    printf "done\\n"
done

# And generate gophernicus@.service
printf "creating init/gophernicus@.service... "
sed -e "s:@DEFAULT@:${DEFAULTCONF}:" \
    -e "s:@SYSCONFIG@:${SYSCONFIG}:" \
    'init/gophernicus@.service.in' > 'init/gophernicus@.service'
printf "done\\n"

# Cleanup
rm -f conftest conftest.c