forked from cvmfs/cvmfsexec
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmountrepo
executable file
·103 lines (87 loc) · 3.06 KB
/
mountrepo
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
#!/bin/bash
#
# Mount a cvmfs repository as an unprivileged user.
# Works with fusermount or with a kernel (>= 4.18) that supports mounting
# fuse repositories in unprivileged "fakeroot" namespaces.
# Mounts in cvmfs subdirectory of the directory where the command is found.
# Written by Dave Dykstra 17 April 2019
#
usage()
{
echo "Usage: mountrepo repo.name" >&2
exit 1
}
if [ $# != 1 ]; then
usage
fi
REPO="$1"
if [ -n "$CVMFSEXEC_CMDFD" ] && [ -n "$CVMFSEXEC_WAITFIFO" ]; then
# this is within cvmfsexec, requesting to mount another repo
if [ -z "$CVMFSMOUNT" ]; then
echo "$0: mount within cvmfsexec only works through \$CVMFSMOUNT interface" >&2
exit 1
fi
# Send command to the "parent" process still outside the namespace.
# "Parent" is in quotes because the linux process tree gets reversed and
# it is actually a linux child. It is a parent environment-wise though.
echo MOUNTREPO $REPO >&$CVMFSEXEC_CMDFD
exec {CVMFSEXEC_CMDFD}>&- # close it, no longer needed
# wait until that process is finished mounting
read RET <$CVMFSEXEC_WAITFIFO
exit $RET
fi
HERE="$(cd `dirname $0` && pwd)"
DIST="$HERE/dist"
if [ ! -f $DIST/usr/bin/cvmfs2 ] || \
[ -z "`find $DIST/etc/cvmfs/default.d -name "*.conf" 2>/dev/null`" ]; then
echo "$DIST should be rpm2cpio of cvmfs + config rpm" >&2
exit 1
fi
CONFFILE="`mktemp`"
trap "rm -f $CONFFILE" 0
relocate()
{
sed -e "s,^\([^/]*\)/cvmfs,\1$DIST/cvmfs," \
-e "s,^\([^/]*\)/etc,\1$DIST/etc," \
-e "s,^\([^/]*\)/var,\1$DIST/var," $* 2>/dev/null
}
DOMAIN="`echo "$REPO"|cut -d. -f2-`"
(
relocate $DIST/etc/cvmfs/default.conf
relocate $DIST/etc/cvmfs/default.d/*.conf
CONFIG_REPO="`sed -n 's/^CVMFS_CONFIG_REPOSITORY=//p' $DIST/etc/cvmfs/default.d/*.conf`"
if [ "$REPO" != "$CONFIG_REPO" ]; then
relocate $DIST/cvmfs/$CONFIG_REPO/etc/cvmfs/default.conf
fi
DEFLOCAL=$DIST/etc/cvmfs/default.local
relocate $DEFLOCAL
# set some defaults if they weren't already in the dist's default.local
if ! grep -q "^CVMFS_HTTP_PROXY=" $DEFLOCAL 2>/dev/null; then
echo 'CVMFS_HTTP_PROXY="auto;DIRECT"'
echo 'CVMFS_PAC_URLS="http://cernvm-wpad.fnal.gov/wpad.dat;http://cernvm-wpad.cern.ch/wpad.dat"'
fi
if ! grep -q "^CVMFS_NFILES=" $DEFLOCAL 2>/dev/null; then
echo "CVMFS_NFILES=`ulimit -Hn`"
fi
if ! grep -q "^CVMFS_USYSLOG=" $DEFLOCAL 2>/dev/null; then
mkdir -p $HERE/log
echo "CVMFS_USYSLOG=$HERE/log/$REPO.log"
fi
if [ "$REPO" != "$CONFIG_REPO" ]; then
relocate $DIST/cvmfs/$CONFIG_REPO/etc/cvmfs/domain.d/$DOMAIN.conf
fi
relocate $DIST/etc/cvmfs/domain.d/$DOMAIN.conf
relocate $DIST/etc/cvmfs/domain.d/$DOMAIN.local
if [ "$REPO" != "$CONFIG_REPO" ]; then
relocate $DIST/cvmfs/$CONFIG_REPO/etc/cvmfs/config.d/$REPO.conf
fi
relocate $DIST/etc/cvmfs/config.d/$REPO.conf
relocate $DIST/etc/cvmfs/config.d/$REPO.local
) > $CONFFILE
OPTS=""
if grep -q ^CVMFS_DEBUGLOG=. $CONFFILE; then
OPTS="$OPTS,debug"
fi
mkdir -p $DIST/var/run/cvmfs
mkdir -p $DIST/cvmfs/$REPO
LD_LIBRARY_PATH=$DIST/usr/lib64 $DIST/usr/bin/cvmfs2 -o config=$CONFFILE$OPTS $REPO $DIST/cvmfs/$REPO