4
by Colin Watson
* Resynchronise with Debian. |
1 |
#!/bin/sh -e
|
2 |
# Setup for using apt to install packages in /target.
|
|
3 |
||
4 |
mountpoints () { |
|
5 |
cut -d" " -f2 /proc/mounts | sort | uniq |
|
6 |
}
|
|
7 |
||
8 |
chroot_setup () { |
|
17
by Colin Watson
* Resynchronise with Debian. Remaining changes: |
9 |
# Bail out if directories we need are not there
|
10 |
if [ ! -d /target/sbin ] || [ ! -d /target/usr/sbin ] || \ |
|
11 |
[ ! -d /target/proc ]; then |
|
12 |
return 1 |
|
13 |
fi
|
|
14 |
case $(uname -r | cut -d . -f 1,2) in |
|
15 |
2.6) |
|
16 |
if [ ! -d /target/sys ] ; then |
|
17 |
return 1 |
|
18 |
fi
|
|
19 |
;;
|
|
20 |
esac
|
|
21 |
||
13
by Colin Watson
Resynchronise with Debian. |
22 |
if [ -e /var/run/chroot-setup.lock ]; then |
23 |
cat >&2 <<EOF |
|
24 |
apt-install or in-target is already running, so you cannot run either of
|
|
25 |
them again until the other instance finishes. You may be able to use
|
|
26 |
'chroot /target ...' instead.
|
|
27 |
EOF
|
|
17
by Colin Watson
* Resynchronise with Debian. Remaining changes: |
28 |
return 1 |
13
by Colin Watson
Resynchronise with Debian. |
29 |
fi
|
30 |
touch /var/run/chroot-setup.lock |
|
31 |
||
4
by Colin Watson
* Resynchronise with Debian. |
32 |
# Create a policy-rc.d to stop maintainer scripts using invoke-rc.d
|
33 |
# from running init scripts. In case of maintainer scripts that don't
|
|
34 |
# use invoke-rc.d, add a dummy start-stop-daemon.
|
|
35 |
cat > /target/usr/sbin/policy-rc.d <<EOF
|
|
36 |
#!/bin/sh
|
|
37 |
exit 101
|
|
38 |
EOF
|
|
39 |
chmod a+rx /target/usr/sbin/policy-rc.d |
|
40 |
||
41 |
if [ -e /target/sbin/start-stop-daemon ]; then |
|
42 |
mv /target/sbin/start-stop-daemon /target/sbin/start-stop-daemon.REAL |
|
43 |
fi
|
|
44 |
cat > /target/sbin/start-stop-daemon <<EOF
|
|
45 |
#!/bin/sh
|
|
46 |
echo 1>&2
|
|
47 |
echo 'Warning: Fake start-stop-daemon called, doing nothing.' 1>&2
|
|
48 |
exit 0
|
|
49 |
EOF
|
|
50 |
chmod a+rx /target/sbin/start-stop-daemon |
|
51 |
||
52 |
# Record the current mounts
|
|
53 |
mountpoints > /tmp/mount.pre |
|
54 |
||
55 |
# Some packages (eg. the kernel-image package) require a mounted
|
|
56 |
# /proc/. Only mount it if not mounted already
|
|
57 |
if [ ! -f /target/proc/cmdline ] ; then |
|
58 |
mount -t proc proc /target/proc |
|
59 |
fi
|
|
60 |
||
61 |
# For installing >=2.6.14 kernels we also need sysfs mounted
|
|
62 |
# Only mount it if not mounted already and we're running 2.6
|
|
63 |
case $(uname -r | cut -d . -f 1,2) in |
|
17
by Colin Watson
* Resynchronise with Debian. Remaining changes: |
64 |
2.6) |
4
by Colin Watson
* Resynchronise with Debian. |
65 |
if [ ! -d /target/sys/devices ] ; then |
66 |
mount -t sysfs none /target/sys |
|
67 |
fi
|
|
17
by Colin Watson
* Resynchronise with Debian. Remaining changes: |
68 |
;;
|
4
by Colin Watson
* Resynchronise with Debian. |
69 |
esac
|
5
by Colin Watson
* Resynchronise with Debian. |
70 |
|
4
by Colin Watson
* Resynchronise with Debian. |
71 |
# Try to enable proxy when using HTTP.
|
72 |
# What about using ftp_proxy for FTP sources?
|
|
73 |
RET=$(debconf-get mirror/protocol || true) |
|
74 |
if [ "$RET" = "http" ]; then |
|
75 |
RET=$(debconf-get mirror/http/proxy || true) |
|
76 |
if [ "$RET" ] ; then |
|
77 |
http_proxy="$RET" |
|
78 |
export http_proxy
|
|
79 |
fi
|
|
80 |
fi
|
|
5
by Colin Watson
* Resynchronise with Debian. |
81 |
|
4
by Colin Watson
* Resynchronise with Debian. |
82 |
# Pass debconf priority through.
|
83 |
DEBIAN_PRIORITY=$(debconf-get debconf/priority || true) |
|
84 |
export DEBIAN_PRIORITY
|
|
85 |
||
5
by Colin Watson
* Resynchronise with Debian. |
86 |
LANG=$(debconf-get debian-installer/locale || true) |
87 |
export LANG
|
|
12
by Colin Watson
Resynchronise with Debian. |
88 |
export PERL_BADLANG=0 |
5
by Colin Watson
* Resynchronise with Debian. |
89 |
|
4
by Colin Watson
* Resynchronise with Debian. |
90 |
# Unset variables that would make scripts in the target think
|
91 |
# that debconf is already running there.
|
|
92 |
unset DEBIAN_HAS_FRONTEND
|
|
93 |
unset DEBIAN_FRONTEND
|
|
94 |
unset DEBCONF_FRONTEND
|
|
95 |
unset DEBCONF_REDIR
|
|
96 |
# Avoid debconf mailing notes.
|
|
97 |
DEBCONF_ADMIN_EMAIL="" |
|
98 |
export DEBCONF_ADMIN_EMAIL
|
|
17
by Colin Watson
* Resynchronise with Debian. Remaining changes: |
99 |
|
100 |
return 0 |
|
4
by Colin Watson
* Resynchronise with Debian. |
101 |
}
|
102 |
||
103 |
chroot_cleanup () { |
|
104 |
rm -f /target/usr/sbin/policy-rc.d |
|
105 |
mv /target/sbin/start-stop-daemon.REAL /target/sbin/start-stop-daemon |
|
106 |
||
107 |
# Undo the mounts done by the packages during installation.
|
|
108 |
# Reverse sorting to umount the deepest mount points first.
|
|
109 |
# Items with count of 1 are new.
|
|
110 |
for dir in $( (cat /tmp/mount.pre /tmp/mount.pre; mountpoints ) | \ |
|
12
by Colin Watson
Resynchronise with Debian. |
111 |
sort -r | uniq -c | grep "^[[:space:]]*1[[:space:]]" | \ |
112 |
sed "s/^[[:space:]]*[0-9][[:space:]]//"); do |
|
4
by Colin Watson
* Resynchronise with Debian. |
113 |
if ! umount $dir ; then |
114 |
logger -t $0 "warning: Unable to umount '$dir'" |
|
115 |
fi
|
|
116 |
done
|
|
117 |
rm -f /tmp/mount.pre |
|
13
by Colin Watson
Resynchronise with Debian. |
118 |
|
119 |
rm -f /var/run/chroot-setup.lock |
|
4
by Colin Watson
* Resynchronise with Debian. |
120 |
}
|