forked from LibreOffice/online
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loolwsd-systemplate-setup
executable file
·124 lines (101 loc) · 4.14 KB
/
loolwsd-systemplate-setup
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
#!/bin/bash
#set -x
test $# -eq 2 || { echo "Usage: $0 <chroot template directory for system libs to create> <LO installation directory>"; exit 1; }
# No provision for spaces or other weird characters in pathnames. So sue me.
CHROOT=$1
INSTDIR=$2
test -d "$INSTDIR" || { echo "No such directory: $INSTDIR"; exit 1; }
mkdir -p $CHROOT || exit 1
# Resolve the real paths, in case they are relative and/or symlinked.
# INSTDIR_LOGICAL will contain the logical path, if there are symlinks,
# while INSTDIR is the physical one. Both will most likely be the same,
# except on systems that have symlinks in the path. We must create
# both paths (if they are different) inside the jail, hence we need both.
CHROOT=`cd $CHROOT && /bin/pwd`
INSTDIR_LOGICAL=`cd $INSTDIR && /bin/pwd -L`
INSTDIR=`cd $INSTDIR && /bin/pwd -P`
cd / || exit 1
(
# Produce a list of file names, one per line, that will be copied
# into the template tree of system files for the chroot jails.
# First essential files and shared objects
find etc/ld.so.* \
lib/ld-* lib64/ld-* \
lib/libnss_* lib64/libnss_* lib/*/libnss_* \
lib/libresolv* lib64/libresolv* lib/*/libresolv* \
var/cache/fontconfig \
etc/fonts \
usr/lib/locale/en_US.utf8 \
usr/lib/locale/C.UTF-8 \
usr/lib/locale/locale_archive \
usr/lib/*/nss/*.so \
usr/lib/*/libsqlite* \
usr/share/zoneinfo/* \
usr/share/liblangtag \
usr/share/hyphen \
-type f 2>/dev/null
find etc/fonts \
lib/ld-* lib64/ld-* \
lib/libnss_* lib64/libnss_* lib/*/libnss_* \
lib/libresolv* lib64/libresolv* lib/*/libresolv* \
usr/lib/*/libsqlite* \
-type l 2>/dev/null
# Go through the LO shared objects and check what system libraries
# they link to.
find $INSTDIR -name 'xpdfimport' |
while read file; do
ldd $file 2>/dev/null
done |
grep -v dynamic | cut -d " " -f 3 | grep -E '^(/lib|/usr)' | sort -u | sed -e 's,^/,,'
) |
# Can't use -l because then symlinks won't be handled well enough.
# This will now copy the file a symlink points to, but whatever.
cpio -p -d -L $CHROOT
# Link the dynamic files, replacing any existing.
for file in hosts nsswitch.conf resolv.conf passwd group host.conf timezone localtime
do
#echo "Linking/Copying /etc/$file"
# Prefer hard-linking, fallback to just copying (do *not* use soft-linking because that would be relative to the jail).
ln -f /etc/$file $CHROOT/etc/ 2> /dev/null || cp /etc/$file $CHROOT/etc/ || echo "Failed to link or copy $file"
done
# Link dev/random and dev/urandom to ../tmp/dev/.
# The jail then creates the random device nodes in its /tmp/dev/.
mkdir -p $CHROOT/dev
mkdir -p $CHROOT/tmp/dev
for file in random urandom
do
# This link is relative anyway, so can be soft.
ln -f ../tmp/dev/$file $CHROOT/dev/ 2> /dev/null || ln -f -s ../tmp/dev/$file $CHROOT/dev/ || echo "Failed to link dev/$file"
done
# Create a relative symbolic link within systemplate that points from
# the path of $INSTDIR (as seen from the jail as an absolute path)
# to the /lo path, where the instdir of LO will really reside.
mkdir -p $CHROOT/lo
# In case the original path is different from
for path in $INSTDIR $INSTDIR_LOGICAL
do
# Create a soft-link, as it's a relative directory path (can't be a hard-link).
INSTDIR_PARENT="$(dirname "$CHROOT/$path")"
mkdir -p $INSTDIR_PARENT
ln -f -s `realpath --relative-to=$INSTDIR_PARENT $CHROOT/lo` $CHROOT/$path
done
# /usr/share/fonts needs to be taken care of separately because the
# directory time stamps must be preserved for fontconfig to trust
# its cache.
cd $CHROOT || exit 1
mkdir -p usr/share || exit 1
cp -r -p -L /usr/share/fonts usr/share
if [ -h usr/share/fonts/ghostscript ]; then
mkdir usr/share/ghostscript || exit 1
cp -r -p -L /usr/share/ghostscript/fonts usr/share/ghostscript
fi
# Remove obsolete & unused bitmap fonts
find usr/share -name '*.pcf' | xargs rm -f
find usr/share -name '*.pcf.gz' | xargs rm -f
# Debugging only hackery to avoid confusion.
if test "z$ENABLE_DEBUG" != "z" -a "z$HOME" != "z"; then
echo "Copying development users's fonts into systemplate"
mkdir -p $CHROOT/$HOME
test -d $HOME/.fonts && cp -r -p -L $HOME/.fonts $CHROOT/$HOME
fi
exit 0