-
Notifications
You must be signed in to change notification settings - Fork 14
/
mountrepo
executable file
·158 lines (140 loc) · 4.64 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
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
#!/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.
set -e
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 ] || [ ! -f $DIST/etc/cvmfs/default.conf ]; then
echo "$DIST should be rpm2cpio of cvmfs rpm" >&2
exit 1
fi
CONFFILE="`mktemp`"
trap "rm -f $CONFFILE" 0
# recursively substitute a ". " or "source " with the contents of the
# sourced file.
procsource()
{
for FILE; do
while read LINE; do
case "$LINE" in
". "*) eval procsource "${LINE/. /}";;
"source "*) eval procsource "${LINE/source /}";;
*) echo "$LINE";;
esac
done <$FILE
done
}
# relocate the given files and process them for sourced files the same way
# that cvmfs does
relocate()
{
cd ${1%/*}
# do /var first in case $DIST begins with /var
procsource $* 2>/dev/null | \
sed -e "s,^\([^/]*\)/var,\1$DIST/var," \
-e "s,^\([^/]*\)/etc,\1$DIST/etc," \
-e "s,^\([^/]*\)/cvmfs$,\1$DIST/cvmfs," \
-e "s,^\([^/]*\)/cvmfs/,\1$DIST/cvmfs/,"
cd - >/dev/null
}
DOMAIN="`echo "$REPO"|cut -d. -f2-`"
(
DEFD_FILES="`find $DIST/etc/cvmfs/default.d -name "*.conf" 2>/dev/null`"
if [ -n "$DEFD_FILES" ]; then
CONFIG_REPO="`sed -n 's/^CVMFS_CONFIG_REPOSITORY=//p' $DIST/etc/cvmfs/default.d/*.conf`"
fi
# these are used in some configuration repository includes, set them
# for procsource
CVMFS_CONFIG_REPOSITORY=$CONFIG_REPO
CVMFS_MOUNT_DIR=$DIST/cvmfs
relocate $DIST/etc/cvmfs/default.conf
if [ -n "$DEFD_FILES" ]; then
relocate $DIST/etc/cvmfs/default.d/*.conf
fi
if [ -n "$CONFIG_REPO" -a "$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_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 ! grep -q "^CVMFS_CACHE_BASE=" $DEFLOCAL 2>/dev/null && [ -d /e2fs ]; then
mkdir -p /e2fs/cvmfscache
echo "CVMFS_CACHE_BASE=/e2fs/cvmfscache"
fi
if [ -n "$CONFIG_REPO" -a "$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 [ -n "$CONFIG_REPO" -a "$REPO" != "$CONFIG_REPO" ]; then
REPOCONF=$DIST/cvmfs/$CONFIG_REPO/etc/cvmfs/config.d/$REPO.conf
if [ "$REPO" = oasis.opensciencegrid.org ]; then
# OASIS_CERTIFICATES is one special variable we do not want relocated
relocate $REPOCONF | sed 's,^\(OASIS_CERTIFICATES\)=.[^/]*,\1=/cvmfs,'
else
relocate $REPOCONF
fi
fi
relocate $DIST/etc/cvmfs/config.d/$REPO.conf
relocate $DIST/etc/cvmfs/config.d/$REPO.local
# this is for finding an authz helper
echo CVMFS_AUTHZ_CVMFS_DIST=$DIST
) > $CONFFILE
OPTS=""
if grep -q ^CVMFS_DEBUGLOG=. $CONFFILE; then
OPTS="$OPTS,debug"
fi
mkdir -p $DIST/var/run/cvmfs
mkdir -p $DIST/cvmfs/$REPO
if [ -f $DIST/usr/lib/libcvmfs_fuse.so ]; then
LPATH=$DIST/usr/lib
LDPATH=$LPATH
if [ ! -f $LPATH/libfuse.so.2 ]; then
# for el6
LDPATH=$LPATH:$DIST/lib
fi
else
LPATH=$DIST/usr/lib64
LDPATH=$LPATH
if [ ! -f $LPATH/libfuse.so.2 ]; then
# for el6
LDPATH=$LPATH:$DIST/lib64
fi
fi
LD_LIBRARY_PATH=$LDPATH CVMFS_LIBRARY_PATH=$LPATH $DIST/usr/bin/cvmfs2 -o config=$CONFFILE$OPTS $REPO $DIST/cvmfs/$REPO