File: autogen-support.sh

package info (click to toggle)
ipv6calc 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,400 kB
  • sloc: ansic: 73,764; sh: 5,750; perl: 4,030; xml: 1,194; makefile: 888
file content (782 lines) | stat: -rwxr-xr-x 19,665 bytes parent folder | download
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
#!/bin/bash
#
# Project    : ipv6calc
# File       : autogen-support.sh
# Version    : $Id: 73a28b7fed84152b56fe6576f4a2be103638202d $
# Copyright  : 2014-2017 by Peter Bieringer <pb (at) bieringer.de>
#
# Information: provide support functions to autogen.sh/autogen-all-variants.sh
#
# $BASE_DEVEL_GEOIP/  (default if unset: "..")
#          GeoIP-1.4.4
#          GeoIP-1.4.5
#          GeoIP-1.4.6
#          GeoIP-1.4.7
#          GeoIP-1.4.8
#          GeoIP-1.5.1
#          GeoIP-1.5.2
#          GeoIP-1.6.0
#          GeoIP-1.6.1
#          GeoIP-1.6.2
#          GeoIP-1.6.3
#          GeoIP-1.6.4
#          GeoIP-1.6.5
#          GeoIP-1.6.6	# 20161218
#          GeoIP-1.6.7	# 20161218
#          GeoIP-1.6.8	# 20161218
#          GeoIP-1.6.9	# 20161218
#          GeoIP-1.6.10	# 20170617
#          GeoIP-1.6.11	# 20170617
#
# $BASE_DEVEL_IP2LCATION/   (default if unset: "..")
#          C-IP2Location-4.0.2  # dropped with version 0.99
#          ip2location-c-6.0.1
#          IP2Location-c-6.0.2
#          ip2location-c-6.0.3	# 20141003
##          ip2location-c-7.0.0	# 20141003 DOWNLOAD BROKEN
#          ip2location-c-7.0.1	# 20150416
#          ip2location-c-8.0.1	# 20161218
#          ip2location-c-8.0.2	# 20161218
#          ip2location-c-8.0.3	# 20161218
#          ip2location-c-8.0.4	# 20170617

#### Definitions

## List of GeoIP versions (append newest one rightmost!)
geoip_versions="1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.6.10 1.6.11"
geoip_url_maxmind="http://geolite.maxmind.com/download/geoip/api/c/"
geoip_url_github="https://codeload.github.com/maxmind/geoip-api-c/tar.gz/"

# reduce version on known issues
if which autoconf >/dev/null 2>&1; then
	autoconf_version=$(autoconf -V |grep autoconf | awk '{ print $NF }' | awk -F. '{ print $1 * 1000 + $2 }')
	if [ -n "$autoconf_version" -a $autoconf_version -lt 2065 ]; then
		# autoconf >= 2.65 is required for GeoIP >= 1.5.2
		geoip_versions_orig="$geoip_versions"
		geoip_versions=""
		for version in $geoip_versions_orig; do
			[ -n "$geoip_versions" ] && geoip_versions="$geoip_versions "
			prefix=""
			version_num=$(echo $version | awk -F. '{ print $3 + $2 * 100 + $1 * 10000}')
			if [ $version_num -ge 10502 ]; then
				prefix="!"
			fi
			geoip_versions="$geoip_versions$prefix$version"
		done	
	fi
else
	echo "ERROR : missing executable in path: : autoconf" >&2
	exit 1
fi

geoip_versions_download="$geoip_versions"

geoip_cross_version_test_blacklist() {
	local version_have=$(echo $1 | awk -F. '{ print $3 + $2 * 100 + $1 * 10000}')
	local version_test=$(echo $2 | awk -F. '{ print $3 + $2 * 100 + $1 * 10000}')

	if [ $version_have -ge 10407 -a $version_test -lt 10407 ]; then
		# missing GeoIP_cleanup
		return 1
	fi

	return 0
}


