1#! /bin/sh
2
3# copy files required for chrooted operation, use bind mounts to expose
4# libraries
5
6BASEDIR=/opt/aprsc
7DIRNAME=aprsc
8
9prepare_chroot () {
10	# config files
11	/bin/cp -p /etc/resolv.conf /etc/nsswitch.conf /etc/hosts /etc/gai.conf $BASEDIR/etc/
12	# live upgrade requires libraries to be visible within chroot, so
13	# set up a read-only bind mount of /lib
14	grep -q "$DIRNAME/lib " /proc/mounts || \
15		( mount --bind /lib $BASEDIR/lib \
16		&& mount -o remount,ro,bind $BASEDIR/lib )
17	if [ -e /lib64 ]; then
18		grep -q "$DIRNAME/lib64 " /proc/mounts || \
19			( mount --bind /lib64 $BASEDIR/lib64 \
20			&& mount -o remount,ro,bind $BASEDIR/lib64 )
21	fi
22	grep -q "$DIRNAME/usr/lib " /proc/mounts || \
23		( mount --bind /usr/lib $BASEDIR/usr/lib \
24		&& mount -o remount,ro,bind $BASEDIR/usr/lib )
25	if [ -e /usr/lib64 ]; then
26		grep -q "$DIRNAME/usr/lib64 " /proc/mounts || \
27			( mount --bind /usr/lib64 $BASEDIR/usr/lib64 \
28			&& mount -o remount,ro,bind $BASEDIR/usr/lib64 )
29	fi
30}
31
32prepare_chroot
33
34