stages: 2/02-squashfs: upgraded squashfs-tools to the latest commit
[dragora.git] / enter-chroot
blob32d3c3ec8ace4b40115ea842a29ef3dcb0165642
1 #! /bin/sh -
2 # Copyright (c) 2016-2018 Matias Fonzo, <selk@dragora.org>.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 PROGRAM="${0##*/}"
18 # Exit immediately on any error
19 set -e
21 # Override locale settings
22 LC_ALL=C
23 export LC_ALL
25 # Get physical working directory, absolute path name
26 CWD=$(CDPATH= cd -P -- $(dirname -- "$0") && printf "$PWD")
28 # Functions
29 unmountSeries()
31 for node in "${rootdir}/usr/src/qi/archive" \
32 "${rootdir}/usr/src/qi/patches" \
33 "${rootdir}/usr/src/qi/recipes" \
34 "${rootdir}/usr/src/qi/sources" \
35 "${rootdir}/sys" \
36 "${rootdir}/proc" \
37 "${rootdir}/dev/pts" \
38 "${rootdir}/dev" ; \
40 if mount | grep -q "$node"
41 then
42 echo "Unmounting ${node} ..."
43 if ! umount "$node"
44 then
45 echo "Doing a lazy unmount for $node ..."
46 umount -l "$node"
49 done
52 # Autodetermine the path of /tools
54 if test ! -L /tools
55 then
56 echo "${PROGRAM}: cannot determine ${rootdir}: /tools does not exist as symlink" 1>&2
57 exit 1
59 if test -L /tools -a ! -e /tools
60 then
61 echo "${PROGRAM}: cannot access /tools: Dangling symlink" 1>&2
62 exit 1
65 # Set canonical name to compose the root directory, removing
66 # the last component from the path name "/tools"
68 rootdir=$(CDPATH= cd -P -- /tools && printf "$PWD")
69 rootdir="${rootdir%/*}"
71 # Unmount directories and file systems before the next mounting
73 unmountSeries
75 # Create required directory for destination
76 mkdir -p -- "${rootdir}/dev" \
77 "${rootdir}/dev/pts" \
78 "${rootdir}/proc" \
79 "${rootdir}/sys" \
80 "${rootdir}/usr/src/qi/archive" \
81 "${rootdir}/usr/src/qi/patches" \
82 "${rootdir}/usr/src/qi/recipes" \
83 "${rootdir}/usr/src/qi/sources"
85 echo "Mounting virtual file systems ..."
86 mount -o bind /dev "${rootdir}/dev"
87 mount -t devpts devpts "${rootdir}/dev/pts"
88 mount -t proc proc "${rootdir}/proc"
89 mount -t sysfs sysfs "${rootdir}/sys"
91 echo "Binding directories to mount: archive, patches, recipes, sources ..."
92 mount -o bind "${CWD}/archive" "${rootdir}/usr/src/qi/archive"
93 mount -o bind "${CWD}/patches" "${rootdir}/usr/src/qi/patches"
94 mount -o bind "${CWD}/recipes" "${rootdir}/usr/src/qi/recipes"
95 mount -o bind "${CWD}/sources" "${rootdir}/usr/src/qi/sources"
97 # Add trap for unmount the series, signalled or not
98 trap 'echo ; unmountSeries' EXIT HUP QUIT ABRT TERM
100 echo "Entering via chroot $rootdir ..."
101 chroot "$rootdir" /tools/bin/env -i \
102 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
103 SHELL=/bin/sh \
104 HOME=/root \
105 TERM=linux \
106 LC_ALL=C \
107 LANGUAGE=C \
108 PKG_CONFIG=/usr/bin/pkgconf \
109 PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig \
110 /bin/sh -