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/>.
20 # Exit immediately on any error
23 # Override locale settings
27 # Get physical working directory, absolute path name
28 CWD
=$
(CDPATH
= cd -P -- $
(dirname -- "$0") && printf "$PWD")
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" \
39 "${rootdir}/dev/shm" \
40 "${rootdir}/dev/pts" \
43 if mount |
grep -q "$node"
45 echo "Unmounting ${node} ..."
48 echo "Doing a lazy unmount for $node ..."
55 # Autodetermine the path of /tools
59 echo "${PROGRAM}: cannot determine ${rootdir}: /tools does not exist as symlink" 1>&2
62 if test -L /tools
-a ! -e /tools
64 echo "${PROGRAM}: cannot access /tools: Dangling symlink" 1>&2
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
78 # Create required directory for destination
79 mkdir
-p -- "${rootdir}/dev" \
80 "${rootdir}/dev/pts" \
81 "${rootdir}/dev/shm" \
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"
97 mount
-o bind "$(readlink /run/shm)" "${rootdir}/dev/shm" || true
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 \
116 TERM
="${TERM:-linux}" \
119 PKG_CONFIG
=/usr
/bin
/pkgconf \
120 PKG_CONFIG_PATH
=/usr
/local
/lib
/pkgconfig
:/usr
/local
/share
/pkgconfig
:/usr
/lib
/pkgconfig
:/usr
/share
/pkgconfig \