summaryrefslogtreecommitdiff
path: root/multistrap/selfstrap
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2017-08-30 20:20:27 -0400
committerAndrew Cady <d@jerkface.net>2017-08-30 20:21:32 -0400
commita39c3c4520ecea31cf85d31741275657268a8cc8 (patch)
tree4aa8cad86fb5e836b164ea30247de630cf98832b /multistrap/selfstrap
parent7392932128db786fe915e8ef432953fbf55bc0f2 (diff)
selfstrap: substantially improve performance
Diffstat (limited to 'multistrap/selfstrap')
-rwxr-xr-xmultistrap/selfstrap41
1 files changed, 21 insertions, 20 deletions
diff --git a/multistrap/selfstrap b/multistrap/selfstrap
index 265049b..88dc07e 100755
--- a/multistrap/selfstrap
+++ b/multistrap/selfstrap
@@ -124,7 +124,7 @@ parse_apt_noact_line()
124 return 1 124 return 1
125} 125}
126 126
127extract_dpkg_info() 127dpkg_extract_with_info()
128{ 128{
129 local deb="$1" TARGET="$2" multiarch="$3" command PKG 129 local deb="$1" TARGET="$2" multiarch="$3" command PKG
130 PKG=${deb##*/} 130 PKG=${deb##*/}
@@ -137,9 +137,10 @@ f=$TARGET/var/lib/dpkg/info/$PKG.${TAR_FILENAME#./}
137cat > "$f" 137cat > "$f"
138chmod $TAR_MODE "$f" 138chmod $TAR_MODE "$f"
139' 139'
140 (export PKG TARGET 140 (export PKG TARGET; dpkg --ctrl-tarfile "$deb" | tar -x --to-command "$command")
141 dpkg --ctrl-tarfile "$deb" | tar -x --to-command "$command") 141 dpkg --fsys-tarfile "$deb" |
142 dpkg --fsys-tarfile "$deb" | tar -t | sed 's?^\.??; s?^/$?/.?; s?/$??' > "$TARGET/var/lib/dpkg/info/$PKG.list" 142 (cd "$TARGET" && tar -xv) |
143 sed 's?^\.??; s?^/$?/.?; s?/$??' > "$TARGET/var/lib/dpkg/info/$PKG.list"
143 144
144} 145}
145 146
@@ -148,11 +149,7 @@ apt_run_inst()
148 apt_get -s -yqq install "$@" | while read line; do 149 apt_get -s -yqq install "$@" | while read line; do
149 parse_apt_noact_line "$line" || die "unexpected output from apt-get: $line" 150 parse_apt_noact_line "$line" || die "unexpected output from apt-get: $line"
150 export DPKG_MAINTSCRIPT_PACKAGE="$package" DPKG_MAINTSCRIPT_ARCH="$arch" 151 export DPKG_MAINTSCRIPT_PACKAGE="$package" DPKG_MAINTSCRIPT_ARCH="$arch"
151 if is_multiarch_same "$package"; then 152 is_multiarch_same "$package" && multiarch=":$arch" || multiarch=
152 multiarch=":$arch"
153 else
154 multiarch=
155 fi
156 case "$action" in 153 case "$action" in
157 Inst) 154 Inst)
158 export DPKG_MAINTSCRIPT_NAME=preinst 155 export DPKG_MAINTSCRIPT_NAME=preinst
@@ -189,11 +186,12 @@ apt_extract()
189 case "$action" in 186 case "$action" in
190 Inst) 187 Inst)
191 printf 'Extracting %s\n' "${deb##*/}" >&2 188 printf 'Extracting %s\n' "${deb##*/}" >&2
192 dpkg-deb --extract "$deb" "$rootfs"
193 189
194 if [ "$EXTRACT_DPKG_INFO" ]; then 190 if [ "$EXTRACT_DPKG_INFO" ]; then
195 is_multiarch_same "$package" && multiarch=":$arch" || multiarch= 191 is_multiarch_same "$package" && multiarch=":$arch" || multiarch=
196 extract_dpkg_info "$deb" "$rootfs" "$multiarch" 192 dpkg_extract_with_info "$deb" "$rootfs" "$multiarch"
193 else
194 dpkg-deb --extract "$deb" "$rootfs"
197 fi 195 fi
198 ;; 196 ;;
199 Conf) 197 Conf)
@@ -227,13 +225,19 @@ required_packages()
227 "$(main_packages_file)" | sort -u 225 "$(main_packages_file)" | sort -u
228} 226}
229 227
230multiarch_same_packages() 228declare -A is_multiarch_same
229multicheck()
231{ 230{
232 [ "$multiarch_same_packages" ] || multiarch_same_packages=$(multiarch_same_packages_) 231 local m
233 echo "$multiarch_same_packages" 232 if [ ! "$multichecked" ]; then
233 for m in $(multiarch_same_packages); do
234 is_multiarch_same[$m]=y
235 done
236 fi
237 multichecked=y
234} 238}
235 239
236multiarch_same_packages_() 240multiarch_same_packages()
237{ 241{
238 perl -00 -ne \ 242 perl -00 -ne \
239 '/^Multi-Arch: same/mi || next; /^Package: (.*)$/m && print "$1\n"' \ 243 '/^Multi-Arch: same/mi || next; /^Package: (.*)$/m && print "$1\n"' \
@@ -242,11 +246,8 @@ multiarch_same_packages_()
242 246
243is_multiarch_same() 247is_multiarch_same()
244{ 248{
245 local p 249 multicheck
246 for p in $(multiarch_same_packages); do 250 [ "${is_multiarch_same[$1]}" ]
247 [ "$1" = "$p" ] && return
248 done
249 return 1
250} 251}
251 252
252set -e 253set -e