## List of IP2Location versions (append newest one rightmost!)
ip2location_versions="4.0.2 6.0.1 6.0.2 6.0.3 7.0.1 8.0.1 8.0.2 8.0.3 8.0.4"
ip2location_versions_download="6.0.1 6.0.2 6.0.3 7.0.1 8.0.1 8.0.2 8.0.3 8.0.4"
ip2location_url_base="https://www.ip2location.com/downloads/"
ip2location_url_github="https://codeload.github.com/chrislim2888/IP2Location-C-Library/tar.gz/"

ip2location_cross_version_test_blacklist() {
	local version_have=$(echo $1 | awk -F. '{ print $3 + $2 * 100 + $1 * 10000}')
	local version_test=$(echo $2 | awk -F. '{ print $3 + $2 * 100 + $1 * 10000}')

	if [ $version_have -ge 60000 -a $version_test -lt 60000 ]; then
		# incompatible API
		return 1
	fi

	if [ $version_have -ge 60003 -a $version_test -lt 60003 ]; then
		# incompatible (library name got suffix .1)
		return 1
	fi

	if [ $version_have -ge 70000 -a $version_test -lt 70000 ]; then
		# incompatible
		return 1
	fi

	if [ $version_have -lt 70000 -a $version_test -ge 70000 ]; then
		# incompatible
		return 1
	fi

	return 0
}

#### NO CHANGES BELOW

### Automatic Definitions

### base directory for GeoIP/IP2Location
BASE_SOURCES=${BASE_SOURCES:-~/Downloads}

BASE_DEVEL_GEOIP=${BASE_DEVEL_GEOIP:-~/tmp}
BASE_DEVEL_IP2LOCATION=${BASE_DEVEL_IP2LOCATION:-~/tmp}


### Functions Definitions

## generate GeoIP/IP2Location source package name from version
# in download mode provide full URL
nameversion_from_name_version() {
	local name="$1"
	local version="$2"
	local mode="$3" # optional (download|extract|outfile)

	local nameversion=""

	local version_numeric=$(echo "$version" | awk -F. '{ print $3 + $2 * 100 + $1 * 10000}')

	case $name in
	    GeoIP|G)
		if [ "$mode" = "download" ]; then
			if [ $version_numeric -ge 10502 ]; then
				# since 1.5.2 on github
				nameversion="${geoip_url_github}v$version"
			else
				nameversion="${geoip_url_maxmind}GeoIP-$version.tar.gz"
			fi
		elif [ "$mode" = "outfile" ]; then
			if [ $version_numeric -ge 10502 ]; then
				# since 1.5.2 on github
				nameversion="geoip-api-c-$version.tar.gz"
			else
				nameversion="GeoIP-$version.tar.gz"
			fi
		else
			if [ $version_numeric -ge 10502 ]; then
				nameversion="geoip-api-c-$version"
			else
				nameversion="GeoIP-$version"
			fi
		fi
		;;
	    IP2Location|I)
		case $version in
		    4.*)
			nameversion="C-IP2Location-$version"
			;;
		    *)
			# default
			if [ "$mode" = "download" ]; then
				if [ $version_numeric -ge 80000 ]; then
					# since 8.0.0 on github
					nameversion="${ip2location_url_github}$version"
				else
					nameversion="${ip2location_url_base}ip2location-c-$version.tar.gz"
				fi
			elif [ "$mode" = "outfile" ]; then
				nameversion="ip2location-c-$version.tar.gz"
			elif [ "$mode" = "extract" ]; then
				case $version in
				    6.0.1|6.0.2|6.0.3|7.*|8.*)
					nameversion="ip2location-c-$version"
					;;
				    *)
					# default
					nameversion="IP2Location-c-$version"
					;;
				esac
			else
				case $version in
				    8.*)
					nameversion="IP2Location-C-Library-$version"
					;;
				    6.0.1|6.0.3|7.*)
					nameversion="ip2location-c-$version"
					;;
				    *)
					# default
					nameversion="IP2Location-c-$version"
					;;
				esac
			fi
		esac
		;;
	    *)
		echo "ERROR : unsupported: $name" >&2
		return 1
		;;
	esac

	echo "$nameversion"
}

