| 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. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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 target "x86" \ |
| 28 "The target architecture to build for. One of { x86, arm }." | 28 "The target architecture to build for. One of { x86, arm }." |
| 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_IMG_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 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 }; | 139 }; |
| 140 DPkg | 140 DPkg |
| 141 { | 141 { |
| 142 options {"--root=${ROOT_FS_DIR}";}; | 142 options {"--root=${ROOT_FS_DIR}";}; |
| 143 }; | 143 }; |
| 144 EOF | 144 EOF |
| 145 | 145 |
| 146 # TODO: Full audit of the apt conf dump to make sure things are ok. | 146 # TODO: Full audit of the apt conf dump to make sure things are ok. |
| 147 apt-config dump > "${OUTPUT_DIR}/apt.conf.dump" | 147 apt-config dump > "${OUTPUT_DIR}/apt.conf.dump" |
| 148 | 148 |
| 149 # Add debootstrap link for the suite, if it doesn't exist. | 149 # We do a rough equivalent to debootstrap that installs the minimal |
| 150 if [ ! -e "/usr/share/debootstrap/scripts/$FLAGS_suite" ] | 150 # packages needed to be able to run apt to install the rest. We don't |
| 151 then | 151 # use debootstrap since it is geared toward having a second stage that |
| 152 sudo ln -s /usr/share/debootstrap/scripts/jaunty \ | 152 # needs to run package maintainer scripts. This is also simpler. |
| 153 "/usr/share/debootstrap/scripts/$FLAGS_suite" | |
| 154 fi | |
| 155 | 153 |
| 156 if [ -z "$EXPERIMENTAL_NO_DEBOOTSTRAP" -a \ | 154 # The set of required packages before apt can take over. |
| 157 -z "$EXPERIMENTAL_NO_MAINTAINER_SCRIPTS" ]; then | 155 PACKAGES="debconf libacl1 libattr1 libc6 libgcc1 libselinux1" |
| 158 # Use debootstrap, which runs maintainer scripts. | |
| 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 | |
| 162 # We do a rough equivalent to debootstrap that installs the minimal | |
| 163 # packages needed to be able to run apt to install the rest. We don't | |
| 164 # use debootstrap since it is geared toward having a second stage that | |
| 165 # needs to run package maintainer scripts. This is also simpler. | |
| 166 | 156 |
| 167 # The set of required packages before apt can take over. | 157 # Set of packages that we need to install early so that other packages |
| 168 PACKAGES="debconf libacl1 libattr1 libc6 libgcc1 libselinux1" | 158 # maintainer scripts can still basically run. |
| 159 # |
| 160 # login - So that groupadd will work |
| 161 # base-passwd/passwd - So that chmod and useradd/groupadd will work |
| 162 # bash - So that scripts can run |
| 163 # libpam-runtime/libuuid1 - Not exactly sure why |
| 164 # sysv-rc - So that we can overwrite invoke-rc.d, update-rc.d |
| 165 EXTRA_PACKAGES="base-files base-passwd bash libpam-runtime libuuid1 login passwd
sysv-rc" |
| 169 | 166 |
| 170 # Set of packages that we need to install early so that other packages | 167 # Prep the rootfs to work with dpgk and apt |
| 171 # maintainer scripts can still basically run. | 168 sudo mkdir -p "${ROOT_FS_DIR}/var/lib/dpkg/info" |
| 172 # | 169 sudo touch "${ROOT_FS_DIR}/var/lib/dpkg/available" \ |
| 173 # login - So that groupadd will work | 170 "${ROOT_FS_DIR}/var/lib/dpkg/diversions" \ |
| 174 # base-passwd/passwd - So that chmod and useradd/groupadd will work | 171 "${ROOT_FS_DIR}/var/lib/dpkg/status" |
| 175 # bash - So that scripts can run | 172 sudo mkdir -p "${ROOT_FS_DIR}/var/lib/apt/lists/partial" \ |
| 176 # libpam-runtim/libuuid1 - Not exactly sure why | 173 "${ROOT_FS_DIR}/var/lib/dpkg/updates" |
| 177 # sysv-rc - So that we can overwrite invoke-rc.d, update-rc.d | |
| 178 EXTRA_PACKAGES="base-files base-passwd bash libpam-runtime libuuid1 login pass
wd sysv-rc" | |
| 179 | 174 |
| 180 # Prep the rootfs to work with dpgk and apt | 175 # Download the initial packages into the apt cache if necessary. |
| 181 sudo mkdir -p "${ROOT_FS_DIR}/var/lib/dpkg/info" | 176 REPO="${APT_CACHE_DIR}/archives" |
| 182 sudo touch "${ROOT_FS_DIR}/var/lib/dpkg/available" \ | 177 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive apt-get update |
| 183 "${ROOT_FS_DIR}/var/lib/dpkg/diversions" \ | 178 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \ |
| 184 "${ROOT_FS_DIR}/var/lib/dpkg/status" | 179 apt-get --download-only install $PACKAGES $EXTRA_PACKAGES |
| 185 sudo mkdir -p "${ROOT_FS_DIR}/var/lib/apt/lists/partial" \ | |
| 186 "${ROOT_FS_DIR}/var/lib/dpkg/updates" | |
| 187 | 180 |
| 188 # Download the initial packages into the apt cache if necessary. | 181 # Install initial packages directly with dpkg_no_scripts.sh |
| 189 REPO="${APT_CACHE_DIR}/archives" | 182 for p in $PACKAGES $EXTRA_PACKAGES; do |
| 190 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive apt-get update | 183 PKG=$(ls "${REPO}"/${p}_*_i386.deb || /bin/true) |
| 191 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \ | 184 if [ -z "$PKG" ]; then |
| 192 apt-get --download-only install $PACKAGES $EXTRA_PACKAGES | 185 PKG=$(ls "${REPO}"/${p}_*_all.deb) |
| 186 fi |
| 187 sudo "${SCRIPTS_DIR}"/dpkg_no_scripts.sh \ |
| 188 --root="$ROOT_FS_DIR" --unpack "$PKG" |
| 189 done |
| 193 | 190 |
| 194 i=0 | 191 # Make sure that apt is ready to work. We use --fix-broken to trigger apt |
| 195 for p in $PACKAGES $EXTRA_PACKAGES; do | 192 # to install additional critical packages. If there are any of these, we |
| 196 set +e | 193 # disable the maintainer scripts so they install ok. |
| 197 PKG=$(ls "${REPO}"/${p}_*_i386.deb) | 194 TMP_FORCE_NO_SCRIPTS="-o=Dir::Bin::dpkg=${SCRIPTS_DIR}/dpkg_no_scripts.sh" |
| 198 set -e | 195 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \ |
| 199 if [ -z "$PKG" ]; then | 196 apt-get $TMP_FORCE_NO_SCRIPTS --force-yes --fix-broken install |
| 200 PKG=$(ls "${REPO}"/${p}_*_all.deb) | |
| 201 fi | |
| 202 echo "Installing package: $PKG [$i]" | |
| 203 sudo "${SCRIPTS_DIR}"/dpkg_no_scripts.sh \ | |
| 204 --root="$ROOT_FS_DIR" --unpack "$PKG" | |
| 205 i=$((i + 1)) | |
| 206 done | |
| 207 | 197 |
| 208 # Make sure that apt is ready to work. We use --fix-broken to trigger apt | 198 # ----- MAINTAINER SCRIPT FIXUPS ----- |
| 209 # to install additional critical packages. If there are any of these, we | |
| 210 # disable the maintainer scripts so they install ok. | |
| 211 TMP_FORCE_NO_SCRIPTS="-o=Dir::Bin::dpkg=${SCRIPTS_DIR}/dpkg_no_scripts.sh" | |
| 212 sudo APT_CONFIG="$APT_CONFIG" DEBIAN_FRONTEND=noninteractive \ | |
| 213 apt-get $TMP_FORCE_NO_SCRIPTS --force-yes --fix-broken install | |
| 214 | 199 |
| 215 # ----- MAINTAINER SCRIPT FIXUPS ----- | 200 # TODO: Remove when we stop having maintainer scripts altogether. |
| 201 sudo cp -a /dev/* "${ROOT_FS_DIR}/dev" |
| 202 sudo cp -a /etc/resolv.conf "${ROOT_FS_DIR}/etc/resolv.conf" |
| 203 sudo ln -sf /bin/true "${ROOT_FS_DIR}/usr/sbin/invoke-rc.d" |
| 204 sudo ln -sf /bin/true "${ROOT_FS_DIR}/usr/sbin/update-rc.d" |
| 216 | 205 |
| 217 # TODO: Remove when we stop having maintainer scripts altogether. | 206 # base-files |
| 218 sudo cp -a /dev/* "${ROOT_FS_DIR}/dev" | 207 # TODO: Careful audit of the postinst; this isn't all that is there. |
| 219 sudo cp -a /etc/resolv.conf "${ROOT_FS_DIR}/etc/resolv.conf" | 208 sudo cp -a "${ROOT_FS_DIR}/usr/share/base-files/networks" \ |
| 220 sudo ln -sf /bin/true "${ROOT_FS_DIR}/usr/sbin/invoke-rc.d" | 209 "${ROOT_FS_DIR}/usr/share/base-files/nsswitch.conf" \ |
| 221 sudo ln -sf /bin/true "${ROOT_FS_DIR}/usr/sbin/update-rc.d" | 210 "${ROOT_FS_DIR}/usr/share/base-files/profile" \ |
| 211 "${ROOT_FS_DIR}/etc/" |
| 222 | 212 |
| 223 # base-files | 213 # base-passwd |
| 224 # TODO: Careful audit of the postinst; this isn't all that is there. | 214 sudo cp "${ROOT_FS_DIR}/usr/share/base-passwd/passwd.master" \ |
| 225 sudo cp -a "${ROOT_FS_DIR}/usr/share/base-files/networks" \ | 215 "${ROOT_FS_DIR}/etc/passwd" |
| 226 "${ROOT_FS_DIR}/usr/share/base-files/nsswitch.conf" \ | 216 sudo cp "${ROOT_FS_DIR}/usr/share/base-passwd/group.master" \ |
| 227 "${ROOT_FS_DIR}/usr/share/base-files/profile" \ | 217 "${ROOT_FS_DIR}/etc/group" |
| 228 "${ROOT_FS_DIR}/etc/" | |
| 229 | 218 |
| 230 # base-passwd | 219 # libpam-runtime |
| 231 sudo cp "${ROOT_FS_DIR}/usr/share/base-passwd/passwd.master" \ | 220 # The postinst script calls pam-auth-update, which is a perl script that |
| 232 "${ROOT_FS_DIR}/etc/passwd" | 221 # expects to run within the targetfs. Until we fix this, we just copy |
| 233 sudo cp "${ROOT_FS_DIR}/usr/share/base-passwd/group.master" \ | 222 # from the build chroot. |
| 234 "${ROOT_FS_DIR}/etc/group" | 223 sudo cp -a /etc/pam.d/common-* \ |
| 224 /etc/pam.d/login \ |
| 225 /etc/pam.d/newusers \ |
| 226 /etc/pam.d/su \ |
| 227 /etc/pam.d/sudo \ |
| 228 "${ROOT_FS_DIR}/etc/pam.d/" |
| 235 | 229 |
| 236 # libpam-runtime | 230 # mawk |
| 237 # The postinst script calls pam-auth-update, which is a perl script that | 231 sudo ln -s mawk "${ROOT_FS_DIR}/usr/bin/awk" |
| 238 # expects to run within the targetfs. Until we fix this, we just copy | |
| 239 # from the build chroot. | |
| 240 sudo cp -a /etc/pam.d/common-* \ | |
| 241 /etc/pam.d/login \ | |
| 242 /etc/pam.d/newusers \ | |
| 243 /etc/pam.d/su \ | |
| 244 /etc/pam.d/sudo \ | |
| 245 "${ROOT_FS_DIR}/etc/pam.d/" | |
| 246 | 232 |
| 247 # mawk | 233 # base-files? |
| 248 sudo ln -s mawk "${ROOT_FS_DIR}/usr/bin/awk" | 234 sudo touch "${ROOT_FS_DIR}/etc/fstab" |
| 249 | 235 |
| 250 # base-files? | 236 # sysv-rc needs this |
| 251 sudo touch "${ROOT_FS_DIR}/etc/fstab" | 237 sudo mkdir -p "${ROOT_FS_DIR}/etc/init.d" |
| 252 | 238 |
| 253 # sysv-rc needs this | 239 # ----- END MAINTAINER SCRIPT FIXUPS ----- |
| 254 sudo mkdir -p "${ROOT_FS_DIR}/etc/init.d" | |
| 255 fi # EXPERIMENTAL_NO_DEBOOTSTRAP | |
| 256 | 240 |
| 257 # Set up mounts for working within the rootfs. We copy some basic | 241 # Set up mounts for working within the rootfs. We copy some basic |
| 258 # network information from the host so that maintainer scripts can | 242 # network information from the host so that maintainer scripts can |
| 259 # access the network as needed. | 243 # access the network as needed. |
| 260 # TODO: All of this rootfs mount stuff can be removed as soon as we stop | 244 # TODO: All of this rootfs mount stuff can be removed as soon as we stop |
| 261 # running the maintainer scripts on install. | 245 # running the maintainer scripts on install. |
| 262 sudo mount -t proc proc "${ROOT_FS_DIR}/proc" | 246 sudo mount -t proc proc "${ROOT_FS_DIR}/proc" |
| 263 sudo cp /etc/hosts "${ROOT_FS_DIR}/etc" | 247 sudo cp /etc/hosts "${ROOT_FS_DIR}/etc" |
| 264 trap cleanup_rootfs_mounts EXIT | 248 trap cleanup_rootfs_mounts EXIT |
| 265 | 249 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 286 apt-get --force-yes install "linux-image-${KERNEL_VERSION}" | 270 apt-get --force-yes install "linux-image-${KERNEL_VERSION}" |
| 287 | 271 |
| 288 # List all packages installed so far, since these are what the local | 272 # List all packages installed so far, since these are what the local |
| 289 # repository needs to contain. | 273 # repository needs to contain. |
| 290 # TODO: Replace with list_installed_packages.sh when it is fixed up. | 274 # TODO: Replace with list_installed_packages.sh when it is fixed up. |
| 291 dpkg --root="${ROOT_FS_DIR}" -l > \ | 275 dpkg --root="${ROOT_FS_DIR}" -l > \ |
| 292 "${OUTPUT_DIR}/package_list_installed.txt" | 276 "${OUTPUT_DIR}/package_list_installed.txt" |
| 293 | 277 |
| 294 cleanup_rootfs_mounts | 278 cleanup_rootfs_mounts |
| 295 trap - EXIT | 279 trap - EXIT |
| OLD | NEW |