OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Script to install packages into the target root file system. | 7 # Script to install packages into the target root file system. |
8 # | 8 # |
9 # NOTE: This script should be called by build_image.sh. Do not run this | 9 # NOTE: This script should be called by build_image.sh. Do not run this |
10 # on your own unless you know what you are doing. | 10 # on your own unless you know what you are doing. |
11 | 11 |
12 # Load common constants. This should be the first executable line. | 12 # Load common constants. This should be the first executable line. |
13 # The path to common.sh should be relative to your script's location. | 13 # The path to common.sh should be relative to your script's location. |
14 . "$(dirname "$0")/common.sh" | 14 . "$(dirname "$0")/common.sh" |
15 | 15 |
16 # Script must be run inside the chroot | 16 # Script must be run inside the chroot |
17 assert_inside_chroot | 17 assert_inside_chroot |
18 assert_not_root_user | 18 assert_not_root_user |
19 | 19 |
20 DEFAULT_PKGLIST="${SRC_ROOT}/package_repo/package-list-prod.txt" | 20 DEFAULT_PKGLIST="${SRC_ROOT}/package_repo/package-list-prod.txt" |
21 | 21 |
22 # Flags | 22 # Flags |
23 DEFINE_string output_dir "" \ | 23 DEFINE_string output_dir "" \ |
24 "The location of the output directory to use [REQUIRED]." | 24 "The location of the output directory to use [REQUIRED]." |
25 DEFINE_string root "" \ | 25 DEFINE_string root "" \ |
26 "The root file system to install packages in." | 26 "The root file system to install packages in." |
27 DEFINE_string target "x86" \ | 27 DEFINE_string arch "x86" \ |
28 "The target architecture to build for. One of { x86, arm }." | 28 "The target architecture to build for. One of { x86, armel }." |
29 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ | 29 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ |
30 "Root of build output" | 30 "Root of build output" |
31 DEFINE_string package_list "$DEFAULT_PKGLIST" \ | 31 DEFINE_string package_list "$DEFAULT_PKGLIST" \ |
32 "The package list file to use." | 32 "The package list file to use." |
33 DEFINE_string server "$DEFAULT_EXT_MIRROR" \ | 33 DEFINE_string server "$DEFAULT_EXT_MIRROR" \ |
34 "The package server to use." | 34 "The package server to use." |
35 DEFINE_string suite "$DEFAULT_IMG_SUITE" \ | 35 DEFINE_string suite "$DEFAULT_IMG_SUITE" \ |
36 "The package suite to use." | 36 "The package suite to use." |
37 | 37 |
38 # Parse command line | 38 # Parse command line |
39 FLAGS "$@" || exit 1 | 39 FLAGS "$@" || exit 1 |
40 eval set -- "${FLAGS_ARGV}" | 40 eval set -- "${FLAGS_ARGV}" |
41 | 41 |
42 # Die on any errors. | 42 # Die on any errors. |
43 set -e | 43 set -e |
44 | 44 |
45 KERNEL_DEB_PATH=$(find "${FLAGS_build_root}/${FLAGS_target}/local_packages" \ | 45 KERNEL_DEB_PATH=$(find "${FLAGS_build_root}/${FLAGS_arch}/local_packages" \ |
46 -name "linux-image-*.deb") | 46 -name "linux-image-*.deb") |
47 KERNEL_DEB=$(basename "${KERNEL_DEB_PATH}" .deb | sed -e 's/linux-image-//' \ | 47 KERNEL_DEB=$(basename "${KERNEL_DEB_PATH}" .deb | sed -e 's/linux-image-//' \ |
48 -e 's/_.*//') | 48 -e 's/_.*//') |
49 KERNEL_VERSION=${KERNEL_VERSION:-${KERNEL_DEB}} | 49 KERNEL_VERSION=${KERNEL_VERSION:-${KERNEL_DEB}} |
50 | 50 |
51 if [[ -z "$FLAGS_output_dir" ]]; then | 51 if [[ -z "$FLAGS_output_dir" ]]; then |
52 echo "Error: --output_dir is required." | 52 echo "Error: --output_dir is required." |
53 exit 1 | 53 exit 1 |
54 fi | 54 fi |
55 OUTPUT_DIR=$(readlink -f "$FLAGS_output_dir") | 55 OUTPUT_DIR=$(readlink -f "$FLAGS_output_dir") |
(...skipping 18 matching lines...) Expand all Loading... |
74 | 74 |
75 # Sometimes the volatile directory is left mounted and sometimes it is not, | 75 # Sometimes the volatile directory is left mounted and sometimes it is not, |
76 # so we precede by '!' to disable the ERR trap. | 76 # so we precede by '!' to disable the ERR trap. |
77 ! sudo umount "$ROOT_FS_DIR"/lib/modules/2.6.*/volatile/ > /dev/null 2>&1 | 77 ! sudo umount "$ROOT_FS_DIR"/lib/modules/2.6.*/volatile/ > /dev/null 2>&1 |
78 | 78 |
79 sudo umount "${ROOT_FS_DIR}/proc" | 79 sudo umount "${ROOT_FS_DIR}/proc" |
80 } | 80 } |
81 | 81 |
82 # Set up repository for locally built packages; these take highest precedence. | 82 # Set up repository for locally built packages; these take highest precedence. |
83 mkdir -p "${SETUP_DIR}/local_packages" | 83 mkdir -p "${SETUP_DIR}/local_packages" |
84 cp "${FLAGS_build_root}/${FLAGS_target}/local_packages"/* \ | 84 cp "${FLAGS_build_root}/${FLAGS_arch}/local_packages"/* \ |
85 "${SETUP_DIR}/local_packages" | 85 "${SETUP_DIR}/local_packages" |
86 cd "$SETUP_DIR" | 86 cd "$SETUP_DIR" |
87 dpkg-scanpackages local_packages/ /dev/null | \ | 87 dpkg-scanpackages local_packages/ /dev/null | \ |
88 gzip > local_packages/Packages.gz | 88 gzip > local_packages/Packages.gz |
89 cd - | 89 cd - |
90 | 90 |
91 # Create the temporary apt source.list used to install packages. | 91 # Create the temporary apt source.list used to install packages. |
92 APT_SOURCE="${OUTPUT_DIR}/sources.list" | 92 APT_SOURCE="${OUTPUT_DIR}/sources.list" |
93 cat <<EOF > "$APT_SOURCE" | 93 cat <<EOF > "$APT_SOURCE" |
94 deb file:"$SETUP_DIR" local_packages/ | 94 deb file:"$SETUP_DIR" local_packages/ |
95 deb $FLAGS_server $FLAGS_suite main restricted multiverse universe | 95 deb $FLAGS_server $FLAGS_suite main restricted multiverse universe |
96 EOF | 96 EOF |
97 | 97 |
98 # Cache directory for APT to use. This cache is re-used across builds. We | 98 # Cache directory for APT to use. This cache is re-used across builds. We |
99 # rely on the cache to reduce traffic to the hosted repositories. | 99 # rely on the cache to reduce traffic to the hosted repositories. |
100 APT_CACHE_DIR="${FLAGS_build_root}/apt_cache-${FLAGS_target}/" | 100 APT_CACHE_DIR="${FLAGS_build_root}/apt_cache-${FLAGS_arch}/" |
101 mkdir -p "${APT_CACHE_DIR}/archives/partial" | 101 mkdir -p "${APT_CACHE_DIR}/archives/partial" |
102 | 102 |
103 # Create the apt configuration file. See "man apt.conf" | 103 # Create the apt configuration file. See "man apt.conf" |
104 APT_PARTS="${OUTPUT_DIR}/apt.conf.d" | 104 APT_PARTS="${OUTPUT_DIR}/apt.conf.d" |
105 mkdir -p "$APT_PARTS" # An empty apt.conf.d to avoid other configs. | 105 mkdir -p "$APT_PARTS" # An empty apt.conf.d to avoid other configs. |
106 export APT_CONFIG="${OUTPUT_DIR}/apt.conf" | 106 export APT_CONFIG="${OUTPUT_DIR}/apt.conf" |
107 cat <<EOF > "$APT_CONFIG" | 107 cat <<EOF > "$APT_CONFIG" |
108 APT | 108 APT |
109 { | 109 { |
110 Install-Recommends "0"; | 110 Install-Recommends "0"; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 sudo mkdir -p "${ROOT_FS_DIR}/var/lib/apt/lists/partial" \ | 170 sudo mkdir -p "${ROOT_FS_DIR}/var/lib/apt/lists/partial" \ |
171 "${ROOT_FS_DIR}/var/lib/dpkg/updates" | 171 "${ROOT_FS_DIR}/var/lib/dpkg/updates" |
172 | 172 |
173 # Download the initial packages into the apt cache if necessary. | 173 # Download the initial packages into the apt cache if necessary. |
174 REPO="${APT_CACHE_DIR}/archives" | 174 REPO="${APT_CACHE_DIR}/archives" |
175 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive apt-get update | 175 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive apt-get update |
176 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \ | 176 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \ |
177 apt-get --download-only install $PACKAGES $EXTRA_PACKAGES | 177 apt-get --download-only install $PACKAGES $EXTRA_PACKAGES |
178 | 178 |
179 # Install initial packages directly with dpkg_no_scripts.sh | 179 # Install initial packages directly with dpkg_no_scripts.sh |
| 180 ARCH="$FLAGS_arch" |
| 181 if [ "$ARCH" = "x86" ]; then |
| 182 ARCH="i?86" # Match i386 | i686 |
| 183 fi |
180 for p in $PACKAGES $EXTRA_PACKAGES; do | 184 for p in $PACKAGES $EXTRA_PACKAGES; do |
181 PKG=$(ls "${REPO}"/${p}_*_i386.deb || /bin/true) | 185 PKG=$(ls "${REPO}"/${p}_*_$ARCH.deb || /bin/true) |
182 if [ -z "$PKG" ]; then | 186 if [ -z "$PKG" ]; then |
183 PKG=$(ls "${REPO}"/${p}_*_all.deb) | 187 PKG=$(ls "${REPO}"/${p}_*_all.deb) |
184 fi | 188 fi |
185 sudo "${SCRIPTS_DIR}"/dpkg_no_scripts.sh \ | 189 sudo "${SCRIPTS_DIR}"/dpkg_no_scripts.sh \ |
186 --root="$ROOT_FS_DIR" --nodpkg_fallback --unpack "$PKG" | 190 --root="$ROOT_FS_DIR" --nodpkg_fallback --unpack "$PKG" |
187 sudo "${SCRIPTS_DIR}"/dpkg_no_scripts.sh \ | 191 sudo "${SCRIPTS_DIR}"/dpkg_no_scripts.sh \ |
188 --root="$ROOT_FS_DIR" --nodpkg_fallback --configure "$p" | 192 --root="$ROOT_FS_DIR" --nodpkg_fallback --configure "$p" |
189 done | 193 done |
190 | 194 |
191 # Make sure that apt is ready to work. We use --fix-broken to trigger apt | 195 # Make sure that apt is ready to work. We use --fix-broken to trigger apt |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 apt-get --force-yes install "linux-image-${KERNEL_VERSION}" | 237 apt-get --force-yes install "linux-image-${KERNEL_VERSION}" |
234 | 238 |
235 # List all packages installed so far, since these are what the local | 239 # List all packages installed so far, since these are what the local |
236 # repository needs to contain. | 240 # repository needs to contain. |
237 # TODO: Replace with list_installed_packages.sh when it is fixed up. | 241 # TODO: Replace with list_installed_packages.sh when it is fixed up. |
238 dpkg --root="${ROOT_FS_DIR}" -l > \ | 242 dpkg --root="${ROOT_FS_DIR}" -l > \ |
239 "${OUTPUT_DIR}/package_list_installed.txt" | 243 "${OUTPUT_DIR}/package_list_installed.txt" |
240 | 244 |
241 cleanup_rootfs_mounts | 245 cleanup_rootfs_mounts |
242 trap - EXIT | 246 trap - EXIT |
OLD | NEW |