recipes: tools/parted: Added version 3.5
[dragora.git] / enter-chroot
blob7c75cc928bc1d6d0417ac1a1356337890195a6c9
1 #! /bin/sh -
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.
17 PROGRAM="${0##*/}"
19 # Exit immediately on any error
20 set -e
22 # Override locale settings
23 LC_ALL=C
24 export LC_ALL
26 # Get physical working directory (absolute path)
27 CWD="$(CDPATH='' cd -P -- "$(dirname -- "$0")" && pwd -P)" || exit $?
29 # Functions
30 unmountSeries()
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" \
37 "${rootdir}/sys" \
38 "${rootdir}/proc" \
39 "${rootdir}/dev/pts" \
40 "${rootdir}/dev" ; \
42 if mount | grep -q "$node"
43 then
44 echo "Unmounting ${node} ..."
45 if ! umount "$node"
46 then
47 echo "Doing a lazy unmount for $node ..."
48 umount -l "$node"
51 done
52 unset -v node
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 && pwd -P)"
72 rootdir="${rootdir%/*}"
74 # Unmount directories and file systems before the next mounting
76 unmountSeries
78 # Create required directory for destination
79 mkdir -p -- \
80 "${rootdir}/dev" \
81 "${rootdir}/dev/pts" \
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" \
88 "${rootdir}/var/cache/qi/packages"
90 echo "Mounting virtual file systems ..."
91 mount -o bind /dev "${rootdir}/dev"
92 mount -t devpts devpts "${rootdir}/dev/pts"
93 mount -t proc proc "${rootdir}/proc"
94 mount -t sysfs sysfs "${rootdir}/sys"
96 echo "Binding directories for archive/, patches/, recipes/, sources/, and packages/ ..."
97 mount -o bind "${CWD}/archive" "${rootdir}/usr/src/qi/archive"
98 mount -o bind "${CWD}/patches" "${rootdir}/usr/src/qi/patches"
99 mount -o bind "${CWD}/recipes" "${rootdir}/usr/src/qi/recipes"
100 mount -o bind "${CWD}/sources" "${rootdir}/usr/src/qi/sources"
101 mount -o bind "${CWD}/packages" "${rootdir}/var/cache/qi/packages"
103 # Change reported architecture for an appropriate environment
104 _machine_type=""
106 if file /tools/bin/busybox | grep -q "32-bit"
107 then
108 echo "Using the linux32 command to change the reported architecure ..."
109 if command -v linux32 > /dev/null
110 then
111 _machine_type="linux32"
112 else
113 echo " The linux32 command is not available in your system." 1>&2
114 echo "The current architecture will be used for the environment: $(uname -m)" 1>&2
118 # Add trap for unmount the series, signalled or not
119 trap 'echo ""; unmountSeries' EXIT HUP QUIT ABRT TERM
121 echo "Entering via chroot $rootdir ..."
122 $_machine_type chroot "$rootdir" /tools/bin/env -i \
123 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin:/opt/trinity/bin \
124 SHELL=/bin/sh \
125 HOME=/root \
126 TERM=linux \
127 HOSTNAME=dragora \
128 LC_ALL=C \
129 PKG_CONFIG=/usr/bin/pkgconf \
130 PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig:/opt/trinity/lib/pkgconfig \
131 /bin/sh -