## retrieve GeoIP/IP2Location options from version
options_from_name_version() {
	local name="$1"
	local version="$2"
	local output="$3"

	local nameversion=$(nameversion_from_name_version $name $version)

	case $name in
	    GeoIP|G)
		local dir="$BASE_DEVEL_GEOIP/$nameversion"
		libdir="$dir/libGeoIP/.libs"
		lib="$libdir/libGeoIP.so"
		result="--with-geoip-headers=$dir/libGeoIP --with-geoip-lib=$libdir"
		;;
	    IP2Location|I)
		local dir="$BASE_DEVEL_IP2LOCATION/$nameversion"
		libdir="$dir/libIP2Location/.libs"
		lib="$libdir/libIP2Location.so"
		result="--with-ip2location-headers=$dir/libIP2Location --with-ip2location-lib=$libdir"
		;;
	    *)
		echo "ERROR : unsupported: $name" >&2
		return 1
		;;
	esac

	case $output in
	    'only-lib')
		echo "$lib"
		;;
	    'only-libdir')
		echo "$libdir"
		;;
	    *)
		echo "$result"
		;;
	esac
}

## fallback for GeoIP/IP2Location
fallback_options_from_name() {
	local name="$1"

	local file_header=""
	local versions=""

	case $name in
	    GeoIP|G)
		file_header="/usr/include/GeoIP.h"
		versions="$geoip_versions"
		dir_base="$BASE_DEVEL_GEOIP"
		;;
	    IP2Location|I)
		file_header="/usr/include/IP2Location.h"
		versions="$ip2location_versions"
		dir_base="$BASE_DEVEL_IP2LOCATION"
		;;
	    *)
		echo "ERROR : unsupported: $name" >&2
		return 1
		;;
	esac

	if [ -e "$file_header" ]; then
		echo "NOTICE: file is existing, no fallback required for $name: $file_header" >&2
		return 0
	fi

	echo "NOTICE: file is missing $file_header, check for local availability for $name: $file_header" >&2

	for version in $(echo "$versions" | awk '{ for (i=NF;i>0;i--) print $i }'); do
		if [ ${version:0:1} = "!" ]; then
			echo "NOTICE: skip blacklisted version: $version" >&2
			continue
		fi

		echo "DEBUG : check for version for $name: $version" >&2

		dir="$dir_base/$(nameversion_from_name_version $name $version)"

		if [ -d "$dir" ]; then
			echo "INFO  : found at least directory for name $name: $dir" >&2
			result="$(options_from_name_version $name $version)"
			break
		else
			echo "NOTICE: did not find directory for name $name: $dir (try next)" >&2
		fi
	done

	if [ -z "$result" ]; then
		echo "ERROR : can't find any local source for $name in: $dir_base" >&2
		return 1
	fi

	echo "$result"
}


## build GeoIP/IP2Location libraries
build_library() {
	local name="$1"
	local version_selected="$2"

	echo "INFO  : build: name=$name version=$version_selected" >&2

	local versions=""
	local base_devel=""

	case $name in
	    GeoIP|G)
		versions="$geoip_versions"
		base_devel="$BASE_DEVEL_GEOIP"
		;;
	    IP2Location|I)
		versions="$ip2location_versions"
		base_devel="$BASE_DEVEL_IP2LOCATION"
		;;
	    *)
		echo "ERROR : unsupported: $name" >&2
		return 1
		;;
	esac

	result_all=0

	autoreconf_version=$(autoreconf -V |grep autoreconf | awk '{ print $NF }' | awk -F. '{ print $1 * 1000 + $2 }')

	for version in $versions; do
		if [ ${version:0:1} = "!" ]; then
			echo "NOTICE: skip blacklisted version: $version" >&2
			continue
		fi

		if [ -n "$version_selected" -a "$version" != "$version_selected" ]; then
			echo "NOTICE: skip not selected version: $version" >&2
			continue
		fi

		local version_numeric=$(echo "$version" | awk -F. '{ print $3 + $2 * 100 + $1 * 10000}')
		local nameversion=$(nameversion_from_name_version $name $version)

		if [ ! -d "$base_devel/$nameversion" ]; then
			echo "ERROR : devel directory missing: $base_devel/$nameversion (forgot to extract?)" >&2
			return 1
		fi

		pushd $base_devel/$nameversion >/dev/null
		if [ $? -ne 0 ]; then
			echo "ERROR : can't change to directory: $base_devel/$nameversion (skip)" >&2
			continue
		else
			echo "INFO  : changed to directory: $base_devel/$nameversion"
		fi

		if [ "$dry_run" = "1" ]; then
			echo "INFO  : would build library (dry-run): $name-$version ($nameversion)"
			continue
		else
			echo "INFO  : build library: $name-$version ($nameversion)"
		fi

		case $name in
		    GeoIP)
			skip_autoreconf=0
			if [ -n "$autoconf_version" -a $autoconf_version -eq 2059 ]; then
				if [ $version_numeric -eq 10407 -o $version_numeric -eq 10501 ]; then
					# on CentOS 5 with autoreconf 2.59 somehow broken for 1.4.7 and 1.5.1
					skip_autoreconf=1
				fi
			fi

			if [ $skip_autoreconf -eq 1 ]; then
				./configure && make clean && make
				result=$?
			else
				autoreconf -fi && ./configure && make clean && make
				result=$?
			fi
			;;
		    IP2Location)
			case $version in
			    6.0.3)
				echo "NOTICE: $name-$version requires patching of Makefile.am"
				perl -pi -e 's/data/ /g' Makefile.am
				;;
			esac
			autoreconf -fi && ./configure && make clean && make
			result=$?
			;;
		esac

		popd >/dev/null

		if [ $result -ne 0 ]; then
			echo "ERROR : trouble during build of $name-$version ($nameversion)" >&2
			result_all=1
			break
		else
			echo "INFO  : successful build of $name-$version ($nameversion)" >&2
			build_library_status="$build_library_status $nameversion"
		fi
	done

	return $result_all
}


