-
Notifications
You must be signed in to change notification settings - Fork 4
/
configure
executable file
·440 lines (401 loc) · 14.6 KB
/
configure
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/bin/sh
#
# sshdo - controls which commands may be executed via incoming ssh
# https://raf.org/sshdo
# https://github.com/raforg/sshdo
# https://codeberg.org/raforg/sshdo
#
# Copyright (C) 2018-2023 raf <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://www.gnu.org/licenses/>.
#
# 20230619 raf <[email protected]>
# Show the usage messge for --help
for opt in "$@"
do
case "$opt" in
--help|-h)
echo "$0 [options]"
echo "options:"
echo " --help, -h - Output this help message, then exit"
echo " --verbose, -v - Show resulting config diffs (Note: no option bundling)"
echo " --test, -n - Don't modify anything (Note: no option bundling)"
echo " --destdir=/path - Override DESTDIR in Makefile for building packages"
echo " --prefix=/path - Override platform-specific installation prefix"
echo " --etcdir=/path - Override platform-specific config directory"
echo " --mandir=/path - Override platform-specific manpage directory"
echo " --macports - Override default macOS config for macports"
echo " --macports-prefix=/path - Same as --macports with a non-default prefix"
echo " --enable-mangz - Enable gzipped manpages (default on some systems)"
echo " --disable-mangz - Disable gzipped manpages (default)"
echo " --with-python=name - Override default python interpreter (name or /path)"
echo " --default - Restore Makefile to its defaults (for distribution)"
echo ""
eco "The --with-python= argument can be the name of a Python2 or Python3 interpreter"
echo "to be found in the PATH (e.g., --with-python=python3.11), or it can be an"
echo "absolute path to a specific interpreter (e.g., --with-python=/bin/python3)."
echo "By default, \"python3\" or \"python\" in the PATH is used."
echo ""
exit 0
;;
esac
done
# Record --verbose and --test early (for editconf)
test=0
verbose=0
for opt in "$@"
do
case "$opt" in
--verbose|-v)
verbose=1;
;;
--test|-n)
test=1;
;;
esac
done
# Handle --default (for distribution)
default=0
for opt in "$@"
do
case "$opt" in
--default|default)
default=1
break
;;
esac
done
# Fatal error message (for editconf)
die() { echo "$0: $@" >&2; exit 1; }
# Modify a file (Makefile) with sed (honours --verbose and --test)
editconf()
{
fname="$1"; shift
if [ $verbose = 1 ]
then
sed "$@" < "$fname" > "$fname.tmp"; diff -u "$fname" "$fname.tmp"; rm "$fname.tmp"
fi
if [ $test = 0 ]
then
cp -p "$fname" "$fname.tmp" # Preserve file permissions
sed "$@" < "$fname" > "$fname.tmp" && mv "$fname.tmp" "$fname" || die "failed to edit $fname"
fi
}
# Operating system preferences (installation locations and manual compression)
case "`uname`" in
Linux*) # prefix=/usr/local etcdir=/etc mandir=$prefix/share/man manzip=1
echo "Configuring for linux"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^\(BINDIR = \).*$,\1$(PREFIX)/bin,' \
-e 's,^\(MANDIR = \).*$,\1$(PREFIX)/share/man,' \
-e 's,^\(ETCDIR = \).*$,\1/etc,' \
-e 's,^\(MAN_GZIP =\) 0,\1 1,'
editconf sshdo \
-e "s,default_config_fname = '.*',default_config_fname = '/etc/sshdoers'," \
-e "s,default_logfiles = '.*',default_logfiles = '/var/log/auth.log*'," \
-e "s,/[a-z/][a-z/]*/sshdo ,/usr/local/bin/sshdo ,"
editconf sshdoers \
-e 's,/[a-z/][a-z/]*/sshdoers,/etc/sshdoers,' \
-e 's,"/[a-z/][a-z/]*/sshdo","/usr/local/bin/sshdo",' \
-e 's, /[a-z/][a-z/]*/sshdo\.$, /usr/local/bin/sshdo.,' \
-e 's,^# logfiles .*$,# logfiles /var/log/auth.log*,' \
-e 's,^# banner .*$,# banner /etc/sshdo.banner,'
editconf test_sshdo \
-e "s,'/var/log/..*','/var/log/auth.log',"
;;
FreeBSD*) # prefix=/usr/local etcdir=$prefix/etc mandir=$prefix/man manzip=1
echo "Configuring for freebsd"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^\(BINDIR = \).*$,\1$(PREFIX)/bin,' \
-e 's,^\(MANDIR = \).*$,\1$(PREFIX)/man,' \
-e 's,^\(ETCDIR = \).*$,\1$(PREFIX)/etc,' \
-e 's,^\(MAN_GZIP =\) 0,\1 1,'
editconf sshdo \
-e "s,default_config_fname = '.*',default_config_fname = '/usr/local/etc/sshdoers'," \
-e "s,default_logfiles = '.*',default_logfiles = '/var/log/auth.log*'," \
-e "s,/[a-z/][a-z/]*/sshdo ,/usr/local/bin/sshdo ,"
editconf sshdoers \
-e 's,/[a-z/][a-z/]*/sshdoers,/usr/local/etc/sshdoers,' \
-e 's,"/[a-z/][a-z/]*/sshdo","/usr/local/bin/sshdo",' \
-e 's, /[a-z/][a-z/]*/sshdo\.$, /usr/local/bin/sshdo.,' \
-e 's,^# logfiles .*$,# logfiles /var/log/auth.log*,' \
-e 's,^# banner .*$,# banner /usr/local/etc/sshdo.banner,'
editconf test_sshdo \
-e "s,'/var/log/..*','/var/log/auth.log',"
;;
NetBSD*) # prefix=/usr/pkg etcdir=$prefix/etc mandir=$prefix/man manzip=0
echo "Configuring for netbsd"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/pkg,' \
-e 's,^\(BINDIR = \).*$,\1$(PREFIX)/bin,' \
-e 's,^\(MANDIR = \).*$,\1$(PREFIX)/man,' \
-e 's,^\(ETCDIR = \).*$,\1$(PREFIX)/etc,' \
-e 's,^\(MAN_GZIP =\) 0,\1 0,'
editconf sshdo \
-e "s,default_config_fname = '.*',default_config_fname = '/usr/pkg/etc/sshdoers'," \
-e "s,default_logfiles = '.*',default_logfiles = '/var/log/authlog*'," \
-e "s,/[a-z/][a-z/]*/sshdo ,/usr/pkg/bin/sshdo ,"
editconf sshdoers \
-e 's,/[a-z/][a-z/]*/sshdoers,/usr/pkg/etc/sshdoers,' \
-e 's,"/[a-z/][a-z/]*/sshdo","/usr/pkg/bin/sshdo",' \
-e 's, /[a-z/][a-z/]*/sshdo\.$, /usr/pkg/bin/sshdo.,' \
-e 's,^# logfiles .*$,# logfiles /var/log/authlog*,' \
-e 's,^# banner .*$,# banner /usr/pkg/etc/sshdo.banner,'
editconf test_sshdo \
-e "s,'/var/log/..*','/var/log/authlog',"
;;
OpenBSD*) # prefix=/usr/local etcdir=$prefix/etc mandir=$prefix/man manzip=0
echo "Configuring for openbsd"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^\(BINDIR = \).*$,\1$(PREFIX)/bin,' \
-e 's,^\(MANDIR = \).*$,\1$(PREFIX)/man,' \
-e 's,^\(ETCDIR = \).*$,\1$(PREFIX)/etc,' \
-e 's,^\(MAN_GZIP =\) 0,\1 0,'
editconf sshdo \
-e "s,default_config_fname = '.*',default_config_fname = '/usr/local/etc/sshdoers'," \
-e "s,default_logfiles = '.*',default_logfiles = '/var/log/authlog*'," \
-e "s,/[a-z/][a-z/]*/sshdo ,/usr/local/bin/sshdo ,"
editconf sshdoers \
-e 's,/[a-z/][a-z/]*/sshdoers,/usr/local/etc/sshdoers,' \
-e 's,"/[a-z/][a-z/]*/sshdo","/usr/local/bin/sshdo",' \
-e 's, /[a-z/][a-z/]*/sshdo\.$, /usr/local/bin/sshdo.,' \
-e 's,^# logfiles .*$,# logfiles /var/log/authlog*,' \
-e 's,^# banner .*$,# banner /usr/local/etc/sshdo.banner,'
editconf test_sshdo \
-e "s,'/var/log/..*','/var/log/authlog',"
;;
SunOS*) # prefix=/usr/local etcdir=/etc mandir=$prefix/share/man manzip=0
echo "Configuring for solaris"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^\(BINDIR = \).*$,\1$(PREFIX)/bin,' \
-e 's,^\(MANDIR = \).*$,\1$(PREFIX)/share/man,' \
-e 's,^\(ETCDIR = \).*$,\1/etc,' \
-e 's,^\(MAN_GZIP =\) 0,\1 0,'
editconf sshdo \
-e "s,default_config_fname = '.*',default_config_fname = '/etc/sshdoers'," \
-e "s,default_logfiles = '.*',default_logfiles = '/var/log/authlog*'," \
-e "s,/[a-z/][a-z/]*/sshdo ,/usr/local/bin/sshdo ,"
editconf sshdoers \
-e 's,/[a-z/][a-z/]*/sshdoers,/etc/sshdoers,' \
-e 's,"/[a-z/][a-z/]*/sshdo","/usr/local/bin/sshdo",' \
-e 's, /[a-z/][a-z/]*/sshdo\.$, /usr/local/bin/sshdo.,' \
-e 's,^# logfiles .*$,# logfiles /var/log/authlog*,' \
-e 's,^# banner .*$,# banner /etc/sshdo.banner,'
editconf test_sshdo \
-e "s,'/var/log/..*','/var/log/authlog',"
;;
Darwin*) # prefix=/usr/local etcdir=/etc mandir=$prefix/share/man manzip=0
echo "Configuring for macos"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^\(BINDIR = \).*$,\1$(PREFIX)/bin,' \
-e 's,^\(MANDIR = \).*$,\1$(PREFIX)/share/man,' \
-e 's,^\(ETCDIR = \).*$,\1/etc,' \
-e 's,^\(MAN_GZIP =\) 0,\1 0,'
editconf sshdo \
-e "s,default_config_fname = '.*',default_config_fname = '/etc/sshdoers'," \
-e "s,default_logfiles = '.*',default_logfiles = '/var/log/system.log*'," \
-e "s,/[a-z/][a-z/]*/sshdo ,/usr/local/bin/sshdo ,"
editconf sshdoers \
-e 's,/[a-z/][a-z/]*/sshdoers,/etc/sshdoers,' \
-e 's,"/[a-z/][a-z/]*/sshdo","/usr/local/bin/sshdo",' \
-e 's, /[a-z/][a-z/]*/sshdo\.$, /usr/local/bin/sshdo.,' \
-e 's,^# logfiles .*$,# logfiles /var/log/system.log*,' \
-e 's,^# banner .*$,# banner /etc/sshdo.banner,'
editconf test_sshdo \
-e "s,'/var/log/..*','/var/log/system.log',"
;;
CYGWIN_NT*) # prefix=/usr/local etcdir=/etc mandir=$prefix/share/man manzip=1
echo "Configuring for cygwin"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^\(BINDIR = \).*$,\1$(PREFIX)/bin,' \
-e 's,^\(MANDIR = \).*$,\1$(PREFIX)/share/man,' \
-e 's,^\(ETCDIR = \).*$,\1/etc,' \
-e 's,^\(MAN_GZIP =\) 0,\1 1,'
editconf sshdo \
-e "s,default_config_fname = '.*',default_config_fname = '/etc/sshdoers'," \
-e "s,default_logfiles = '.*',default_logfiles = '/var/log/auth.log*'," \
-e "s,/[a-z/][a-z/]*/sshdo ,/usr/local/bin/sshdo ,"
editconf sshdoers \
-e 's,/[a-z/][a-z/]*/sshdoers,/etc/sshdoers,' \
-e 's,"/[a-z/][a-z/]*/sshdo","/usr/local/bin/sshdo",' \
-e 's, /[a-z/][a-z/]*/sshdo\.$, /usr/local/bin/sshdo.,' \
-e 's,^# logfiles .*$,# logfiles /var/log/auth.log*,' \
-e 's,^# banner .*$,# banner /etc/sshdo.banner,'
editconf test_sshdo \
-e "s,'/var/log/..*','/var/log/auth.log',"
;;
*)
echo "Unknown platform: Check Makefile for binary/config/manpage installation locations"
;;
esac
need_python_name=1
if [ $default = 1 ]
then
echo "Configuring --default"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr,' \
-e 's,^\(BINDIR = \).*$,\1$(PREFIX)/bin,' \
-e 's,^\(MANDIR = \).*$,\1$(PREFIX)/share/man,' \
-e 's,^\(ETCDIR = \).*$,\1/etc,' \
-e 's,^\(MAN_GZIP =\) 1,\1 0,'
editconf sshdo \
-e "s,default_config_fname = '.*',default_config_fname = '/etc/sshdoers'," \
-e "s,default_logfiles = '.*',default_logfiles = '/var/log/auth.log*'," \
-e "s,/[a-z/][a-z/]*/sshdo ,/usr/bin/sshdo ,"
editconf sshdoers \
-e 's,/[a-z/][a-z/]*/sshdoers,/etc/sshdoers,' \
-e 's,"/[a-z/][a-z/]*/sshdo","/usr/bin/sshdo",' \
-e 's, /[a-z/][a-z/]*/sshdo\.$, /usr/bin/sshdo.,' \
-e 's,^# logfiles .*$,# logfiles /var/log/auth.log*,' \
-e 's,^# banner .*$,# banner /etc/sshdo.banner,'
editconf test_sshdo \
-e "s,'/var/log/..*','/var/log/auth.log',"
editconf sshdo \
-e 's|^#!/.*$|#!/usr/bin/env python3|'
editconf test_sshdo \
-e 's|^#!/.*$|#!/usr/bin/env python3|'
need_python_name=0
fi
# Process command line options
for opt in "$@"
do
case "$opt" in
--verbose|-v)
;;
--test|-n)
;;
--default|default)
;;
--destdir=*)
echo "Configuring $opt"
destdir="${opt#--destdir=}"
[ -n "$destdir" ] && destdir=" $destdir"
editconf Makefile \
-e 's|^\(DESTDIR =\).*$|\1'"$destdir"'|'
;;
--prefix=*)
echo "Configuring $opt"
prefix="${opt#--prefix=}"
[ "$prefix" = "default" ] && prefix=/usr
editconf Makefile \
-e 's|^\(PREFIX =\).*$|\1 '"$prefix"'|'
editconf sshdo \
-e "s|/[a-z/][a-z/]*/sshdo |$prefix/bin/sshdo |"
editconf sshdoers \
-e 's|"/[a-z/][a-z/]*/sshdo"|"'"$prefix"'/bin/sshdo"|' \
-e 's| /[a-z/][a-z/]*/sshdo\.$| '"$prefix"'/bin/sshdo.|'
;;
--etcdir=*)
echo "Configuring $opt"
etcdir="${opt#--etcdir=}"
editconf Makefile \
-e 's|^\(ETCDIR =\).*$|\1 '"$etcdir"'|'
editconf sshdo \
-e "s|default_config_fname = '.*'|default_config_fname = '$etcdir/sshdoers'|"
editconf sshdoers \
-e "s,/[a-z/][a-z/]*/sshdoers,$etcdir/sshdoers," \
-e "s,^# banner .*$,# banner $etcdir/sshdo.banner,"
;;
--mandir=*)
echo "Configuring $opt"
mandir="${opt#--mandir=}"
editconf Makefile \
-e 's|^\(MANDIR =\).*$|\1 '"$mandir"'|'
;;
--macports|--macports-prefix=*) # default prefix=/opt/local etcdir=$prefix/etc mandir=$prefix/share/man manzip=1
echo "Configuring $opt"
if [ "x$opt" = x--macports ]
then
prefix="/opt/local"
else
prefix="${opt#--macports-prefix=}"
fi
editconf Makefile \
-e 's|^\(PREFIX = \).*$|\1'"$prefix"'|' \
-e 's,^\(BINDIR = \).*$,\1$(PREFIX)/bin,' \
-e 's,^\(MANDIR = \).*$,\1$(PREFIX)/share/man,' \
-e 's,^\(ETCDIR = \).*$,\1$(PREFIX)/etc,' \
-e 's,^\(MAN_GZIP =\) 0,\1 1,'
editconf sshdo \
-e "s|default_config_fname = '.*'|default_config_fname = '$prefix/etc/sshdoers'|" \
-e "s|default_logfiles = '.*'|default_logfiles = '/var/log/system.log*'|" \
-e "s|/[a-z/][a-z/]*/sshdo |$prefix/bin/sshdo |"
editconf sshdoers \
-e 's|/[a-z/][a-z/]*/sshdoers|'"$prefix"'/etc/sshdoers|' \
-e 's|"/[a-z/][a-z/]*/sshdo"|"'"$prefix"'/bin/sshdo"|' \
-e 's| /[a-z/][a-z/]*/sshdo\.$| '"$prefix"'/bin/sshdo.|' \
-e 's|^# logfiles .*$|# logfiles /var/log/system.log*|' \
-e 's|^# banner .*$|# banner '"$prefix"'/etc/sshdo.banner|'
editconf test_sshdo \
-e "s,'/var/log/..*','/var/log/system.log',"
;;
--enable-mangz)
echo "Configuring $opt"
editconf Makefile \
-e 's,^\(MAN_GZIP =\).*$,\1 1,'
;;
--disable-mangz)
echo "Configuring $opt"
editconf Makefile \
-e 's,^\(MAN_GZIP =\).*$,\1 0,'
;;
--with-python=*)
echo "Configuring $opt"
python="${opt#--with-python=}"
need_python_name=0
case "$python" in
/?*)
editconf sshdo \
-e 's|^#!/usr/bin/env .*$|#!'"$python"'|'
editconf test_sshdo \
-e 's|^#!/usr/bin/env .*$|#!'"$python"'|'
;;
*)
editconf sshdo \
-e 's|^#!/usr/bin/env .*$|#!/usr/bin/env '"$python"'|'
editconf test_sshdo \
-e 's|^#!/usr/bin/env .*$|#!/usr/bin/env '"$python"'|'
;;
esac
;;
*)
echo "$0: Unknown argument: $opt" >&2
exit 1
;;
esac
done
# Find out what Python is called here (if not already specified)
if [ $need_python_name = 1 ]
then
for pyname in python3 python
do
[ -z "`command -v $pyname`" ] && continue
editconf sshdo \
-e 's|^#!/usr/bin/env .*$|#!/usr/bin/env '"$pyname"'|'
editconf test_sshdo \
-e 's|^#!/usr/bin/env .*$|#!/usr/bin/env '"$pyname"'|'
exit 0
done
echo "$0: failed to find python3 or python in the PATH."
echo "Please install python3 or try again with: --with-python=/path/to/python3"
exit 1
fi
exit 0
# vi:set ts=4 sw=4: