-
Notifications
You must be signed in to change notification settings - Fork 0
/
cvmfs-client-setup.sh
executable file
·850 lines (683 loc) · 20.2 KB
/
cvmfs-client-setup.sh
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
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
#!/bin/sh
#
# Create a client host.
#
# Note: this is a POSIX "sh" script for maximum portability.
#
# Copyright (C) 2021, 2022, QCIF Ltd.
#================================================================
PROGRAM='cvmfs-client-setup'
VERSION='3.1.0'
EXE=$(basename "$0" .sh)
EXE_EXT=$(basename "$0")
#----------------------------------------------------------------
# Constants
# Default port for the proxy cache
DEFAULT_PROXY_PORT=3128
# Default cache size in MiB (should be between 4 GiB and 50 GiB)
DEFAULT_CACHE_SIZE_MB=4096 # 4 GiB
# Minimum value allowed for --size option in MiB
MIN_CACHE_SIZE_MB=1024 # 1 GiB
#----------------
# Header inserted into generated files
PROGRAM_INFO="Created by $PROGRAM $VERSION [$(date '+%F %T %Z')]"
#----------------------------------------------------------------
# Error handling
# Exit immediately if a simple command exits with a non-zero status.
# Better to abort than to continue running when something went wrong.
set -e
set -u # fail on attempts to expand undefined environment variables
#----------------------------------------------------------------
# Utility functions
# Internally, REPOS contains a list of repository specifications.
# These functions extract out the fully qualified repository name
# (FQRN), public key filename and organisation from a repository
# specification.
_fqrn() {
echo "$1" | sed 's/:.*$//' # everything before first colon
}
_pubkey_file() {
echo "$1" | sed 's/^[^:]*://' # everything after the first colon
}
_org_id() {
_fqrn "$1" | sed -E 's/^[^\.]+\.//'
}
# Parse a command line argument into the repository ID and public key filename
# Prints out "repo_id:filename"
_canonicalise_repo() {
ARG="$1"
if echo "$ARG" | grep -q ':'; then
# Has colon: value should be repository_id:filename (split on first colon)
REPO_ID=$(echo "$ARG" | sed 's/:.*$'// )
FILENAME=$(echo "$ARG" | sed 's/^[^:]*://' )
else
# No colon: repository ID is the base of the filename
REPO_ID=$(basename "$ARG" .pub)
FILENAME="$ARG"
fi
# Check syntax of fully qualified repository name
ORG=$(echo "$REPO_ID" | sed -E 's/^[^\.]+\.//')
if [ -z "$ORG" ]; then
echo "$EXE: error: invalid fully qualified repository name: $REPO_ID" >&2
exit 1
fi
if [ "$ORG" = "$REPO_ID" ] || [ ".$ORG" = "$REPO_ID" ] ; then
echo "$EXE: error: invalid fully qualified repository name: $REPO_ID" >&2
exit 1
fi
# Success
echo "$REPO_ID:$FILENAME"
}
#----------------------------------------------------------------
# Command line arguments
# Note: parsing does not support combining single letter options (e.g. "-vh")
STRATUM_1_HOSTS=
CVMFS_HTTP_PROXY=
FIXED_PROXY_ORDER=
GEO_API=
CVMFS_QUOTA_LIMIT_MB=$DEFAULT_CACHE_SIZE_MB
CVMFS_VERSION=
QUIET=
VERBOSE=
VERY_VERBOSE=
SHOW_VERSION=
SHOW_HELP=
REPOS=
while [ $# -gt 0 ]
do
case "$1" in
-1|--s1|--stratum1|--stratum-1)
if [ -z "$2" ]; then
echo "$EXE: usage error: stratum 1 host cannot be an empty string" >&2
exit 2
fi
STRATUM_1_HOSTS="$STRATUM_1_HOSTS $2"
shift
;;
-p|--proxy)
if [ "$CVMFS_HTTP_PROXY" = 'DIRECT' ]; then
echo "$EXE: usage error: do not provide proxies with --direct" >&2
exit 2
fi
if echo "$2" | grep -q '^http://'; then
echo "$EXE: usage error: expecting an address, not a URL: \"$2\"" >&2
exit 2
fi
if echo "$2" | grep -q '^https://'; then
echo "$EXE: usage error: expecting an address, not a URL: \"$2\"" >&2
exit 2
fi
if echo "$2" | grep -q ':'; then
# Value has a port number
P="http://$2"
elif [ -z "$2" ]; then
echo "$EXE: usage error: proxy cannot be an empty string" >&2
exit 2
else
# Use default port number
P="http://$2:$DEFAULT_PROXY_PORT"
fi
if [ -z "$CVMFS_HTTP_PROXY" ]; then
CVMFS_HTTP_PROXY="$P"
else
CVMFS_HTTP_PROXY="$CVMFS_HTTP_PROXY|$P"
# Note: ";" separates groups, "|" separates proxies in the same group.
# The default is to treat each proxy as belonging to the same group.
# CernVM-FS will randomly choose a proxy from within a group, and
# randomly try the other proxies in the same group until one that
# works is found.
fi
shift
;;
--fixed-proxy-order)
FIXED_PROXY_ORDER=yes
;;
-d|--direct)
if [ -n "$CVMFS_HTTP_PROXY" ]; then
echo "$EXE: usage error: do not use --direct with proxies" >&2
exit 2
fi
CVMFS_HTTP_PROXY=DIRECT
;;
-g|--geo-api)
GEO_API=yes
;;
-c|--cache-size)
if [ $# -lt 2 ]; then
echo "$EXE: usage error: $1 missing value" >&2
exit 2
fi
CVMFS_QUOTA_LIMIT_MB="$2"
shift
;;
-C|--cvmfs-version)
if [ $# -lt 2 ]; then
echo "$EXE: usage error: $1 missing value" >&2
exit 2
fi
CVMFS_VERSION="$2"
shift
;;
-q|--quiet)
QUIET=yes
;;
-v|--verbose)
if [ -z "$VERBOSE" ]; then
VERBOSE=yes
else
VERY_VERBOSE=yes
fi
;;
--version)
SHOW_VERSION=yes
;;
-h|--help)
SHOW_HELP=yes
;;
-*)
echo "$EXE: usage error: unknown option: $1" >&2
exit 2
;;
*)
# Argument: use as repository
if [ -z "$1" ]; then
echo "$EXE: usage error: repository cannot be an empty string" >&2
exit 2
fi
REPOS="$REPOS $(_canonicalise_repo "$1")"
;;
esac
shift
done
if [ -n "$SHOW_HELP" ]; then
cat <<EOF
Usage: $EXE_EXT [options] { REPO_FQRN.pub | REPO_FQRN:PUBKEY }
Options:
-1 | --stratum-1 HOST Stratum 1 replica (mandatory; repeat for each)
-p | --proxy HOST[:PORT] proxy server and optional port (repeat for each)*
--fixed-proxy-order try proxies in provided order (default: random order)
-d | --direct no proxies, connect to Stratum 1 (not recommended)*
-g | --geo-api use Geo API (default: do not use Geo API)
-c | --cache-size NUM size of cache in MiB (default: $DEFAULT_CACHE_SIZE_MB)
-q | --quiet output nothing unless an error occurs
-v | --verbose output extra information when running
--version display version information and exit
-h | --help display this help and exit
REPO_FQRN: fully qualified repository name
PUBKEY: file containing the repository's public key
* = at least one --proxy or --direct is required
e.g. $EXE_EXT --stratum-1 s1.example.org --proxy p.example.org \\
data.example.org.pub tools.example.org:pubkey.pub
EOF
if [ -n "$VERBOSE" ]; then
cat <<EOF
Reload repository:
cvmfs_config reload repo.organization.tld
EOF
fi
# Experimental feature: not working on Ubuntu yet, so not mentioned in help
#
# -C | --cvmfs-version VER version, and optional release, of cvmfs to install
# (default: latest version and release)
exit 0
fi
if [ -n "$SHOW_VERSION" ]; then
echo "$PROGRAM $VERSION"
exit 0
fi
#----------------
if [ -z "$STRATUM_1_HOSTS" ]; then
echo "$EXE: usage error: missing one or more --stratum-1 hosts" >&2
exit 2
fi
if [ -z "$CVMFS_HTTP_PROXY" ]; then
echo "$EXE: usage error: missing --direct or one or more --proxy" >&2
exit 2
fi
if [ -z "$REPOS" ]; then
echo "$EXE: usage error: missing repositories (-h for help)" >&2
exit 2
fi
if ! echo "$CVMFS_QUOTA_LIMIT_MB" | grep -qE '^[0-9]+$'; then
echo "$EXE: usage error: invalid number: \"$CVMFS_QUOTA_LIMIT_MB\"" >&2
exit 2
fi
if [ "$CVMFS_QUOTA_LIMIT_MB" -lt $MIN_CACHE_SIZE_MB ]; then
echo "$EXE: usage error: cache is too small: $CVMFS_QUOTA_LIMIT_MB MiB" >&2
exit 2
fi
if [ -n "$FIXED_PROXY_ORDER" ]; then
# For multiple proxies, change from the default (where they are all in
# the same group) to them being in separate groups.
#
# https://cvmfs.readthedocs.io/en/stable/cpt-configure.html#proxy-lists
CVMFS_HTTP_PROXY=$(echo "$CVMFS_HTTP_PROXY" | sed 's/|/;/g')
fi
#----------------
# Checks
# Check that all the public key files exist
for REPO in $REPOS; do
FILENAME=$(_pubkey_file "$REPO")
if [ ! -f "$FILENAME" ]; then
echo "$EXE: usage error: file does not exist: \"$FILENAME\"" >&2
exit 2
fi
done
# Check repository is not already configured on this host
for REPO in $REPOS; do
FULLNAME=$(_fqrn "$REPO")
# Assumption: if the repository has been configured, its public key
# exists in the common/expected places.
for FILE in "/etc/cvmfs/keys/$(_org_id "$REPO")/${FULLNAME}.pub" \
"/etc/cvmfs/keys/${FULLNAME}.pub"; do
if [ -e "$FILE" ]; then
echo "$EXE: error: repository already configured: $FULLNAME ($FILE)" >&2
exit 1
fi
done
done
# Check all organisations are the same
COMMON_ORG=
for REPO in $REPOS; do
if [ -z "$COMMON_ORG" ]; then
COMMON_ORG=$(_org_id "$REPO")
elif [ "$COMMON_ORG" != "$(_org_id "$REPO")" ]; then
echo "$EXE: error: multiple organisations not supported" >&2
exit 1
fi
done
# TODO: can this script also check if the repository exists via the proxy?
#----------------------------------------------------------------
# Detect tested systems
if [ -f '/etc/system-release' ]; then
# Fedora based
DISTRO=$(head -1 /etc/system-release)
elif which lsb_release >/dev/null 2>&1; then
# Debian based
DISTRO="$(lsb_release --id --short) $(lsb_release --release --short)"
elif which uname >/dev/null 2>&1; then
# Other
DISTRO="$(uname -s) $(uname -r)"
else
DISTRO=unknown
fi
case "$DISTRO" in
'CentOS Linux release 7.'* \
| 'CentOS Linux release 8.'* \
| 'CentOS Stream release 8' \
| 'Rocky Linux release 8.5 (Green Obsidian)' \
| 'Rocky Linux release 8.6 (Green Obsidian)' \
| 'Rocky Linux release 8.7 (Green Obsidian)' \
| 'Rocky Linux release 9.0 (Blue Onyx)' \
| 'Ubuntu 22.04' \
| 'Ubuntu 21.04' \
| 'Ubuntu 20.04' \
| 'Ubuntu 20.10' )
# Tested distribution (add to above, if others have been tested)
;;
*)
echo "$EXE: warning: untested system: $DISTRO" >&2
;;
esac
#----------------------------------------------------------------
# Check for root privileges
if [ "$(id -u)" -ne 0 ]; then
echo "$EXE: error: root privileges required" >&2
exit 1
fi
#----------------------------------------------------------------
# Install CernVM-FS client
# Use LOG file to suppress apt-get messages, only show on error
# Unfortunately, "apt-get -q" and "yum install -q" still produces output.
LOG="/tmp/${PROGRAM}.$$"
#----------------
# Fedora functions
_yum_not_installed() {
if rpm -q "$1" >/dev/null; then
return 1 # already installed
else
return 0 # not installed
fi
}
_yum_no_repo() {
# CentOS 7 has yum 3.4.3: no --enabled option, output is "cernvm/7/x86_64..."
# CentOS Stream 8 has yum 4.4.2: has --enabled option, output is "cernvm "
#
# So use old "enabled" argument instead of --enabled option and look for
# slash or space after the repo name.
if $YUM repolist enabled | grep -q "^$1[/ ]"; then
return 1 # has enabled repo
else
return 0 # no enabled repo
fi
}
_yum_install_repo() {
# Install the CernVM-FS YUM repository (if needed)
REPO_NAME="$1"
URL="$2"
if _yum_no_repo "$REPO_NAME"; then
# Repository not installed
_yum_install "$URL"
if _yum_no_repo "$REPO_NAME"; then
echo "$EXE: internal error: $URL did not install repo \"$REPO_NAME\"" >&2
exit 3
fi
else
if [ -z "$QUIET" ]; then
echo "$EXE: repository already installed: $REPO_NAME"
fi
fi
}
_yum_install() {
PKG="$1"
PKG_NAME=
if ! echo "$PKG" | grep -q /^https:/; then
# Value is a URL: extract package name from it
PKG_NAME=$(echo "$PKG" | sed 's/^.*\///') # remove everything up to last /
PKG_NAME=$(echo "$PKG_NAME" | sed 's/\.rpm$//') # remove .rpm
else
# Assume the entire value is the package name
PKG_NAME="$PKG"
fi
if ! rpm -q "$PKG_NAME" >/dev/null ; then
# Not already installed
if [ -z "$QUIET" ]; then
echo "$EXE: $YUM install: $PKG"
fi
if ! $YUM install -y "$PKG" >$LOG 2>&1; then
cat $LOG
rm $LOG
echo "$EXE: error: $YUM install: $PKG failed" >&2
exit 1
fi
rm $LOG
else
if [ -z "$QUIET" ]; then
echo "$EXE: package already installed: $PKG"
fi
fi
}
#----------------
# Debian functions
_dpkg_not_installed() {
if dpkg-query -s "$1" >/dev/null 2>&1; then
return 1 # already installed
else
return 0 # not installed
fi
}
_dpkg_download_and_install() {
# Download a Debian file from a URL and install it.
PKG_NAME="$1"
URL="$2"
if _dpkg_not_installed "$PKG_NAME"; then
# Download it
if [ -z "$QUIET" ]; then
echo "$EXE: downloading $URL"
fi
DEB_FILE="/tmp/$(basename "$URL").$$"
if ! wget --quiet -O "$DEB_FILE" "$URL"; then
rm -f "$DEB_FILE"
echo "$EXE: error: could not download: $URL" >&2
exit 1
fi
# Install it
if [ -z "$QUIET" ]; then
echo "$EXE: dpkg installing download file"
fi
if ! dpkg --install "$DEB_FILE" >$LOG 2>&1; then
cat $LOG
rm $LOG
echo "$EXE: error: dpkg install failed" >&2
exit 1
fi
rm -f "$DEB_FILE"
if _dpkg_not_installed "$PKG_NAME"; then
# The package from the URL did not install the expected package
echo "$EXE: internal error: $URL did not install $PKG_NAME" >&2
exit 3
fi
else
if [ -z "$QUIET" ]; then
echo "$EXE: package already installed: $PKG_NAME"
fi
fi
}
_apt_get_update() {
if [ -z "$QUIET" ]; then
echo "$EXE: apt-get update"
fi
if ! apt-get update >$LOG 2>&1; then
cat $LOG
rm $LOG
echo "$EXE: error: apt-get update failed" >&2
exit 1
fi
}
_apt_get_install() {
PKG="$1"
if _dpkg_not_installed "$PKG" ; then
# Not already installed: install it
if [ -z "$QUIET" ]; then
echo "$EXE: apt-get install $PKG"
fi
if ! apt-get install -y "$PKG" >$LOG 2>&1; then
cat $LOG
rm $LOG
echo "$EXE: error: apt-get install cvmfs failed" >&2
exit 1
fi
rm $LOG
else
if [ -z "$QUIET" ]; then
echo "$EXE: package already installed: $PKG"
fi
fi
}
#----------------
# Install for either Fedora or Debian based distributions
YUM=yum
if which dnf >/dev/null 2>&1; then
YUM=dnf
fi
if which $YUM >/dev/null 2>&1; then
# Installing for Fedora based distributions
if _yum_not_installed 'cvmfs'; then
# Get cvmfs-release-latest repo
_yum_install_repo 'cernvm' \
https://ecsft.cern.ch/dist/cvmfs/cvmfs-release/cvmfs-release-latest.noarch.rpm
# Install cvmfs
CVMFS_DNF_VERSION_SUFFIX=
if [ -n "$CVMFS_VERSION" ]; then
# e.g. version only "-2.1.0", or with release "-2.1.0-1"
CVMFS_DNF_VERSION_SUFFIX="-$CVMFS_VERSION"
fi
_yum_install cvmfs$CVMFS_DNF_VERSION_SUFFIX
if [ -n "$VERBOSE" ]; then
echo "$EXE: installed:"
rpm -qa \
--queryformat '%{NAME}-%{VERSION}-%{RELEASE} (%{BUILDTIME:day})\n' \
cvmfs\* | sort | sed 's/^/ /'
fi
else
if [ -z "$QUIET" ]; then
echo "$EXE: package already installed: cvmfs"
fi
fi
elif which apt-get >/dev/null 2>&1; then
# Installing for Debian based distributions
if _dpkg_not_installed 'cvmfs' ; then
# Install cvmfs
# Get cvmfs-release-latest-all repo
_dpkg_download_and_install 'cvmfs-release' \
https://ecsft.cern.ch/dist/cvmfs/cvmfs-release/cvmfs-release-latest_all.deb
_apt_get_update
# Install cvmfs
CVMFS_APT_VERSION_SUFFIX=
if [ -n "$CVMFS_VERSION" ]; then
CVMFS_APT_VERSION_SUFFIX="=$CVMFS_VERSION"
fi
_apt_get_install cvmfs$CVMFS_APT_VERSION_SUFFIX
else
if [ -z "$QUIET" ]; then
echo "$EXE: package already installed: cvmfs"
fi
fi
else
echo "$EXE: unsupported distribution: no apt-get, yum or dnf" >&2
exit 3
fi
#----------------------------------------------------------------
# Disable default repositories
#
# Disable the configurations of the CERN and EGI repositories that
# comes with the "cvmfs" package, since the example proxy will not be
# configured to support them.
for F in \
/etc/cvmfs/config.d/cvmfs-config.cern.ch.conf \
/etc/cvmfs/default.d/50-cern-debian.conf \
/etc/cvmfs/domain.d/cern.ch.conf \
/etc/cvmfs/domain.d/egi.eu.conf \
/etc/cvmfs/domain.d/opensciencegrid.org.conf \
; do
if [ -f "$F" ]; then
mv "$F" "$F-DISABLED"
fi
done
#----------------------------------------------------------------
# Configure CernVM-FS
#----------------
# Calculate CVMFS_SERVER_URL with all the Stratum 1 replica hosts
CVMFS_SERVER_URL=
for S1_HOST in $STRATUM_1_HOSTS; do
URL="http://${S1_HOST}/cvmfs/@fqrn@"
if [ -z "$CVMFS_SERVER_URL" ]; then
CVMFS_SERVER_URL=$URL
else
CVMFS_SERVER_URL="$CVMFS_SERVER_URL;$URL"
fi
done
# TODO: this does not work if there are multiple organisations.
#----------------
# Create the organisation config file(s)
for REPO in $REPOS; do
ORG=$(_org_id "$REPO")
FILE=/etc/cvmfs/domain.d/${ORG}.conf
if [ ! -e "$FILE" ]; then
# Create organisation config file
if [ -z "$QUIET" ]; then
echo "$EXE: configuring organisation: $FILE"
fi
ORG_KEY_DIR="/etc/cvmfs/keys/$(_org_id "$REPO")"
cat > "$FILE" <<EOF
# CVMFS repository configuration: $ORG
# $PROGRAM_INFO
CVMFS_SERVER_URL="$CVMFS_SERVER_URL"
CVMFS_KEYS_DIR="$ORG_KEY_DIR"
EOF
else
if [ -n "$VERY_VERBOSE" ]; then
echo "$EXE: organisation already configured: $FILE"
fi
fi
done
#----------------
# Add public keys to the organisation's key directory
for REPO in $REPOS; do
FULLNAME=$(_fqrn "$REPO")
ORG_KEY_DIR="/etc/cvmfs/keys/$(_org_id "$REPO")"
if [ ! -e "$ORG_KEY_DIR" ]; then
if ! mkdir "$ORG_KEY_DIR"; then
echo "$EXE: error: could not create directory: $ORG_KEY_DIR" >&2
exit 1
fi
fi
REPO_PUBKEY_FILE="${ORG_KEY_DIR}/${FULLNAME}.pub"
if [ -z "$QUIET" ]; then
echo "$EXE: public key for repository: $REPO_PUBKEY_FILE"
fi
cp "$(_pubkey_file "$REPO")" "$REPO_PUBKEY_FILE"
chmod 644 "$REPO_PUBKEY_FILE"
# TODO: what about configuring /etc/cvmfs/config.d/${FULLNAME}.conf?
done
#----------------------------------------------------------------
# The local defaults file
FILE="/etc/cvmfs/default.local"
NEW_IDS=
for REPO in $REPOS; do
FULLNAME=$(_fqrn "$REPO")
if [ -z "$NEW_IDS" ]; then
NEW_IDS="${FULLNAME}"
else
NEW_IDS="${NEW_IDS},${FULLNAME}"
fi
done
if [ ! -f "$FILE" ] ; then
CVMFS_REPOSITORIES="$NEW_IDS" # no previously configured repositories
else
EXISTING_REPOS=$(grep CVMFS_REPOSITORIES /etc/cvmfs/default.local | \
sed 's/^CVMFS_REPOSITORIES=\(.*\)/\1/')
if [ -n "$EXISTING_REPOS" ]; then
CVMFS_REPOSITORIES="${EXISTING_REPOS},${NEW_IDS}" # append new repositories
else
CVMFS_REPOSITORIES="$NEW_IDS" # no previously configured repositories
fi
fi
if [ -z "$QUIET" ]; then
echo "$EXE: configuring: $FILE"
fi
GEO='CVMFS_USE_GEOAPI=yes # sort servers by geographic distance from client'
if [ -z "$GEO_API" ]; then
# Do not enable use of Geo API
GEO="# $GEO"
fi
cat > "$FILE" <<EOF
# CVMFS default.local
# $PROGRAM_INFO
# CVMFS_HTTP_PROXY
#
# Proxies within the same group are separated by a pipe character "|" and
# groups are separated from each other by a semicolon character ";".
# When finding a working proxy, all the proxies in a group are randomly
# tried, before then trying the next group.
#
# See <https://cvmfs.readthedocs.io/en/stable/cpt-configure.html#proxy-lists>
# for details.
CVMFS_HTTP_PROXY="$CVMFS_HTTP_PROXY"
CVMFS_QUOTA_LIMIT=${CVMFS_QUOTA_LIMIT_MB} # cache size in MiB (recommended: 4GB to 50GB)
$GEO
# Configured repositories
CVMFS_REPOSITORIES=$CVMFS_REPOSITORIES
EOF
#----------------------------------------------------------------
# Configure CVMFS
# Check
if ! cvmfs_config chksetup >$LOG 2>&1; then
cat $LOG
rm $LOG
echo "$EXE: error: bad cvmfs setup" 2>&1
exit 1
fi
rm $LOG
# Setup
if [ -z "$QUIET" ]; then
echo "$EXE: running \"cvmfs_config setup\""
fi
if ! cvmfs_config setup >$LOG 2>&1; then
cat $LOG
rm $LOG
echo "$EXE: error: cvmfs_config setup failed" 2>&1
exit 1
fi
if [ -n "$VERY_VERBOSE" ]; then
# This doesn't usually produce any output, but maybe it might in the future?
cat $LOG
fi
rm $LOG
#----------------------------------------------------------------
# Success
if [ -z "$QUIET" ]; then
echo "$EXE: done"
fi
exit 0
#EOF