compressors/xlunzip: Upgraded to version 0.6
[dragora.git] / enter-chroot
blob6319b2ed66dd4e747e49564d68bdf7d0cde8879d
1 #! /bin/sh -
2 # Copyright (c) 2016-2018 Matias Fonzo, <selk@dragora.org>.
3 # Copyright (c) 2020 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 current working directory
27 CWD="$(dirname -- "$0")"
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}/sys" \
37 "${rootdir}/proc" \
38 "${rootdir}/dev/pts" \
39 "${rootdir}/dev" ; \
41 if mount | grep -q "$node"
42 then
43 echo "Unmounting ${node} ..."
44 if ! umount "$node"
45 then
46 echo "Doing a lazy unmount for $node ..."
47 umount -l "$node"
50 done
51 unset node
54 # Autodetermine the path of /tools
56 if test ! -L /tools
57 then
58 echo "${PROGRAM}: cannot determine ${rootdir}: /tools does not exist as symlink" 1>&2
59 exit 1
61 if test -L /tools -a ! -e /tools
62 then
63 echo "${PROGRAM}: cannot access /tools: Dangling symlink" 1>&2
64 exit 1
67 # Set canonical name to compose the root directory, removing
68 # the last component from the path name "/tools"
70 rootdir="$(CDPATH='' cd -P -- /tools && pwd -P)"
71 rootdir="${rootdir%/*}"
73 # Unmount directories and file systems before the next mounting
75 unmountSeries
77 # Create required directory for destination
78 mkdir -p -- "${rootdir}/dev" \
79 "${rootdir}/dev/pts" \
80 "${rootdir}/proc" \
81 "${rootdir}/sys" \
82 "${rootdir}/usr/src/qi/archive" \
83 "${rootdir}/usr/src/qi/patches" \
84 "${rootdir}/usr/src/qi/recipes" \
85 "${rootdir}/usr/src/qi/sources"
87 echo "Mounting virtual file systems ..."
88 mount -o bind /dev "${rootdir}/dev"
89 mount -t devpts devpts "${rootdir}/dev/pts"
90 mount -t proc proc "${rootdir}/proc"
91 mount -t sysfs sysfs "${rootdir}/sys"
93 echo "Binding directories to mount: archive, patches, recipes, sources ..."
94 mount -o bind "${CWD}/archive" "${rootdir}/usr/src/qi/archive"
95 mount -o bind "${CWD}/patches" "${rootdir}/usr/src/qi/patches"
96 mount -o bind "${CWD}/recipes" "${rootdir}/usr/src/qi/recipes"
97 mount -o bind "${CWD}/sources" "${rootdir}/usr/src/qi/sources"
99 # Change reported architecture for an appropriate environment
100 _machine_type=""
102 if file /tools/bin/busybox | grep -q "32-bit"
103 then
104 echo "Using the linux32 command for this machine type: $(uname -m) ..."
105 if command -v linux32 > /dev/null
106 then
107 _machine_type="linux32"
108 else
109 echo " The linux32 command is not available on your system." 1>&2
113 # Add trap for unmount the series, signalled or not
114 trap 'echo ""; unmountSeries' EXIT HUP QUIT ABRT TERM
116 echo "Entering via chroot $rootdir ..."
117 $_machine_type chroot "$rootdir" /tools/bin/env -i \
118 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin:/opt/trinity/bin \
119 SHELL=/bin/sh \
120 HOME=/root \
121 TERM=linux \
122 HOSTNAME=dragora \
123 LC_ALL=C \
124 PKG_CONFIG=/usr/bin/pkgconf \
125 PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig:/opt/trinity/lib/pkgconfig \
126 QTDIR=/opt/trinity/lib/tqt3 \
127 /bin/sh -