flatcar-scripts/dpkg_no_scripts.sh
tedbo ccd326b84d Changes to install_packages.sh so that we can master an image without
running maintainer scripts.

This is a work-in-progress. If you build_image like:

EXPERIMENTAL_NO_DEBOOTSTRAP=1 ./build_image.sh

it will skip debootstrap and install the base required packages
without running maintainer scripts. This is about 68 packages that
have lots of interleaved dependencies so it is nasty to trim down.

If you build like:

EXPERIMENTAL_NO_MAINTAINER_SCRIPTS=1 ./build_image.sh

it will install all packages skipping maintainer scripts.

Using these we can try and get things in a state where we can
create an image built of cross-compiled packages.

This is obviously not finished but in this case I prefer to commit
early so others can poke at it.

Review URL: http://codereview.chromium.org/527015
2010-01-06 18:23:50 -08:00

95 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This script can be used to replace the "dpkg" binary as far as the
# "apt-get install" command is concerned. When "apt-get install foo"
# runs it will make two calls to dpkg like:
# dpkg --status-fd ## --unpack --auto-deconfigure /path/to/foo.deb
# dpkg --status-fd ## --configure foo
# This script will extract the .deb file and make it appear to be installed
# successfully. It will skip the maintainer scripts and configure steps.
#
# As a one-off test, you can run like:
# apt-get -o="Dir::Bin::dpkg=/path/to/this" install foo
# Load common constants. This should be the first executable line.
# The path to common.sh should be relative to your script's location.
. "$(dirname "$0")/common.sh"
# Flags
DEFINE_string root "" \
"The target rootfs directory in which to install packages."
DEFINE_string status_fd "" \
"The file descriptor to report status on; ignored."
DEFINE_boolean unpack $FLAGS_FALSE "Is the action 'unpack'?"
DEFINE_boolean configure $FLAGS_FALSE "Is the action 'configure'?"
DEFINE_boolean remove $FLAGS_FALSE "Is the action 'remove'?"
DEFINE_boolean auto_deconfigure $FLAGS_FALSE "Ignored"
DEFINE_boolean force_depends $FLAGS_FALSE "Ignored"
DEFINE_boolean force_remove_essential $FLAGS_FALSE "Ignored"
# Fix up the command line and parse with shflags.
FIXED_FLAGS="$@"
FIXED_FLAGS=${FIXED_FLAGS/status-fd/status_fd}
FIXED_FLAGS=${FIXED_FLAGS/auto-deconfigure/auto_deconfigure}
FIXED_FLAGS=${FIXED_FLAGS/force-depends/force_depends}
FIXED_FLAGS=${FIXED_FLAGS/force-remove-essential/force_remove_essential}
FLAGS $FIXED_FLAGS || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on any errors.
set -e
if [ $FLAGS_configure -eq $FLAGS_TRUE ]; then
# We ignore configure requests.
exit 0
fi
if [ $FLAGS_remove -eq $FLAGS_TRUE ]; then
# We log but ignore remove requests.
echo "dpkg_no_scripts, remove: $@"
exit 0
fi
if [ $FLAGS_unpack -ne $FLAGS_TRUE ]; then
# Ignore unknown command line.
echo "Unexpected command line: $@"
exit 0
fi
if [ -z "$FLAGS_root" ]; then
echo "Missing root directory."
exit 0
fi
DPKG_STATUS=""
if [ -d "$FLAGS_root/var/lib/dpkg" ]; then
DPKG_STATUS="$FLAGS_root/var/lib/dpkg/status"
DPKG_INFO="$FLAGS_root/var/lib/dpkg/info/"
fi
for p in "$@"; do
echo "Extracting $p"
dpkg-deb --extract "$p" "$FLAGS_root"
if [ -n "$DPKG_STATUS" ]; then
TMPDIR=$(mktemp -d)
dpkg-deb --control "$p" "$TMPDIR"
# Copy the info files
PACKAGE=$(dpkg-deb --field "$p" Package)
FILES=$(ls "$TMPDIR" | grep -v control)
for f in $FILES; do
cp "${TMPDIR}/$f" "${DPKG_INFO}/$PACKAGE.$f"
done
touch "${DPKG_INFO}/$PACKAGE.list"
# Mark the package as installed successfully.
echo "Status: install ok installed" >> "$DPKG_STATUS"
cat "${TMPDIR}/control" >> "$DPKG_STATUS"
echo "" >> "$DPKG_STATUS"
rm -rf "$TMPDIR"
fi
done