Skip to content

Commit 5bf3d8a

Browse files
committed
feat(pack-images): multi process dpkg
1 parent 3635192 commit 5bf3d8a

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

rootfs/usr/local/bin/apt-utils.sh

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,39 @@ apt-clean() {
2424
apt-get $APT_OPTIONS clean
2525
}
2626

27-
apt-install() {
27+
dpkg-install() {
28+
DEB_URL="$1"
2829
APT_INSTALL_DIR="${APT_INSTALL_DIR:?APT_INSTALL_DIR is required}"
30+
DEB_FILE="${APT_CACHE_DIR}"/$(echo "$DEB_URL" | awk -F "/" '{print $NF}')
31+
if [[ ! -f "${DEB_FILE}" ]] ; then
32+
curl -fsSL -o "${DEB_FILE}" "${DEB_URL}"
33+
fi
34+
readonly control_dir=$(mktemp -d)
35+
dpkg -e "${DEB_FILE}" "${control_dir}"
36+
if [[ -f "${control_dir}"/preinst ]] ; then
37+
sed -i "s#/usr/lib/#$APT_INSTALL_DIR/usr/lib/#g" "${control_dir}"/preinst
38+
"${control_dir}"/preinst install 2>/dev/null || echo "skip exec ${DEB_FILE} postinst"
39+
fi
40+
dpkg -x "${DEB_FILE}" "$APT_INSTALL_DIR"
41+
if [[ -f "${control_dir}"/postinst ]] ; then
42+
sed -i "s#/usr/lib/#$APT_INSTALL_DIR/usr/lib/#g" "${control_dir}"/postinst
43+
"${control_dir}"/postinst configure 2>/dev/null || echo "skip exec ${DEB_FILE} postinst"
44+
fi
45+
rm -rf "${control_dir}"
46+
47+
pkgconfig_list=$(find "$APT_INSTALL_DIR"/usr/lib/*-linux-gnu/pkgconfig/*.pc 2>/dev/null || echo "")
48+
for pkgconfig in ${pkgconfig_list}
49+
do
50+
sed -i "s#/usr/lib/#$APT_INSTALL_DIR/usr/lib/#g" "${pkgconfig}"
51+
sed -i "s#/usr/include/#$APT_INSTALL_DIR/usr/include/#g" "${pkgconfig}"
52+
done
53+
}
54+
55+
apt-install() {
2956
# shellcheck disable=SC2086
3057
for DEB_URL in $(apt-get $APT_OPTIONS install --print-uris -qq "$@" | cut -d"'" -f2)
3158
do
32-
DEB_FILE="${APT_CACHE_DIR}"/$(echo "$DEB_URL" | awk -F "/" '{print $NF}')
33-
if [[ ! -f "${DEB_FILE}" ]] ; then
34-
curl -fsSL -o "${DEB_FILE}" "${DEB_URL}"
35-
fi
36-
dpkg -e "${DEB_FILE}" "$APT_INSTALL_DIR"/DEBIAN
37-
if [[ -f "$APT_INSTALL_DIR"/DEBIAN/preinst ]] ; then
38-
sed -i "s#/usr/lib/#$APT_INSTALL_DIR/usr/lib/#g" "$APT_INSTALL_DIR"/DEBIAN/preinst
39-
"$APT_INSTALL_DIR"/DEBIAN/preinst install 2>/dev/null || echo "skip exec ${DEB_FILE} postinst"
40-
fi
41-
dpkg -x "${DEB_FILE}" "$APT_INSTALL_DIR"
42-
if [[ -f "$APT_INSTALL_DIR"/DEBIAN/postinst ]] ; then
43-
sed -i "s#/usr/lib/#$APT_INSTALL_DIR/usr/lib/#g" "$APT_INSTALL_DIR"/DEBIAN/postinst
44-
"$APT_INSTALL_DIR"/DEBIAN/postinst configure 2>/dev/null || echo "skip exec ${DEB_FILE} postinst"
45-
fi
46-
rm -rf "$APT_INSTALL_DIR"/DEBIAN
47-
48-
pkgconfig_list=$(find "$APT_INSTALL_DIR"/usr/lib/*-linux-gnu/pkgconfig/*.pc 2>/dev/null || echo "")
49-
for pkgconfig in ${pkgconfig_list}
50-
do
51-
sed -i "s#/usr/lib/#$APT_INSTALL_DIR/usr/lib/#g" "${pkgconfig}"
52-
sed -i "s#/usr/include/#$APT_INSTALL_DIR/usr/include/#g" "${pkgconfig}"
53-
done
59+
dpkg-install "${DEB_URL}" &
5460
done
61+
wait
5562
}

0 commit comments

Comments
 (0)