Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(866)

Unified Diff: src/scripts/dpkg_no_scripts.sh

Issue 517004: Add a helper script to be able to run "apt-get install" without running (Closed)
Patch Set: Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scripts/dpkg_no_scripts.sh
diff --git a/src/scripts/dpkg_no_scripts.sh b/src/scripts/dpkg_no_scripts.sh
new file mode 100755
index 0000000000000000000000000000000000000000..fe5a817a8141431f26c821590e1721c82abc5535
--- /dev/null
+++ b/src/scripts/dpkg_no_scripts.sh
@@ -0,0 +1,83 @@
+#!/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 auto_deconfigure $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}
+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_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
+
+ # 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698