2 # Copyright (c) 2016-2018 Matias Fonzo, <selk@dragora.org>.
3 # Copyright (c) 2020-2022 Matias Fonzo, <selk@dragora.org>.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 # Exit immediately on any error
22 # Override locale settings
26 # Get physical working directory (absolute path)
27 CWD
="$(CDPATH='' cd -P -- "$
(dirname -- "$0")" && pwd -P)" ||
exit $?
32 for node
in "${rootdir}/usr/src/qi/archive" \
33 "${rootdir}/usr/src/qi/patches" \
34 "${rootdir}/usr/src/qi/recipes" \
35 "${rootdir}/usr/src/qi/sources" \
36 "${rootdir}/var/cache/qi/packages" \
39 "${rootdir}/dev/pts" \
40 "${rootdir}/dev/shm" \
43 if mount |
grep -q "$node"
45 echo "Unmounting ${node} ..."
48 echo "Doing a lazy unmount for $node ..."
56 # Autodetermine the path of /tools
60 echo "${PROGRAM}: cannot determine ${rootdir}: /tools does not exist as symlink" 1>&2
63 if test -L /tools
&& test ! -e /tools
65 echo "${PROGRAM}: cannot access /tools: Dangling symlink" 1>&2
69 # Set canonical name to compose the root directory, removing
70 # the last component from the path name "/tools"
72 rootdir
="$(CDPATH='' cd -P -- /tools && pwd -P)"
73 rootdir
="${rootdir%/*}"
75 # Unmount directories and file systems before the next mounting
79 # Create required directory for destination
82 "${rootdir}/dev/pts" \
83 "${rootdir}/dev/shm" \
86 "${rootdir}/usr/src/qi/archive" \
87 "${rootdir}/usr/src/qi/patches" \
88 "${rootdir}/usr/src/qi/recipes" \
89 "${rootdir}/usr/src/qi/sources" \
90 "${rootdir}/var/cache/qi/packages"
92 echo "Mounting virtual file systems ..."
93 mount
-o bind /dev
"${rootdir}/dev"
94 mount
-t devpts devpts
"${rootdir}/dev/pts"
95 mount
-t tmpfs devshm
"${rootdir}/dev/shm"
96 mount
-t proc proc
"${rootdir}/proc"
97 mount
-t sysfs sysfs
"${rootdir}/sys"
99 echo "Binding directories for archive/, patches/, recipes/, sources/, and packages/ ..."
100 mount
-o bind "${CWD}/archive" "${rootdir}/usr/src/qi/archive"
101 mount
-o bind "${CWD}/patches" "${rootdir}/usr/src/qi/patches"
102 mount
-o bind "${CWD}/recipes" "${rootdir}/usr/src/qi/recipes"
103 mount
-o bind "${CWD}/sources" "${rootdir}/usr/src/qi/sources"
104 mount
-o bind "${CWD}/packages" "${rootdir}/var/cache/qi/packages"
106 # Change reported architecture for an appropriate environment
109 if file /tools
/bin
/busybox |
grep -q "32-bit"
111 echo "Using the linux32 command to change the reported architecure ..."
112 if command -v linux32
> /dev
/null
114 _machine_type
="linux32"
116 echo " The linux32 command is not available in your system." 1>&2
117 echo "The current architecture will be used for the environment: $(uname -m)" 1>&2
121 # Add trap for unmount the series, signalled or not
122 trap 'echo ""; unmountSeries' EXIT HUP QUIT ABRT TERM
124 echo "Entering via chroot $rootdir ..."
125 $_machine_type chroot
"$rootdir" /tools
/bin
/env
-i \
126 PATH
=/bin
:/usr
/bin
:/sbin
:/usr
/sbin
:/tools
/bin
:/opt
/trinity
/bin \
132 PKG_CONFIG
=/usr
/bin
/pkgconf \
133 PKG_CONFIG_PATH
=/usr
/local
/lib
/pkgconfig
:/usr
/local
/share
/pkgconfig
:/usr
/lib
/pkgconfig
:/usr
/share
/pkgconfig
:/opt
/trinity
/lib
/pkgconfig \