| OLD | NEW |
| (Empty) |
| 1 #!/bin/bash | |
| 2 | |
| 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 # This script can be used to replace the "dpkg" binary as far as the | |
| 8 # "apt-get install" command is concerned. When "apt-get install foo" | |
| 9 # runs it will make two calls to dpkg like: | |
| 10 # dpkg --status-fd ## --unpack --auto-deconfigure /path/to/foo.deb | |
| 11 # dpkg --status-fd ## --configure foo | |
| 12 # This script will extract the .deb file and make it appear to be installed | |
| 13 # successfully. It will skip the maintainer scripts and configure steps. | |
| 14 # | |
| 15 # As a one-off test, you can run like: | |
| 16 # apt-get -o="Dir::Bin::dpkg=/path/to/this" install foo | |
| 17 | |
| 18 # Load common constants. This should be the first executable line. | |
| 19 # The path to common.sh should be relative to your script's location. | |
| 20 . "$(dirname "$0")/common.sh" | |
| 21 | |
| 22 # Flags | |
| 23 DEFINE_string root "" \ | |
| 24 "The target rootfs directory in which to install packages." | |
| 25 DEFINE_boolean dpkg_fallback $FLAGS_TRUE \ | |
| 26 "Run normal dpkg if maintainer scripts are not whitelisted." | |
| 27 DEFINE_string status_fd "" \ | |
| 28 "The file descriptor to report status on; ignored." | |
| 29 DEFINE_string whitelist "${SRC_ROOT}/package_scripts/package.whitelist" \ | |
| 30 "The whitelist file to use." | |
| 31 DEFINE_boolean unpack $FLAGS_FALSE "Is the action 'unpack'?" | |
| 32 DEFINE_boolean configure $FLAGS_FALSE "Is the action 'configure'?" | |
| 33 DEFINE_boolean remove $FLAGS_FALSE "Is the action 'remove'?" | |
| 34 DEFINE_boolean auto_deconfigure $FLAGS_FALSE "Ignored" | |
| 35 DEFINE_boolean force_depends $FLAGS_FALSE "Ignored" | |
| 36 DEFINE_boolean force_remove_essential $FLAGS_FALSE "Ignored" | |
| 37 | |
| 38 # Fix up the command line and parse with shflags. | |
| 39 FIXED_FLAGS="$@" | |
| 40 FIXED_FLAGS=${FIXED_FLAGS/status-fd/status_fd} | |
| 41 FIXED_FLAGS=${FIXED_FLAGS/auto-deconfigure/auto_deconfigure} | |
| 42 FIXED_FLAGS=${FIXED_FLAGS/force-depends/force_depends} | |
| 43 FIXED_FLAGS=${FIXED_FLAGS/force-remove-essential/force_remove_essential} | |
| 44 FLAGS $FIXED_FLAGS || exit 1 | |
| 45 eval set -- "${FLAGS_ARGV}" | |
| 46 | |
| 47 # Die on any errors. | |
| 48 set -e | |
| 49 | |
| 50 # Returns true if either of the two given files exist and are not whitelisted. | |
| 51 # | |
| 52 # $1 - The package name. | |
| 53 # $2 - The path to the preinst file if it were to exist. | |
| 54 # $3 - The path to the postinst file if it were to exist. | |
| 55 has_missing_whitelist() { | |
| 56 local package=$1 | |
| 57 local preinst=$2 | |
| 58 local postinst=$3 | |
| 59 local missing_whitelist=0 | |
| 60 | |
| 61 if [ -f "$preinst" ]; then | |
| 62 if ! is_whitelisted "$preinst"; then | |
| 63 missing_whitelist=1 | |
| 64 echo "Warning: Missing whitelist entry for ${package}.preinst" | |
| 65 fi | |
| 66 fi | |
| 67 if [ -f "$postinst" ]; then | |
| 68 if ! is_whitelisted "$postinst"; then | |
| 69 missing_whitelist=1 | |
| 70 echo "Warning: Missing whitelist entry for ${package}.postinst" | |
| 71 fi | |
| 72 fi | |
| 73 test $missing_whitelist -ne 0 | |
| 74 } | |
| 75 | |
| 76 do_configure() { | |
| 77 local dpkg_info="$FLAGS_root/var/lib/dpkg/info/" | |
| 78 local fallback_packages="" | |
| 79 | |
| 80 for p in "$@"; do | |
| 81 echo "Configuring: $p" | |
| 82 | |
| 83 # Make sure that any .preinst or .postinst files are whitelisted. | |
| 84 local preinst="${dpkg_info}/${p}.preinst" | |
| 85 local postinst="${dpkg_info}/${p}.postinst" | |
| 86 if has_missing_whitelist "$p" "$preinst" "$postinst"; then | |
| 87 if [ $FLAGS_dpkg_fallback -eq $FLAGS_TRUE ]; then | |
| 88 echo "** Warning: Will run full maintainer scripts for ${p}." | |
| 89 fallback_packages="$fallback_packages $p" | |
| 90 continue | |
| 91 else | |
| 92 # TODO: Eventually should be upgraded to a full error. | |
| 93 echo "** Warning: Ignoring missing whitelist for ${p}." | |
| 94 fi | |
| 95 fi | |
| 96 | |
| 97 # Run our maintainer script for this package if we have one. | |
| 98 local chromium_postinst="${SRC_ROOT}/package_scripts/${p}.postinst" | |
| 99 if [ -f "$chromium_postinst" ]; then | |
| 100 echo "Running: $chromium_postinst" | |
| 101 ROOT="$FLAGS_root" SRC_ROOT="$SRC_ROOT" $chromium_postinst | |
| 102 fi | |
| 103 done | |
| 104 | |
| 105 if [ -n "$fallback_packages" ]; then | |
| 106 dpkg --root="$FLAGS_root" --configure $fallback_packages | |
| 107 fi | |
| 108 } | |
| 109 | |
| 110 do_unpack() { | |
| 111 local dpkg_status="$FLAGS_root/var/lib/dpkg/status" | |
| 112 local dpkg_info="$FLAGS_root/var/lib/dpkg/info/" | |
| 113 | |
| 114 if [ ! -d "$dpkg_info" ] | |
| 115 then | |
| 116 mkdir -p "$dpkg_info" | |
| 117 fi | |
| 118 | |
| 119 for p in "$@"; do | |
| 120 local package=$(dpkg-deb --field "$p" Package) | |
| 121 local tmpdir=$(mktemp -d) | |
| 122 | |
| 123 dpkg-deb --control "$p" "$tmpdir" | |
| 124 | |
| 125 local preinst="${tmpdir}/preinst" | |
| 126 local postinst="${tmpdir}/postinst" | |
| 127 if has_missing_whitelist "$package" "$preinst" "$postinst"; then | |
| 128 if [ $FLAGS_dpkg_fallback -eq $FLAGS_TRUE ]; then | |
| 129 echo "** Warning: Running full maintainer scripts for ${package}." | |
| 130 dpkg --root="$FLAGS_root" --unpack --auto-deconfigure "$p" | |
| 131 rm -rf "$tmpdir" | |
| 132 continue | |
| 133 else | |
| 134 # TODO: Eventually should be upgraded to a full error. | |
| 135 echo "** Warning: Ignoring missing whitelist for ${p}." | |
| 136 fi | |
| 137 fi | |
| 138 | |
| 139 # Copy the info files | |
| 140 local files=$(ls "$tmpdir" | grep -v control) | |
| 141 for f in $files; do | |
| 142 cp "${tmpdir}/${f}" "${dpkg_info}/${package}.${f}" | |
| 143 done | |
| 144 dpkg -c "$p" | sed 's,.* \.\/,/,; s/ -> .*//; s,^/$,/.,; s,/$,,' > \ | |
| 145 "${dpkg_info}/${package}.list" | |
| 146 | |
| 147 # Mark the package as installed successfully. | |
| 148 echo "Status: install ok installed" >> "$dpkg_status" | |
| 149 cat "${tmpdir}/control" >> "$dpkg_status" | |
| 150 echo "" >> "$dpkg_status" | |
| 151 | |
| 152 rm -rf "$tmpdir" | |
| 153 | |
| 154 # Run our maintainer script for this package if we have one. | |
| 155 local chromium_preinst="${SRC_ROOT}/package_scripts/${package}.preinst" | |
| 156 if [ -f "$chromium_preinst" ]; then | |
| 157 echo "Running: ${chromium_preinst}" | |
| 158 ROOT="$FLAGS_root" SRC_ROOT="$SRC_ROOT" $chromium_preinst | |
| 159 fi | |
| 160 | |
| 161 echo "Unpacking: $p" | |
| 162 dpkg-deb --extract "$p" "$FLAGS_root" | |
| 163 done | |
| 164 } | |
| 165 | |
| 166 # This script requires at least "--root=" | |
| 167 if [ -z "$FLAGS_root" ]; then | |
| 168 echo "dpkg_no_scripts: Missing root directory." | |
| 169 exit 1 | |
| 170 fi | |
| 171 | |
| 172 if [ $FLAGS_configure -eq $FLAGS_TRUE ]; then | |
| 173 do_configure $@ | |
| 174 elif [ $FLAGS_unpack -eq $FLAGS_TRUE ]; then | |
| 175 do_unpack $@ | |
| 176 elif [ $FLAGS_remove -eq $FLAGS_TRUE ]; then | |
| 177 # We log but ignore remove requests. | |
| 178 echo "Ignoring remove: $@" | |
| 179 else | |
| 180 echo "dpkg_no_scripts.sh: Unknown or missing command." | |
| 181 exit 1 | |
| 182 fi | |
| 183 | |
| 184 exit 0 | |
| OLD | NEW |