## clean GeoIP/IP2Location libraries
clean_versions() {
	local name="$1"
	local version_selected="$2"

	echo "INFO  : clean: name=$name version=$version_selected" >&2

	local versions=""
	local base_devel=""

	case $name in
	    GeoIP|G)
		versions="$geoip_versions"
		base_devel="$BASE_DEVEL_GEOIP"
		;;
	    IP2Location|I)
		versions="$ip2location_versions"
		base_devel="$BASE_DEVEL_IP2LOCATION"
		;;
	    *)
		echo "ERROR : unsupported: $name" >&2
		return 1
		;;
	esac

	result_all=0

	for version in $versions; do
		if [ ${version:0:1} = "!" ]; then
			echo "NOTICE: skip blacklisted version: $version" >&2
			continue
		fi

		if [ -n "$version_selected" -a "$version" != "$version_selected" ]; then
			echo "NOTICE: skip not selected version: $version" >&2
			continue
		fi

		local nameversion=$(nameversion_from_name_version $name $version)

		if [ ! -d "$base_devel/$nameversion" ]; then
			echo "NOTICE: devel directory missing: $base_devel/$nameversion (nothing to clean)" >&2
			continue
		fi

		if [ "$dry_run" = "1" ]; then
			echo "INFO  : would remove: $base_devel/$nameversion" >&2
			continue
		else
			echo "INFO  : remove: $base_devel/$nameversion" >&2
		fi

		rm -rf $base_devel/$nameversion
		result=$?

		if [ $result -ne 0 ]; then
			echo "ERROR : trouble during remove of of $name-$version ($nameversion)" >&2
			result_all=1
			break
		else
			echo "INFO  : successful remove of $name-$version ($nameversion)" >&2
			clean_library_status="$clean_library_status $nameversion"
		fi
	done

	return $result_all
}
## extract GeoIP/IP2Location source packages
extract_versions() {
	local name="$1"
	local version_selected="$2"

	echo "INFO  : extract: name=$name version=$version_selected" >&2

	case $name in
	    GeoIP|G)
		versions="$geoip_versions"
		base_devel="$BASE_DEVEL_GEOIP"
		;;
	    IP2Location|I)
		versions="$ip2location_versions"
		base_devel="$BASE_DEVEL_IP2LOCATION"
		;;
	    *)
		echo "ERROR : unsupported: $name" >&2
		return 1
		;;
	esac

	result_all=0

	for version in $versions; do
		if [ ${version:0:1} = "!" ]; then
			echo "NOTICE: skip blacklisted version: $version" >&2
			continue
		fi

		if [ -n "$version_selected" -a "$version" != "$version_selected" ]; then
			echo "NOTICE: skip not selected version: $version" >&2
			continue
		fi

		local nameversion=$(nameversion_from_name_version $name $version extract)

		local nameversion_internal=$(nameversion_from_name_version $name $version)
		local file="$BASE_SOURCES/$nameversion.tar.gz"

		if [ ! -f "$file" ]; then
			echo "NOTICE: file not existing, can't extract: $file" >&2
			continue
		fi

		if [ "$dry_run" = "1" ]; then
			echo "INFO  : would extract source package (dry-run): $name-$version ($nameversion) from $file" >&2
			continue
		else
			echo "INFO  : extract source package: $name-$version ($nameversion): $file" >&2
		fi

		if [ ! -d "$base_devel" ]; then
			echo "ERROR : base devel directory missing: $base_devel" >&2
			return 1
		fi

		# check contents of tgz
		base_dir=$(tar tzf "$file" | head -1 | sed 's/^\.\///g' | awk -F /  '{ print $1 }')
		if [ -z "$base_dir" ]; then
			echo "ERROR : can't extract base_dir from: $file" >&2
			return 1
		fi

		echo "INFO  : file contains base_dir: $base_dir" >&2

		if [ "$nameversion_internal" != "$base_dir" ]; then
			echo "ERROR : nameversion is not matching base_dir: $nameversion_internal <=> $base_dir (download broken or workaround required)"
			return 1
		fi

		tar xzf "$file" -C $base_devel
		result=$?

		if [ $result -ne 0 ]; then
			echo "ERROR : trouble during extract of $name-$version ($nameversion) from $file" >&2
			result_all=1
			break
		else
			echo "INFO  : successful extract of $name-$version ($nameversion) from $file to $base_devel" >&2
			extract_library_status="$extract_library_status $nameversion"
		fi
	done

	return $result_all
}
## retrieve GeoIP/IP2Location source packages
download_versions() {
	local name="$1"
	local version_selected="$2"

	echo "INFO  : download: name=$name version=$version_selected" >&2

	case $name in
	    GeoIP|G)
		versions="$geoip_versions_download"
		base_devel="$BASE_DEVEL_GEOIP"
		;;
	    IP2Location|I)
		versions="$ip2location_versions_download"
		base_devel="$BASE_DEVEL_IP2LOCATION"
		;;
	    *)
		echo "ERROR : unsupported: $name" >&2
		return 1
		;;
	esac

	result_all=0

	for version in $versions; do
		if [ ${version:0:1} = "!" ]; then
			echo "NOTICE: skip blacklisted version: $version" >&2
			continue
		fi

		if [ -n "$version_selected" -a "$version" != "$version_selected" ]; then
			echo "NOTICE: skip not selected version: $version" >&2
			continue
		fi

		local url=$(nameversion_from_name_version $name $version download)
		local outfile="$(nameversion_from_name_version $name $version outfile)"

		local outfile_option=""
		local outfile_option_info=""
		if ! echo "$url" | grep -q "$outfile"; then
			# URL does not contains outfile
			outfile_option="-O $outfile"
			outfile_option_info="($outfile_option)"
		fi

		if [ ! -d "$BASE_SOURCES" ]; then
			echo "ERROR : base source directory missing: $BASE_SOURCES (BASE_SOURCES)" >&2
			return 1
		fi

		pushd $BASE_SOURCES >/dev/null
		if [ $? -ne 0 ]; then
			echo "ERROR : can't change to directory: $BASE_SOURCES (BASE_SOURCES)" >&2
			return 1
		fi

		if [ "$dry_run" = "1" ]; then
			echo "INFO  : would download source package (dry-run): $name-$version from $url $outfile_option_info" >&2
			continue
		else
			echo "INFO  : download source package: $name-$version from $url $outfile_option_info" >&2
		fi

		wget -c -q "$url" $outfile_option
		result=$?

		popd >/dev/null

		if [ $result -ne 0 ]; then
			echo "ERROR : trouble during downloading of $name-$version from $url" >&2
			result_all=1
			break
		else
			echo "INFO  : successful downloaded of $name-$version from $url to $BASE_SOURCES" >&2
			download_library_status="$download_library_status $name:$version"
		fi
	done

	return $result_all
}

