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

Side by Side Diff: src/scripts/install_packages.sh

Issue 520004: Moved debootstrap phase from build_image.sh to install_packages.sh. (Closed)
Patch Set: Fixed flag defaults. Moved bootchart. Created 10 years, 12 months 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 unified diff | Download patch
« no previous file with comments | « src/scripts/build_image.sh ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
19
20 DEFAULT_PKGLIST="${SRC_ROOT}/package_repo/package-list-prod.txt"
18 21
19 # Flags 22 # Flags
23 DEFINE_string output_dir "" \
24 "The location of the output directory to use [REQUIRED]."
25 DEFINE_string root "" \
26 "The root file system to install packages in."
20 DEFINE_string target "x86" \ 27 DEFINE_string target "x86" \
21 "The target architecture to build for. One of { x86, arm }." 28 "The target architecture to build for. One of { x86, arm }."
22 DEFINE_string root "" \ 29 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \
23 "The root file system to install packages in." 30 "Root of build output"
24 DEFINE_string output_dir "" \ 31 DEFINE_string package_list "$DEFAULT_PKGLIST" \
25 "The location of the output directory to use."
26 DEFINE_string package_list "" \
27 "The package list file to use." 32 "The package list file to use."
28 DEFINE_string setup_dir "/tmp" \ 33 DEFINE_string server "$DEFAULT_IMG_MIRROR" \
29 "The staging directory to use."
30 DEFINE_string server "" \
31 "The package server to use." 34 "The package server to use."
32 DEFINE_string suite "" \ 35 DEFINE_string suite "$DEFAULT_IMG_SUITE" \
33 "The package suite to use." 36 "The package suite to use."
34 DEFINE_string kernel_version "" \
35 "The kernel version to use."
36 37
37 # Parse command line 38 # Parse command line
38 FLAGS "$@" || exit 1 39 FLAGS "$@" || exit 1
39 eval set -- "${FLAGS_ARGV}" 40 eval set -- "${FLAGS_ARGV}"
40 41
41 # Die on any errors. 42 # Die on any errors.
42 set -e 43 set -e
43 44
44 ROOT_FS_DIR="$FLAGS_root" 45 KERNEL_DEB_PATH=$(find "${FLAGS_build_root}/${FLAGS_target}/local_packages" \
45 if [[ -z "$ROOT_FS_DIR" ]]; then 46 -name "linux-image-*.deb")
46 echo "Error: --root is required." 47 KERNEL_DEB=$(basename "${KERNEL_DEB_PATH}" .deb | sed -e 's/linux-image-//' \
48 -e 's/_.*//')
49 KERNEL_VERSION=${KERNEL_VERSION:-${KERNEL_DEB}}
50
51 if [[ -z "$FLAGS_output_dir" ]]; then
52 echo "Error: --output_dir is required."
47 exit 1 53 exit 1
48 fi 54 fi
49 if [[ ! -d "$ROOT_FS_DIR" ]]; then 55 OUTPUT_DIR=$(readlink -f "$FLAGS_output_dir")
50 echo "Error: Root FS does not exist? ($ROOT_FS_DIR)" 56 SETUP_DIR="${OUTPUT_DIR}/local_repo"
51 exit 1 57 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
58 if [[ -n "$FLAGS_root" ]]; then
59 ROOT_FS_DIR=$(readlink -f "$FLAGS_root")
52 fi 60 fi
61 mkdir -p "$OUTPUT_DIR" "$SETUP_DIR" "$ROOT_FS_DIR"
62
63 # Make sure anything mounted in the rootfs is cleaned up ok on exit.
64 cleanup_rootfs_mounts() {
65 # Occasionally there are some daemons left hanging around that have our
66 # root image file system open. We do a best effort attempt to kill them.
67 PIDS=`sudo lsof -t "$ROOT_FS_DIR" | sort | uniq`
68 for pid in $PIDS
69 do
70 local cmdline=`cat /proc/$pid/cmdline`
71 echo "Killing process that has open file on our rootfs: $cmdline"
72 ! sudo kill $pid # Preceded by ! to disable ERR trap.
73 done
74
75 # Sometimes the volatile directory is left mounted and sometimes it is not,
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
78
79 sudo umount "${ROOT_FS_DIR}/proc"
80 sudo umount "${ROOT_FS_DIR}/sys"
81 }
82
83 # Create setup directory and copy over scripts, config files, and locally
84 # built packages.
85 mkdir -p "${SETUP_DIR}/local_packages"
86 cp "${FLAGS_build_root}/${FLAGS_target}/local_packages"/* \
87 "${SETUP_DIR}/local_packages"
88
89 # Set up repository for local packages to install in the rootfs via apt-get.
90 cd "$SETUP_DIR"
91 dpkg-scanpackages local_packages/ /dev/null | \
92 gzip > local_packages/Packages.gz
93 cd -
53 94
54 # Create the temporary apt source.list used to install packages. 95 # Create the temporary apt source.list used to install packages.
55 APT_SOURCE="${FLAGS_output_dir}/sources.list" 96 APT_SOURCE="${OUTPUT_DIR}/sources.list"
56 cat <<EOF > "$APT_SOURCE" 97 cat <<EOF > "$APT_SOURCE"
57 deb file:"$FLAGS_setup_dir" local_packages/ 98 deb file:"$SETUP_DIR" local_packages/
58 deb $FLAGS_server $FLAGS_suite main restricted multiverse universe 99 deb $FLAGS_server $FLAGS_suite main restricted multiverse universe
59 EOF 100 EOF
60 101
61 # Cache directory for APT to use. 102 # Cache directory for APT to use.
62 APT_CACHE_DIR="${FLAGS_output_dir}/tmp/cache/" 103 APT_CACHE_DIR="${OUTPUT_DIR}/tmp/cache/"
63 mkdir -p "${APT_CACHE_DIR}/archives/partial" 104 mkdir -p "${APT_CACHE_DIR}/archives/partial"
64 105
65 # Create the apt configuration file. See "man apt.conf" 106 # Create the apt configuration file. See "man apt.conf"
66 APT_PARTS="${FLAGS_output_dir}/apt.conf.d" 107 APT_PARTS="${OUTPUT_DIR}/apt.conf.d"
67 mkdir -p "$APT_PARTS" # An empty apt.conf.d to avoid other configs. 108 mkdir -p "$APT_PARTS" # An empty apt.conf.d to avoid other configs.
68 export APT_CONFIG="${FLAGS_output_dir}/apt.conf" 109 export APT_CONFIG="${OUTPUT_DIR}/apt.conf"
69 cat <<EOF > "$APT_CONFIG" 110 cat <<EOF > "$APT_CONFIG"
70 APT 111 APT
71 { 112 {
72 Install-Recommends "0"; 113 Install-Recommends "0";
73 Install-Suggests "0"; 114 Install-Suggests "0";
74 Get 115 Get
75 { 116 {
76 Assume-Yes "1"; 117 Assume-Yes "1";
77 }; 118 };
78 }; 119 };
(...skipping 14 matching lines...) Expand all
93 status "${ROOT_FS_DIR}/var/lib/dpkg/status"; 134 status "${ROOT_FS_DIR}/var/lib/dpkg/status";
94 }; 135 };
95 }; 136 };
96 DPkg 137 DPkg
97 { 138 {
98 options {"--root=${ROOT_FS_DIR}";}; 139 options {"--root=${ROOT_FS_DIR}";};
99 }; 140 };
100 EOF 141 EOF
101 142
102 # TODO: Full audit of the apt conf dump to make sure things are ok. 143 # TODO: Full audit of the apt conf dump to make sure things are ok.
103 apt-config dump > "${FLAGS_output_dir}/apt.conf.dump" 144 apt-config dump > "${OUTPUT_DIR}/apt.conf.dump"
145
146 # Add debootstrap link for the suite, if it doesn't exist.
147 if [ ! -e "/usr/share/debootstrap/scripts/$FLAGS_suite" ]
148 then
149 sudo ln -s /usr/share/debootstrap/scripts/jaunty \
150 "/usr/share/debootstrap/scripts/$FLAGS_suite"
151 fi
152
153 # Bootstrap the base debian file system
154 # TODO: Switch to --variant=minbase
155 sudo debootstrap --arch=i386 $FLAGS_suite "$ROOT_FS_DIR" "${FLAGS_server}"
156
157 # Set up mounts for working within the rootfs. We copy some basic
158 # network information from the host so that maintainer scripts can
159 # access the network as needed.
160 # TODO: All of this rootfs mount stuff can be removed as soon as we stop
161 # running the maintainer scripts on install.
162 sudo mount -t proc proc "${ROOT_FS_DIR}/proc"
163 sudo mount -t sysfs sysfs "${ROOT_FS_DIR}/sys" # TODO: Do we need sysfs?
164 sudo cp /etc/hosts "${ROOT_FS_DIR}/etc"
165 trap cleanup_rootfs_mounts EXIT
104 166
105 # Install prod packages 167 # Install prod packages
106 COMPONENTS=`cat $FLAGS_package_list | grep -v ' *#' | grep -v '^ *$' | sed '/$/{ N;s/\n/ /;}'` 168 COMPONENTS=`cat $FLAGS_package_list | grep -v ' *#' | grep -v '^ *$' | sed '/$/{ N;s/\n/ /;}'`
107 sudo APT_CONFIG="$APT_CONFIG" apt-get update 169 sudo APT_CONFIG="$APT_CONFIG" apt-get update
108 sudo APT_CONFIG="$APT_CONFIG" apt-get --force-yes \ 170 sudo APT_CONFIG="$APT_CONFIG" apt-get --force-yes \
109 install $COMPONENTS 171 install $COMPONENTS
110 172
111 # Create kernel installation configuration to suppress warnings, 173 # Create kernel installation configuration to suppress warnings,
112 # install the kernel in /boot, and manage symlinks. 174 # install the kernel in /boot, and manage symlinks.
113 cat <<EOF | sudo dd of="${ROOT_FS_DIR}/etc/kernel-img.conf" 175 cat <<EOF | sudo dd of="${ROOT_FS_DIR}/etc/kernel-img.conf"
114 link_in_boot = yes 176 link_in_boot = yes
115 do_symlinks = yes 177 do_symlinks = yes
116 minimal_swap = yes 178 minimal_swap = yes
117 clobber_modules = yes 179 clobber_modules = yes
118 warn_reboot = no 180 warn_reboot = no
119 do_bootloader = no 181 do_bootloader = no
120 do_initrd = yes 182 do_initrd = yes
121 warn_initrd = no 183 warn_initrd = no
122 EOF 184 EOF
123 185
124 # Install the kernel. 186 # Install the kernel.
125 sudo APT_CONFIG="$APT_CONFIG" apt-get --force-yes \ 187 sudo APT_CONFIG="$APT_CONFIG" apt-get --force-yes \
126 install "linux-image-${FLAGS_kernel_version}" 188 install "linux-image-${KERNEL_VERSION}"
127
128 # Setup bootchart.
129 # TODO: Move this and other developer oriented "components" into an optional
130 # package-list-prod-dev.txt (ideally with a better name).
131 sudo APT_CONFIG="$APT_CONFIG" apt-get --force-yes \
132 install bootchart
133 189
134 # Clean up the apt cache. 190 # Clean up the apt cache.
135 # TODO: The cache was populated by debootstrap, not these installs. Remove 191 # TODO: The cache was populated by debootstrap, not these installs. Remove
136 # this line when we can get debootstrap to stop doing this. 192 # this line when we can get debootstrap to stop doing this.
137 sudo rm -f "${ROOT_FS_DIR}"/var/cache/apt/archives/*.deb 193 sudo rm -f "${ROOT_FS_DIR}"/var/cache/apt/archives/*.deb
138 194
139 # List all packages installed so far, since these are what the local 195 # List all packages installed so far, since these are what the local
140 # repository needs to contain. 196 # repository needs to contain.
141 # TODO: Replace with list_installed_packages.sh when it is fixed up. 197 # TODO: Replace with list_installed_packages.sh when it is fixed up.
142 dpkg --root="${ROOT_FS_DIR}" -l > \ 198 dpkg --root="${ROOT_FS_DIR}" -l > \
143 "${FLAGS_output_dir}/package_list_installed.txt" 199 "${OUTPUT_DIR}/package_list_installed.txt"
200
201 cleanup_rootfs_mounts
202 trap - EXIT
OLDNEW
« no previous file with comments | « src/scripts/build_image.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698