#!/bin/bash # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # Script to install packages into the target root file system. # # NOTE: This script should be called by build_image.sh. Do not run this # on your own unless you know what you are doing. # Load common constants. This should be the first executable line. # The path to common.sh should be relative to your script's location. . "$(dirname "$0")/common.sh" # Script must be run inside the chroot assert_inside_chroot # Flags DEFINE_string target "x86" \ "The target architecture to build for. One of { x86, arm }." DEFINE_string root "" \ "The root file system to install packages in." DEFINE_string output_dir "" \ "The location of the output directory to use." DEFINE_string package_list "" \ "The package list file to use." DEFINE_string setup_dir "/tmp" \ "The staging directory to use." DEFINE_string server "" \ "The package server to use." DEFINE_string suite "" \ "The package suite to use." DEFINE_string kernel_version "" \ "The kernel version to use." # Parse command line FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Die on any errors. set -e ROOT_FS_DIR="$FLAGS_root" if [[ -z "$ROOT_FS_DIR" ]]; then echo "Error: --root is required." exit 1 fi if [[ ! -d "$ROOT_FS_DIR" ]]; then echo "Error: Root FS does not exist? ($ROOT_FS_DIR)" exit 1 fi # Create the temporary apt source.list used to install packages. APT_SOURCE="${ROOT_FS_DIR}/../sources.list" cat < "$APT_SOURCE" deb file:"$FLAGS_setup_dir" local_packages/ deb $FLAGS_server $FLAGS_suite main restricted multiverse universe EOF # Cache directory for APT to use. APT_CACHE_DIR="${FLAGS_output_dir}/tmp/cache/" mkdir -p "${APT_CACHE_DIR}/archives/partial" # Create the apt configuration file. See "man apt.conf" APT_CONFIG="${ROOT_FS_DIR}/../apt.conf" cat < "$APT_CONFIG" Dir { Cache "$APT_CACHE_DIR"; # TODO: Empty string to disable? Cache { archives "${APT_CACHE_DIR}/archives"; # TODO: Why do we need this? }; Etc { sourcelist "$APT_SOURCE" }; State "${ROOT_FS_DIR}/var/lib/apt/"; State { status "${ROOT_FS_DIR}/var/lib/dpkg/status"; }; }; DPkg { options {"--root=${ROOT_FS_DIR}";}; }; EOF # TODO: Full audit of the apt conf dump to make sure things are ok. apt-config -c="$APT_CONFIG" dump > "${ROOT_FS_DIR}/../apt.conf.dump" # Install prod packages COMPONENTS=`cat $FLAGS_package_list | grep -v ' *#' | grep -v '^ *$' | sed '/$/{N;s/\n/ /;}'` sudo apt-get -c="$APT_CONFIG" update sudo apt-get -c="$APT_CONFIG" --yes --force-yes --no-install-recommends \ install $COMPONENTS # Create kernel installation configuration to suppress warnings, # install the kernel in /boot, and manage symlinks. cat < \ "${FLAGS_output_dir}/package_list_installed.txt"