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

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

Issue 523146: Switch install_packages.sh to re-use the apt cache across runs. (Closed)
Patch Set: Created 10 years, 11 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 | « no previous file | 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.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 ! sudo kill $pid # Preceded by ! to disable ERR trap. 72 ! sudo kill $pid # Preceded by ! to disable ERR trap.
73 done 73 done
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 # Create setup directory and copy over scripts, config files, and locally 82 # Set up repository for locally built packages; these take highest precedence.
83 # built packages.
84 mkdir -p "${SETUP_DIR}/local_packages" 83 mkdir -p "${SETUP_DIR}/local_packages"
85 cp "${FLAGS_build_root}/${FLAGS_target}/local_packages"/* \ 84 cp "${FLAGS_build_root}/${FLAGS_target}/local_packages"/* \
86 "${SETUP_DIR}/local_packages" 85 "${SETUP_DIR}/local_packages"
87
88 # Set up repository for local packages to install in the rootfs via apt-get.
89 cd "$SETUP_DIR" 86 cd "$SETUP_DIR"
90 dpkg-scanpackages local_packages/ /dev/null | \ 87 dpkg-scanpackages local_packages/ /dev/null | \
91 gzip > local_packages/Packages.gz 88 gzip > local_packages/Packages.gz
92 cd - 89 cd -
93 90
94 # Create the temporary apt source.list used to install packages. 91 # Create the temporary apt source.list used to install packages.
95 APT_SOURCE="${OUTPUT_DIR}/sources.list" 92 APT_SOURCE="${OUTPUT_DIR}/sources.list"
96 cat <<EOF > "$APT_SOURCE" 93 cat <<EOF > "$APT_SOURCE"
97 deb file:"$SETUP_DIR" local_packages/ 94 deb file:"$SETUP_DIR" local_packages/
98 deb $FLAGS_server $FLAGS_suite main restricted multiverse universe 95 deb $FLAGS_server $FLAGS_suite main restricted multiverse universe
99 EOF 96 EOF
100 97
101 # Cache directory for APT to use. 98 # Cache directory for APT to use. This cache is re-used across builds. We
102 APT_CACHE_DIR="${OUTPUT_DIR}/tmp/cache/" 99 # rely on the cache to reduce traffic to the hosted repositories.
100 APT_CACHE_DIR="${FLAGS_build_root}/apt_cache-${FLAGS_target}/"
103 mkdir -p "${APT_CACHE_DIR}/archives/partial" 101 mkdir -p "${APT_CACHE_DIR}/archives/partial"
104 102
105 # Create the apt configuration file. See "man apt.conf" 103 # Create the apt configuration file. See "man apt.conf"
106 NO_MAINTAINER_SCRIPTS="" 104 NO_MAINTAINER_SCRIPTS=""
107 if [ -n "$EXPERIMENTAL_NO_MAINTAINER_SCRIPTS" ]; then 105 if [ -n "$EXPERIMENTAL_NO_MAINTAINER_SCRIPTS" ]; then
108 NO_MAINTAINER_SCRIPTS="Bin { dpkg \"${SCRIPTS_DIR}/dpkg_no_scripts.sh\"; };" 106 NO_MAINTAINER_SCRIPTS="Bin { dpkg \"${SCRIPTS_DIR}/dpkg_no_scripts.sh\"; };"
109 fi 107 fi
110 APT_PARTS="${OUTPUT_DIR}/apt.conf.d" 108 APT_PARTS="${OUTPUT_DIR}/apt.conf.d"
111 mkdir -p "$APT_PARTS" # An empty apt.conf.d to avoid other configs. 109 mkdir -p "$APT_PARTS" # An empty apt.conf.d to avoid other configs.
112 export APT_CONFIG="${OUTPUT_DIR}/apt.conf" 110 export APT_CONFIG="${OUTPUT_DIR}/apt.conf"
113 cat <<EOF > "$APT_CONFIG" 111 cat <<EOF > "$APT_CONFIG"
114 APT 112 APT
115 { 113 {
116 Install-Recommends "0"; 114 Install-Recommends "0";
117 Install-Suggests "0"; 115 Install-Suggests "0";
118 Get 116 Get
119 { 117 {
120 Assume-Yes "1"; 118 Assume-Yes "1";
119 AllowUnauthenticated "1";
121 }; 120 };
122 }; 121 };
123 Dir 122 Dir
124 { 123 {
125 $NO_MAINTAINER_SCRIPTS 124 $NO_MAINTAINER_SCRIPTS
126 Cache "$APT_CACHE_DIR"; 125 Cache "$APT_CACHE_DIR";
127 Cache { 126 Cache {
128 archives "${APT_CACHE_DIR}/archives"; 127 archives "${APT_CACHE_DIR}/archives";
129 }; 128 };
130 Etc 129 Etc
(...skipping 20 matching lines...) Expand all
151 if [ ! -e "/usr/share/debootstrap/scripts/$FLAGS_suite" ] 150 if [ ! -e "/usr/share/debootstrap/scripts/$FLAGS_suite" ]
152 then 151 then
153 sudo ln -s /usr/share/debootstrap/scripts/jaunty \ 152 sudo ln -s /usr/share/debootstrap/scripts/jaunty \
154 "/usr/share/debootstrap/scripts/$FLAGS_suite" 153 "/usr/share/debootstrap/scripts/$FLAGS_suite"
155 fi 154 fi
156 155
157 if [ -z "$EXPERIMENTAL_NO_DEBOOTSTRAP" -a \ 156 if [ -z "$EXPERIMENTAL_NO_DEBOOTSTRAP" -a \
158 -z "$EXPERIMENTAL_NO_MAINTAINER_SCRIPTS" ]; then 157 -z "$EXPERIMENTAL_NO_MAINTAINER_SCRIPTS" ]; then
159 # Use debootstrap, which runs maintainer scripts. 158 # Use debootstrap, which runs maintainer scripts.
160 sudo debootstrap --arch=i386 $FLAGS_suite "$ROOT_FS_DIR" "${FLAGS_server}" 159 sudo debootstrap --arch=i386 $FLAGS_suite "$ROOT_FS_DIR" "${FLAGS_server}"
160 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive apt-get update
161 else 161 else
162 # A hack-in-progress that does our own debootstrap equivalent and skips 162 # We do a rough equivalent to debootstrap that installs the minimal
163 # maintainer scripts. 163 # packages needed to be able to run apt to install the rest. We don't
164 164 # use debootstrap since it is geared toward having a second stage that
165 # TODO: Replace with a pointer to lool's repo or maybe apt-get --download-only ? 165 # needs to run package maintainer scripts. This is also simpler.
166 REPO="${GCLIENT_ROOT}/repo/var/cache/make_local_repo"
167 166
168 # The set of required packages before apt can take over. 167 # The set of required packages before apt can take over.
169 PACKAGES="debconf libacl1 libattr1 libc6 libgcc1 libselinux1" 168 PACKAGES="debconf libacl1 libattr1 libc6 libgcc1 libselinux1"
170 169
171 # Set of packages that we need to install early so that other packages 170 # Set of packages that we need to install early so that other packages
172 # maintainer scripts can still basically run. 171 # maintainer scripts can still basically run.
173 # 172 #
174 # login - So that groupadd will work 173 # login - So that groupadd will work
175 # base-passwd/passwd - So that chmod and useradd/groupadd will work 174 # base-passwd/passwd - So that chmod and useradd/groupadd will work
176 # bash - So that scripts can run 175 # bash - So that scripts can run
177 # libpam-runtim/libuuid1 - Not exactly sure why 176 # libpam-runtim/libuuid1 - Not exactly sure why
178 EXTRA_PACKAGES="base-files base-passwd bash libpam-runtime libuuid1 login pass wd" 177 EXTRA_PACKAGES="base-files base-passwd bash libpam-runtime libuuid1 login pass wd"
179 178
180 # Prep the rootfs to work with dpgk and apt 179 # Prep the rootfs to work with dpgk and apt
181 sudo mkdir -p "${ROOT_FS_DIR}/var/lib/dpkg/info" 180 sudo mkdir -p "${ROOT_FS_DIR}/var/lib/dpkg/info"
182 sudo touch "${ROOT_FS_DIR}/var/lib/dpkg/available" \ 181 sudo touch "${ROOT_FS_DIR}/var/lib/dpkg/available" \
183 "${ROOT_FS_DIR}/var/lib/dpkg/diversions" \ 182 "${ROOT_FS_DIR}/var/lib/dpkg/diversions" \
184 "${ROOT_FS_DIR}/var/lib/dpkg/status" 183 "${ROOT_FS_DIR}/var/lib/dpkg/status"
185 sudo mkdir -p "${ROOT_FS_DIR}/var/lib/apt/lists/partial" \ 184 sudo mkdir -p "${ROOT_FS_DIR}/var/lib/apt/lists/partial" \
186 "${ROOT_FS_DIR}/var/lib/dpkg/updates" 185 "${ROOT_FS_DIR}/var/lib/dpkg/updates"
187 186
187 # Download the initial packages into the apt cache if necessary.
188 REPO="${APT_CACHE_DIR}/archives"
189 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive apt-get update
190 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \
191 apt-get --download-only install $PACKAGES $EXTRA_PACKAGES
192
188 i=0 193 i=0
189 for p in $PACKAGES $EXTRA_PACKAGES; do 194 for p in $PACKAGES $EXTRA_PACKAGES; do
190 set +e 195 set +e
191 PKG=$(ls "${REPO}"/${p}_*_i386.deb) 196 PKG=$(ls "${REPO}"/${p}_*_i386.deb)
192 set -e 197 set -e
193 if [ -z "$PKG" ]; then 198 if [ -z "$PKG" ]; then
194 PKG=$(ls "${REPO}"/${p}_*_all.deb) 199 PKG=$(ls "${REPO}"/${p}_*_all.deb)
195 fi 200 fi
196 echo "Installing package: $PKG [$i]" 201 echo "Installing package: $PKG [$i]"
197 sudo "${SCRIPTS_DIR}"/dpkg_no_scripts.sh \ 202 sudo "${SCRIPTS_DIR}"/dpkg_no_scripts.sh \
198 --root="$ROOT_FS_DIR" --unpack "$PKG" 203 --root="$ROOT_FS_DIR" --unpack "$PKG"
199 i=$((i + 1)) 204 i=$((i + 1))
200 done 205 done
201 206
207 # Make sure that apt is ready to work. We use --fix-broken to trigger apt
208 # to install additional critical packages. If there are any of these, we
209 # disable the maintainer scripts so they install ok.
210 TMP_FORCE_NO_SCRIPTS="-o=Dir::Bin::dpkg=${SCRIPTS_DIR}/dpkg_no_scripts.sh"
211 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \
212 apt-get $TMP_FORCE_NO_SCRIPTS --force-yes --fix-broken install
213
202 # ----- MAINTAINER SCRIPT FIXUPS ----- 214 # ----- MAINTAINER SCRIPT FIXUPS -----
203 215
204 # TODO: Remove when we stop having maintainer scripts altogether. 216 # TODO: Remove when we stop having maintainer scripts altogether.
205 sudo cp -a /dev/* "${ROOT_FS_DIR}/dev" 217 sudo cp -a /dev/* "${ROOT_FS_DIR}/dev"
206 218
207 # base-passwd 219 # base-passwd
208 sudo cp "${ROOT_FS_DIR}/usr/share/base-passwd/passwd.master" \ 220 sudo cp "${ROOT_FS_DIR}/usr/share/base-passwd/passwd.master" \
209 "${ROOT_FS_DIR}/etc/passwd" 221 "${ROOT_FS_DIR}/etc/passwd"
210 sudo cp "${ROOT_FS_DIR}/usr/share/base-passwd/group.master" \ 222 sudo cp "${ROOT_FS_DIR}/usr/share/base-passwd/group.master" \
211 "${ROOT_FS_DIR}/etc/group" 223 "${ROOT_FS_DIR}/etc/group"
(...skipping 12 matching lines...) Expand all
224 # mawk 236 # mawk
225 sudo ln -s mawk "${ROOT_FS_DIR}/usr/bin/awk" 237 sudo ln -s mawk "${ROOT_FS_DIR}/usr/bin/awk"
226 238
227 # base-files? 239 # base-files?
228 sudo touch "${ROOT_FS_DIR}/etc/fstab" 240 sudo touch "${ROOT_FS_DIR}/etc/fstab"
229 241
230 # sysv-rc needs this 242 # sysv-rc needs this
231 sudo mkdir -p "${ROOT_FS_DIR}/etc/init.d" 243 sudo mkdir -p "${ROOT_FS_DIR}/etc/init.d"
232 fi # EXPERIMENTAL_NO_DEBOOTSTRAP 244 fi # EXPERIMENTAL_NO_DEBOOTSTRAP
233 245
234
235 # Set up mounts for working within the rootfs. We copy some basic 246 # Set up mounts for working within the rootfs. We copy some basic
236 # network information from the host so that maintainer scripts can 247 # network information from the host so that maintainer scripts can
237 # access the network as needed. 248 # access the network as needed.
238 # TODO: All of this rootfs mount stuff can be removed as soon as we stop 249 # TODO: All of this rootfs mount stuff can be removed as soon as we stop
239 # running the maintainer scripts on install. 250 # running the maintainer scripts on install.
240 sudo mount -t proc proc "${ROOT_FS_DIR}/proc" 251 sudo mount -t proc proc "${ROOT_FS_DIR}/proc"
241 sudo cp /etc/hosts "${ROOT_FS_DIR}/etc" 252 sudo cp /etc/hosts "${ROOT_FS_DIR}/etc"
242 trap cleanup_rootfs_mounts EXIT 253 trap cleanup_rootfs_mounts EXIT
243 254
244 # Make sure that apt is ready to work. We use --fix-broken to trigger apt
245 # to install additional critical packages. If there are any of these, we
246 # disable the maintainer scripts so they install ok.
247 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive apt-get update
248 TMP_FORCE_NO_SCRIPTS="-o=Dir::Bin::dpkg=${SCRIPTS_DIR}/dpkg_no_scripts.sh"
249 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \
250 apt-get $TMP_FORCE_NO_SCRIPTS --force-yes --fix-broken install
251
252 # Install prod packages 255 # Install prod packages
253 COMPONENTS=`cat $FLAGS_package_list | grep -v ' *#' | grep -v '^ *$' | sed '/$/{ N;s/\n/ /;}'` 256 COMPONENTS=`cat $FLAGS_package_list | grep -v ' *#' | grep -v '^ *$' | sed '/$/{ N;s/\n/ /;}'`
254 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \ 257 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \
255 apt-get --force-yes install $COMPONENTS 258 apt-get --force-yes install $COMPONENTS
256 259
257 # Create kernel installation configuration to suppress warnings, 260 # Create kernel installation configuration to suppress warnings,
258 # install the kernel in /boot, and manage symlinks. 261 # install the kernel in /boot, and manage symlinks.
259 cat <<EOF | sudo dd of="${ROOT_FS_DIR}/etc/kernel-img.conf" 262 cat <<EOF | sudo dd of="${ROOT_FS_DIR}/etc/kernel-img.conf"
260 link_in_boot = yes 263 link_in_boot = yes
261 do_symlinks = yes 264 do_symlinks = yes
262 minimal_swap = yes 265 minimal_swap = yes
263 clobber_modules = yes 266 clobber_modules = yes
264 warn_reboot = no 267 warn_reboot = no
265 do_bootloader = no 268 do_bootloader = no
266 do_initrd = yes 269 do_initrd = yes
267 warn_initrd = no 270 warn_initrd = no
268 EOF 271 EOF
269 272
270 # Install the kernel. 273 # Install the kernel.
271 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \ 274 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \
272 apt-get --force-yes install "linux-image-${KERNEL_VERSION}" 275 apt-get --force-yes install "linux-image-${KERNEL_VERSION}"
273 276
274 # Clean up the apt cache.
275 # TODO: The cache was populated by debootstrap, not these installs. Remove
276 # this line when we can get debootstrap to stop doing this.
277 sudo rm -f "${ROOT_FS_DIR}"/var/cache/apt/archives/*.deb
278 # Need to rm read-only created lock files in order for archiving step to work
279 sudo rm -rf "$APT_CACHE_DIR"
280
281 # List all packages installed so far, since these are what the local 277 # List all packages installed so far, since these are what the local
282 # repository needs to contain. 278 # repository needs to contain.
283 # TODO: Replace with list_installed_packages.sh when it is fixed up. 279 # TODO: Replace with list_installed_packages.sh when it is fixed up.
284 dpkg --root="${ROOT_FS_DIR}" -l > \ 280 dpkg --root="${ROOT_FS_DIR}" -l > \
285 "${OUTPUT_DIR}/package_list_installed.txt" 281 "${OUTPUT_DIR}/package_list_installed.txt"
286 282
287 cleanup_rootfs_mounts 283 cleanup_rootfs_mounts
288 trap - EXIT 284 trap - EXIT
OLDNEW
« 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