## help
help() {
	cat <<END
$0 [-h|-?]
$0 source
$0 [-D] [-X] [-B] [-n] [GeoIP|IP2Location [<version>]]
$0 [-A] [-n] [GeoIP|IP2Location [<version>]]

	source: source mode (using functions only in main script)

	-D  : download GeoIP/IP2Location source packages
	-C  : clean GeoIP/IP2Location source packages
	-X  : extract GeoIP/IP2Location source packages
	-B  : build GeoIP/IP2Location libraries
	-A  : whole chain: download/extract/build
	-n  : dry-run
	(optionally, type and version can be specified)

	GeoIP: $geoip_versions
	IP2Location: $ip2location_versions
	Prefix '!' means not supported on this platform

	-h|?: this online help

	used values from environment (or defaults):
	  BASE_SOURCES=$BASE_SOURCES
	  BASE_DEVEL_GEOIP=$BASE_DEVEL_GEOIP
	  BASE_DEVEL_IP2LOCATION=$BASE_DEVEL_IP2LOCATION
END
}

if [ "$1" != "source" ]; then
	# use script not only as source (function-mode)

	#### Main
	while getopts ":ADCXnB?h" opt; do
		case $opt in
		    'n')
			dry_run=1
			echo "NOTICE: dry-run selected" >&2
			;;
		    'A')
			action="prepare"
			do_download="1"
			do_clean="1"
			do_extract="1"
			do_build="1"
			;;
		    'C')
			action="prepare"
			do_clean="1"
			;;
		    'D')
			action="prepare"
			do_download="1"
			;;
		    'X')
			action="prepare"
			do_extract="1"
			;;
		    'B')
			action="prepare"
			do_build="1"
			;;
		    \?|h)
			help
			exit 1
			;;
		    *)
			echo "Invalid option: -$OPTARG" >&2
			exit 1
			;;
		esac
	done

	shift $[ $OPTIND - 1 ]

	case $action in
	    'prepare')
		if [ "$do_download" = "1" ]; then
			if [ -z "$*" ]; then
				download_versions GeoIP || exit 1
				download_versions IP2Location || exit 1
			else
				download_versions $* || exit 1
			fi
			echo "INFO  : following libaries were successfully downloaded: $download_library_status" >&2
		fi
		if [ "$do_clean" = "1" ]; then
			if [ -z "$*" ]; then
				clean_versions GeoIP || exit 1
				clean_versions IP2Location || exit 1
			else
				clean_versions $* || exit 1
			fi
			echo "INFO  : following libaries were successfully cleaned: $clean_library_status" >&2
		fi
		if [ "$do_extract" = "1" ]; then
			if [ -z "$*" ]; then
				extract_versions GeoIP || exit 1
				extract_versions IP2Location || exit 1
			else
				extract_versions $* || exit 1
			fi
			echo "INFO  : following libaries were successfully extracted: $extract_library_status" >&2
		fi
		if [ "$do_build" = "1" ]; then
			if [ -z "$*" ]; then
				build_library GeoIP || exit 1
				build_library IP2Location || exit 1
			else
				build_library $* || exit 1
			fi
			echo "INFO  : following libaries were successfully built: $build_library_status" >&2
		fi
		;;
	    *)
		help
		;;
	esac
fi