OLD | NEW |
1 #!/bin/sh | 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 # Sets up the chromium-based os from inside a chroot of the root fs. | 7 # Script to install packages into the target root file system. |
| 8 # |
8 # 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 |
9 # on your own unless you know what you are doing. | 10 # on your own unless you know what you are doing. |
10 | 11 |
| 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. |
| 14 . "$(dirname "$0")/common.sh" |
| 15 |
| 16 # Script must be run inside the chroot |
| 17 assert_inside_chroot |
| 18 |
| 19 # Flags |
| 20 DEFINE_string target "x86" \ |
| 21 "The target architecture to build for. One of { x86, arm }." |
| 22 DEFINE_string root "" \ |
| 23 "The root file system to install packages in." |
| 24 DEFINE_string output_dir "" \ |
| 25 "The location of the output directory to use." |
| 26 DEFINE_string package_list "" \ |
| 27 "The package list file to use." |
| 28 DEFINE_string setup_dir "/tmp" \ |
| 29 "The staging directory to use." |
| 30 DEFINE_string server "" \ |
| 31 "The package server to use." |
| 32 DEFINE_string suite "" \ |
| 33 "The package suite to use." |
| 34 DEFINE_string kernel_version "" \ |
| 35 "The kernel version to use." |
| 36 |
| 37 # Parse command line |
| 38 FLAGS "$@" || exit 1 |
| 39 eval set -- "${FLAGS_ARGV}" |
| 40 |
| 41 # Die on any errors. |
11 set -e | 42 set -e |
12 | 43 |
13 # Read options from the config file created by build_image.sh. | 44 ROOT_FS_DIR="$FLAGS_root" |
14 echo "Reading options..." | 45 if [[ -z "$ROOT_FS_DIR" ]]; then |
15 cat "$(dirname $0)/customize_opts.sh" | 46 echo "Error: --root is required." |
16 . "$(dirname $0)/customize_opts.sh" | 47 exit 1 |
17 | 48 fi |
18 PACKAGE_LIST_FILE="${SETUP_DIR}/package-list-prod.txt" | 49 if [[ ! -d "$ROOT_FS_DIR" ]]; then |
19 PACKAGE_LIST_FILE2="${SETUP_DIR}/package-list-2.txt" | 50 echo "Error: Root FS does not exist? ($ROOT_FS_DIR)" |
20 COMPONENTS=`cat $PACKAGE_LIST_FILE | grep -v ' *#' | grep -v '^ *$' | sed '/$/{N
;s/\n/ /;}'` | 51 exit 1 |
| 52 fi |
21 | 53 |
22 # Create the temporary apt source.list used to install packages. | 54 # Create the temporary apt source.list used to install packages. |
23 cat <<EOF > /etc/apt/sources.list | 55 APT_SOURCE="${ROOT_FS_DIR}/../sources.list" |
24 deb file:"$SETUP_DIR" local_packages/ | 56 cat <<EOF > "$APT_SOURCE" |
25 deb $SERVER $SUITE main restricted multiverse universe | 57 deb file:"$FLAGS_setup_dir" local_packages/ |
| 58 deb $FLAGS_server $FLAGS_suite main restricted multiverse universe |
26 EOF | 59 EOF |
27 | 60 |
| 61 # Cache directory for APT to use. |
| 62 APT_CACHE_DIR="${FLAGS_output_dir}/tmp/cache/" |
| 63 mkdir -p "${APT_CACHE_DIR}/archives/partial" |
| 64 |
| 65 # Create the apt configuration file. See "man apt.conf" |
| 66 APT_CONFIG="${ROOT_FS_DIR}/../apt.conf" |
| 67 cat <<EOF > "$APT_CONFIG" |
| 68 Dir |
| 69 { |
| 70 Cache "$APT_CACHE_DIR"; # TODO: Empty string to disable? |
| 71 Cache { |
| 72 archives "${APT_CACHE_DIR}/archives"; # TODO: Why do we need this? |
| 73 }; |
| 74 Etc |
| 75 { |
| 76 sourcelist "$APT_SOURCE" |
| 77 }; |
| 78 State "${ROOT_FS_DIR}/var/lib/apt/"; |
| 79 State |
| 80 { |
| 81 status "${ROOT_FS_DIR}/var/lib/dpkg/status"; |
| 82 }; |
| 83 }; |
| 84 DPkg |
| 85 { |
| 86 options {"--root=${ROOT_FS_DIR}";}; |
| 87 }; |
| 88 EOF |
| 89 |
| 90 # TODO: Full audit of the apt conf dump to make sure things are ok. |
| 91 apt-config -c="$APT_CONFIG" dump > "${ROOT_FS_DIR}/../apt.conf.dump" |
| 92 |
28 # Install prod packages | 93 # Install prod packages |
29 apt-get update | 94 COMPONENTS=`cat $FLAGS_package_list | grep -v ' *#' | grep -v '^ *$' | sed '/$/{
N;s/\n/ /;}'` |
30 apt-get --yes --force-yes install $COMPONENTS | 95 sudo apt-get -c="$APT_CONFIG" update |
| 96 sudo apt-get -c="$APT_CONFIG" --yes --force-yes install $COMPONENTS |
31 | 97 |
32 # Create kernel installation configuration to suppress warnings, | 98 # Create kernel installation configuration to suppress warnings, |
33 # install the kernel in /boot, and manage symlinks. | 99 # install the kernel in /boot, and manage symlinks. |
34 cat <<EOF > /etc/kernel-img.conf | 100 cat <<EOF | sudo dd of="${ROOT_FS_DIR}/etc/kernel-img.conf" |
35 link_in_boot = yes | 101 link_in_boot = yes |
36 do_symlinks = yes | 102 do_symlinks = yes |
37 minimal_swap = yes | 103 minimal_swap = yes |
38 clobber_modules = yes | 104 clobber_modules = yes |
39 warn_reboot = no | 105 warn_reboot = no |
40 do_bootloader = no | 106 do_bootloader = no |
41 do_initrd = yes | 107 do_initrd = yes |
42 warn_initrd = no | 108 warn_initrd = no |
43 EOF | 109 EOF |
44 | 110 |
45 # NB: KERNEL_VERSION comes from customize_opts.sh | 111 # Install the kernel. |
46 apt-get --yes --force-yes --no-install-recommends \ | 112 sudo apt-get -c="$APT_CONFIG" --yes --force-yes --no-install-recommends \ |
47 install "linux-image-${KERNEL_VERSION}" | 113 install "linux-image-${FLAGS_kernel_version}" |
48 | 114 |
49 # Setup bootchart. | 115 # Setup bootchart. |
50 # TODO: Move this and other developer oriented "components" into an optional | 116 # TODO: Move this and other developer oriented "components" into an optional |
51 # package-list-prod-dev.txt (ideally with a better name). | 117 # package-list-prod-dev.txt (ideally with a better name). |
52 apt-get --yes --force-yes --no-install-recommends install bootchart | 118 sudo apt-get -c="$APT_CONFIG" --yes --force-yes --no-install-recommends \ |
| 119 install bootchart |
53 | 120 |
54 # Install additional packages from a second mirror, if necessary. This must | 121 # Clean up the apt cache. |
55 # be done after all packages from the first repository are installed; after | 122 # TODO: The cache was populated by debootstrap, not these installs. Remove |
56 # the apt-get update, apt-get and debootstrap will prefer the newest package | 123 # this line when we can get debootstrap to stop doing this. |
57 # versions (which are probably on this second mirror). | 124 sudo rm -f "${ROOT_FS_DIR}"/var/cache/apt/archives/*.deb |
58 if [ -f "$PACKAGE_LIST_FILE2" ] | |
59 then | |
60 COMPONENTS2=`cat $PACKAGE_LIST_FILE2 | grep -v ' *#' | grep -v '^ *$' | sed '/
$/{N;s/\n/ /;}'` | |
61 | |
62 echo "deb $SERVER2 $SUITE2 main restricted multiverse universe" \ | |
63 >> /etc/apt/sources.list | |
64 apt-get update | |
65 apt-get --yes --force-yes --no-install-recommends \ | |
66 install $COMPONENTS2 | |
67 fi | |
68 | 125 |
69 # List all packages installed so far, since these are what the local | 126 # List all packages installed so far, since these are what the local |
70 # repository needs to contain. | 127 # repository needs to contain. |
71 # TODO: better place to put the list. Must still exist after the chroot | 128 # TODO: Replace with list_installed_packages.sh when it is fixed up. |
72 # is dismounted, so build_image.sh can get it. That rules out /tmp and | 129 dpkg --root="${ROOT_FS_DIR}" -l > \ |
73 # $SETUP_DIR (which is under /tmp). | 130 "${FLAGS_output_dir}/package_list_installed.txt" |
74 sudo sh -c "/trunk/src/scripts/list_installed_packages.sh \ | |
75 > /etc/package_list_installed.txt" | |
76 | |
77 # Clean up other useless stuff created as part of the install process. | |
78 rm -f /var/cache/apt/archives/*.deb | |
79 | |
80 # List all packages still installed post-pruning | |
81 sudo sh -c "/trunk/src/scripts/list_installed_packages.sh \ | |
82 > /etc/package_list_pruned.txt" | |
OLD | NEW |