minor change on etc/rc.d/rc.documents
[dragora.git] / enter-chroot
bloba14b1c2b13bee6c527effecc3aa795e9497c9a18
1 #! /bin/sh -
3 # Copyright (C) 2016, 2017 Matias Andres Fonzo <selk@dragora.org>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 PROGRAM="${0##*/}"
20 # Exit immediately on any error
21 set -e
23 # Override locale settings
24 LC_ALL=C
25 export LC_ALL
27 # Get physical working directory, absolute path name
28 CWD=$(CDPATH= cd -P -- $(dirname -- "$0") && printf "$PWD")
30 # Functions
31 unmountSeries()
33 for node in "${rootdir}/usr/src/qi/archive" \
34 "${rootdir}/usr/src/qi/patches" \
35 "${rootdir}/usr/src/qi/recipes" \
36 "${rootdir}/usr/src/qi/sources" \
37 "${rootdir}/sys" \
38 "${rootdir}/proc" \
39 "${rootdir}/dev/shm" \
40 "${rootdir}/dev/pts" \
41 "${rootdir}/dev" ; \
43 if mount | grep -q "$node"
44 then
45 echo "Unmounting ${node} ..."
46 if ! umount "$node"
47 then
48 echo "Doing a lazy unmount for $node ..."
49 umount -l "$node"
52 done
55 # Autodetermine the path of /tools
57 if test ! -L /tools
58 then
59 echo "${PROGRAM}: cannot determine ${rootdir}: /tools does not exist as symlink" 1>&2
60 exit 1
62 if test -L /tools -a ! -e /tools
63 then
64 echo "${PROGRAM}: cannot access /tools: Dangling symlink" 1>&2
65 exit 1
68 # Set canonical name to compose the root directory, removing
69 # the last component from the path name "/tools"
71 rootdir=$(CDPATH= cd -P -- /tools && printf "$PWD")
72 rootdir="${rootdir%/*}"
74 # Unmount directories and file systems before the next mounting
76 unmountSeries
78 # Create required directory for destination
79 mkdir -p -- "${rootdir}/dev" \
80 "${rootdir}/dev/pts" \
81 "${rootdir}/dev/shm" \
82 "${rootdir}/proc" \
83 "${rootdir}/sys" \
84 "${rootdir}/usr/src/qi/archive" \
85 "${rootdir}/usr/src/qi/patches" \
86 "${rootdir}/usr/src/qi/recipes" \
87 "${rootdir}/usr/src/qi/sources"
89 echo "Mounting virtual file systems ..."
90 mount -o bind /dev "${rootdir}/dev"
91 mount -t devpts devpts "${rootdir}/dev/pts"
92 mount -t proc proc "${rootdir}/proc"
93 mount -t sysfs sysfs "${rootdir}/sys"
95 if test -L /run/shm
96 then
97 mount -o bind "$(readlink /run/shm)" "${rootdir}/dev/shm" || true
98 else
99 mount -o bind /dev/shm "${rootdir}/dev/shm" || true
102 echo "Binding directories to mount: archive, patches, recipes, sources ..."
103 mount -o bind "${CWD}/archive" "${rootdir}/usr/src/qi/archive"
104 mount -o bind "${CWD}/patches" "${rootdir}/usr/src/qi/patches"
105 mount -o bind "${CWD}/recipes" "${rootdir}/usr/src/qi/recipes"
106 mount -o bind "${CWD}/sources" "${rootdir}/usr/src/qi/sources"
108 # Add trap for unmount the series, signalled or not
109 trap 'echo ; unmountSeries' EXIT HUP QUIT ABRT TERM
111 echo "Entering via chroot $rootdir ..."
112 chroot "$rootdir" /tools/bin/env -i \
113 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
114 SHELL=/bin/sh \
115 HOME=/root \
116 TERM="${TERM:-linux}" \
117 LC_ALL=C \
118 LANGUAGE=C \
119 PKG_CONFIG=/usr/bin/pkgconf \
120 PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig \
121 /bin/sh -