Start copying over source.

git-svn-id: svn://chrome-svn/chromeos/trunk@4 06c00378-0e64-4dae-be16-12b19f9950a1
This commit is contained in:
rspangler@google.com 2009-10-09 20:56:14 +00:00
commit d74220d772
23 changed files with 2860 additions and 0 deletions

82
archive_build.sh Executable file
View File

@ -0,0 +1,82 @@
#!/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 archive build results. Used by the buildbots.
# 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 outside the chroot
assert_outside_chroot
IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images"
# Default to the most recent image
DEFAULT_FROM="${IMAGES_DIR}/`ls -t1 $IMAGES_DIR | head -1`"
DEFAULT_TO="${GCLIENT_ROOT}/archive"
# Flags
DEFINE_string from "$DEFAULT_FROM" \
"Directory to archive"
DEFINE_string to "$DEFAULT_TO" "Directory of build archive"
DEFINE_integer keep_max 0 "Maximum builds to keep in archive (0=all)"
DEFINE_string zipname "image.zip" "Name of zip file to create."
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on any errors.
set -e
# Get version information
. "${SCRIPTS_DIR}/chromeos_version.sh"
# Get subversion revision
SVN_REVISION=`svn info | grep "Revision: " | awk '{print $2}'`
# Use the version number plus revision as the last change. (Need both, since
# trunk builds multiple times with the same version string.)
LAST_CHANGE="${CHROMEOS_VERSION_STRING}-r${SVN_REVISION}"
# The Chromium buildbot scripts only create a clickable link to the archive
# if an output line of the form "last change: XXX" exists
echo "last change: $LAST_CHANGE"
echo "archive from: $FLAGS_from"
# Create the output directory
OUTDIR="${FLAGS_to}/${LAST_CHANGE}"
ZIPFILE="${OUTDIR}/${FLAGS_zipname}"
echo "archive to dir: $OUTDIR"
echo "archive to file: $ZIPFILE"
rm -rf "$OUTDIR"
mkdir -p "$OUTDIR"
# Zip the build
echo "Compressing and archiving build..."
cd "$DEFAULT_FROM"
zip -r "$ZIPFILE" *
cd -
# Update LATEST file
echo "$LAST_CHANGE" > "${FLAGS_to}/LATEST"
# Make sure files are readable
chmod 644 "$ZIPFILE" "${FLAGS_to}/LATEST"
chmod 755 "$OUTDIR"
# Purge old builds if necessary
if [ $FLAGS_keep_max -gt 0 ]
then
echo "Deleting old builds (all but the newest ${FLAGS_keep_max})..."
cd "$FLAGS_to"
# +2 because line numbers start at 1 and need to skip LATEST file
rm -rf `ls -t1 | tail --lines=+$(($FLAGS_keep_max + 2))`
cd -
fi
echo "Done."

16
build_all.sh Executable file
View File

@ -0,0 +1,16 @@
#!/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.
# Simple script for building the entire system.
# Die on error; print commands
set -e
./build_platform_packages.sh
./build_tests.sh
./build_kernel.sh
./run_tests.sh
./build_image.sh --replace

65
build_chrome.sh Executable file
View File

@ -0,0 +1,65 @@
#!/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 for building our own custom Chrome
# 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 outside the chroot
assert_outside_chroot
# This script defaults Chrome source is in /usr/local/google/home/$USER/chrome
# You may override the Chrome source dir by passing in chrome_dir
# or with the CHROME_DIR environment variable
DEFAULT_CHROME_DIR="${CHROME_DIR:-/usr/local/google/home/$USER/chrome}"
# Flags
DEFINE_string chrome_dir "$DEFAULT_CHROME_DIR" \
"Directory to Chrome source"
DEFINE_string mode "Release" \
"The mode to build Chrome in (Debug or Release)"
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on error; print commands
set -e
# Convert args to paths. Need eval to un-quote the string so that shell
# chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work.
FLAGS_chrome_dir=`eval readlink -f $FLAGS_chrome_dir`
# Build Chrome
echo Building Chrome in mode $FLAGS_mode
export GYP_DEFINES=chromeos=1
CHROME_DIR=$FLAGS_chrome_dir
cd "$CHROME_DIR/src/build"
gclient runhooks --force
hammer --implicit-deps-changed --mode=$FLAGS_mode chrome
# Zip into chrome-chromeos.zip and put in local_assets
BUILD_DIR="$CHROME_DIR/src/sconsbuild"
CHROME_LINUX_DIR="$BUILD_DIR/chrome-chromeos"
OUTPUT_DIR="${SRC_ROOT}/build/x86/local_assets"
OUTPUT_ZIP="$BUILD_DIR/chrome-chromeos.zip"
if [ -n "$OUTPUT_DIR" ]
then
mkdir -p $OUTPUT_DIR
fi
# create symlink so that we can create the zip file with prefix chrome-chromeos
rm -f $CHROME_LINUX_DIR
ln -s $BUILD_DIR/$FLAGS_mode $CHROME_LINUX_DIR
echo Zipping $CHROME_LINUX_DIR to $OUTPUT_ZIP
cd $BUILD_DIR
rm -f $OUTPUT_ZIP
zip -r9 $OUTPUT_ZIP chrome-chromeos -x "chrome-chromeos/lib/*" \
"chrome-chromeos/obj/*" "chrome-chromeos/mksnapshot" "chrome-chromeos/protoc"
cp -f $OUTPUT_ZIP $OUTPUT_DIR
echo Done.

273
build_image.sh Executable file
View File

@ -0,0 +1,273 @@
#!/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 build a bootable keyfob-based chromeos system image.
# It uses debootstrap (see https://wiki.ubuntu.com/DebootstrapChroot) to
# create a base file system. It then cusotmizes the file system and adds
# Ubuntu and chromeos specific packages. Finally, it creates a bootable USB
# image from the root fs.
#
# NOTE: This script must be run from the chromeos build chroot environment.
#
# 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
DEFAULT_PKGLIST="${SRC_ROOT}/package_repo/package-list-prod.txt"
# Flags
DEFINE_integer build_attempt 1 \
"The build attempt for this image build."
DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \
"Directory in which to place image result directories (named by version)"
DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \
"Root of build output"
DEFINE_boolean use_ubuntu_kernel $FLAGS_FALSE \
"Use the Ubuntu kernel (rather than our own)?"
DEFINE_boolean replace $FLAGS_FALSE "Overwrite existing output, if any."
DEFINE_string mirror "$DEFAULT_IMG_MIRROR" "Repository mirror to use."
DEFINE_string suite "$DEFAULT_IMG_SUITE" "Repository suite to base image on."
DEFINE_string pkglist "$DEFAULT_PKGLIST" \
"Name of file listing packages to install from repository."
DEFINE_string mirror2 "$DEFAULT_EXT_MIRROR" "Additional mirror to use."
DEFINE_string suite2 "$DEFAULT_EXT_SUITE" "Suite to use in additional mirror."
DEFINE_string pkglist2 "" \
"Name of file listing packages to install from additional mirror."
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on any errors.
set -e
USE_UBUNTU_KERNEL=0
if [ $FLAGS_use_ubuntu_kernel -eq $FLAGS_TRUE ]
then
USE_UBUNTU_KERNEL=1
fi
# Determine build version
. "${SCRIPTS_DIR}/chromeos_version.sh"
# Use canonical path since some tools (e.g. mount) do not like symlinks
# Append build attempt to output directory
IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}"
OUTPUT_DIR="${FLAGS_output_root}/${IMAGE_SUBDIR}"
ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image"
MBR_IMG="${OUTPUT_DIR}/mbr.image"
OUTPUT_IMG="${OUTPUT_DIR}/usb.img"
ROOTFS_CUSTOMIZE_SCRIPT="customize_rootfs.sh"
ROOTFS_SETUP_DIR="/tmp/chromeos_setup"
SETUP_DIR="${ROOT_FS_DIR}/${ROOTFS_SETUP_DIR}"
LOOP_DEV=
# Handle existing directory
if [ -e "$OUTPUT_DIR" ]
then
if [ $FLAGS_replace -eq $FLAGS_TRUE ]
then
sudo rm -rf "$OUTPUT_DIR"
else
echo "Directory $OUTPUT_DIR already exists."
echo "Use --build_attempt option to specify an unused attempt."
echo "Or use --replace if you want to overwrite this directory."
exit 1
fi
fi
# create the output directory
mkdir -p "$OUTPUT_DIR"
# Make sure anything mounted in the rootfs is cleaned up ok on exit.
cleanup_rootfs_mounts() {
# Occasionally there are some daemons left hanging around that have our
# root image file system open. We do a best effort attempt to kill them.
PIDS=`sudo lsof -t "$ROOT_FS_DIR" | sort | uniq`
for pid in $PIDS
do
local cmdline=`cat /proc/$pid/cmdline`
echo "Killing process that has open file on our rootfs: $cmdline"
! sudo kill $pid # Preceded by ! to disable ERR trap.
done
# Sometimes the volatile directory is left mounted and sometimes it is not,
# so we precede by '!' to disable the ERR trap.
! sudo umount "$ROOT_FS_DIR"/lib/modules/2.6.*/volatile/
sudo umount "${ROOT_FS_DIR}/proc"
sudo umount "${ROOT_FS_DIR}/sys"
sudo umount "${ROOT_FS_DIR}/trunk"
}
cleanup_rootfs_loop() {
sudo umount "$LOOP_DEV"
sleep 1 # in case $LOOP_DEV is in use
sudo losetup -d "$LOOP_DEV"
}
cleanup() {
# Disable die on error.
set +e
cleanup_rootfs_mounts
if [ -n "$LOOP_DEV" ]
then
cleanup_rootfs_loop
fi
# Turn die on error back on.
set -e
}
trap cleanup EXIT
mkdir -p "$ROOT_FS_DIR"
# Create root file system disk image to fit on a 1GB memory stick.
# 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes.
ROOT_SIZE_BYTES=$((1024 * 1024 * 950))
dd if=/dev/zero of="$ROOT_FS_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
# Format, tune, and mount the rootfs.
# Make sure we have a mtab to keep mkfs happy.
if [ ! -e /etc/mtab ]; then
sudo touch /etc/mtab
fi
UUID=`uuidgen`
DISK_LABEL=C-$CHROMEOS_VERSION
LOOP_DEV=`sudo losetup -f`
sudo losetup "$LOOP_DEV" "$ROOT_FS_IMG"
sudo mkfs.ext3 "$LOOP_DEV"
sudo tune2fs -L "$DISK_LABEL" -U "$UUID" -c 0 -i 0 "$LOOP_DEV"
sudo mount "$LOOP_DEV" "$ROOT_FS_DIR"
# Add debootstrap link for the suite, if it doesn't exist.
if [ ! -e "/usr/share/debootstrap/scripts/$FLAGS_suite" ]
then
sudo ln -s /usr/share/debootstrap/scripts/jaunty \
"/usr/share/debootstrap/scripts/$FLAGS_suite"
fi
# Bootstrap the base debian file system
sudo debootstrap --arch=i386 $FLAGS_suite "$ROOT_FS_DIR" "${FLAGS_mirror}"
# -- Customize the root file system --
# Set up mounts for working within the chroot. We copy some basic
# network information from the host so that the chroot can access
# repositories on the network as needed.
sudo mount -t proc proc "${ROOT_FS_DIR}/proc"
sudo mount -t sysfs sysfs "${ROOT_FS_DIR}/sys" # TODO: Do we need sysfs?
sudo cp /etc/hosts "${ROOT_FS_DIR}/etc"
# Set up bind mount for trunk, so we can get to package repository
# TODO: also use this instead of SETUP_DIR for other things below?
sudo mkdir -p "$ROOT_FS_DIR/trunk"
sudo mount --bind "$GCLIENT_ROOT" "$ROOT_FS_DIR/trunk"
# Create setup directory and copy over scripts, config files, and locally
# built packages.
mkdir -p "$SETUP_DIR"
mkdir -p "${SETUP_DIR}/local_packages"
cp "${SCRIPTS_DIR}/${ROOTFS_CUSTOMIZE_SCRIPT}" "$SETUP_DIR"
cp "$FLAGS_pkglist" "${SETUP_DIR}/package-list-prod.txt"
cp "${FLAGS_build_root}/x86/local_packages"/* "${SETUP_DIR}/local_packages"
if [ -n "$FLAGS_pkglist2" ]
then
cp "$FLAGS_pkglist2" "${SETUP_DIR}/package-list-2.txt"
fi
# Set up repository for local packages to install in the rootfs via apt-get.
cd "$SETUP_DIR"
dpkg-scanpackages local_packages/ /dev/null | \
gzip > local_packages/Packages.gz
cd -
# File-type mirrors have a different path when bind-mounted inside the chroot
# ${FOO/bar/baz} replaces bar with baz when evaluating $FOO.
MIRROR_INSIDE="${FLAGS_mirror/$GCLIENT_ROOT//trunk}"
MIRROR2_INSIDE="${FLAGS_mirror2/$GCLIENT_ROOT//trunk}"
# Write options for customize script into the chroot
CUST_OPTS="${SETUP_DIR}/customize_opts.sh"
cat <<EOF > $CUST_OPTS
SETUP_DIR="$ROOTFS_SETUP_DIR"
USE_UBUNTU_KERNEL="$USE_UBUNTU_KERNEL"
SERVER="$MIRROR_INSIDE"
SUITE="$FLAGS_suite"
SERVER2="$MIRROR2_INSIDE"
SUITE2="$FLAGS_suite2"
EOF
# Also export ChromeOS version strings
set | grep "CHROMEOS_VERSION" >> $CUST_OPTS
# Run the setup script
sudo chroot "$ROOT_FS_DIR" "${ROOTFS_SETUP_DIR}/${ROOTFS_CUSTOMIZE_SCRIPT}"
# Move package lists from the image into the output dir
sudo mv "$ROOT_FS_DIR"/etc/package_list_*.txt "$OUTPUT_DIR"
# Unmount mounts within the rootfs so it is ready to be imaged.
cleanup_rootfs_mounts
# -- Turn root file system into bootable image --
# Setup extlinux configuration.
# TODO: For some reason the /dev/disk/by-uuid is not being generated by udev
# in the initramfs. When we figure that out, switch to root=UUID=$UUID.
cat <<EOF | sudo dd of="$ROOT_FS_DIR"/boot/extlinux.conf
DEFAULT chromeos-usb
PROMPT 0
TIMEOUT 0
label chromeos-usb
menu label chromeos-usb
kernel vmlinuz
append quiet console=tty2 initrd=initrd.img init=/sbin/init boot=local rootwait root=LABEL=$DISK_LABEL noresume noswap i915.modeset=1 loglevel=1
label chromeos-hd
menu label chromeos-hd
kernel vmlinuz
append quiet console=tty2 init=/sbin/init boot=local rootwait root=HDROOT ro noresume noswap i915.modeset=1 loglevel=1
EOF
# Make partition bootable and label it.
sudo "$SCRIPTS_DIR/extlinux.sh" -z --install "${ROOT_FS_DIR}/boot"
cleanup_rootfs_loop
# Create a master boot record.
# Start with the syslinux master boot record. We need to zero-pad to
# fill out a 512-byte sector size.
SYSLINUX_MBR="/usr/lib/syslinux/mbr.bin"
dd if="$SYSLINUX_MBR" of="$MBR_IMG" bs=512 count=1 conv=sync
# Create a partition table in the MBR.
NUM_SECTORS=$((`stat --format="%s" "$ROOT_FS_IMG"` / 512))
sudo sfdisk -H64 -S32 -uS -f "$MBR_IMG" <<EOF
,$NUM_SECTORS,L,*,
,$NUM_SECTORS,L,-,
,$NUM_SECTORS,S,-,
;
EOF
OUTSIDE_OUTPUT_DIR="~/chromeos/src/build/images/${IMAGE_SUBDIR}"
echo "Done. Image created in ${OUTPUT_DIR}"
echo "To copy to USB keyfob, outside the chroot, do something like:"
echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdb"
echo "To convert to VMWare image, outside the chroot, do something like:"
echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
trap - EXIT

173
build_kernel.sh Executable file
View File

@ -0,0 +1,173 @@
#! /bin/sh
# 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.
# This script contains the set of commands to build a kernel package.
#
# If successful, a new linux-image-*.deb file will appear in the specified
# output directory.
#
# The user-provided kernel config file is parsed to obtain information about
# the desired kernel version and target platform. Here are the requirements:
# 1) Kernel version string in the header, e.g. "Linux kernel version: 2.6.30"
# 2) Target architecture variables set up, e.g. CONFIG_X86, CONFIG_ARM, etc.
# 3) LOCALVERSION set to describe target platform (e.g. intel-menlow). This is
# used for package naming.
SRC_ROOT=$(dirname $(readlink -f $(dirname "$0")))
. "${SRC_ROOT}/third_party/shflags/files/src/shflags"
# Flags
DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"}
DEFINE_string config "config.2.6.30-chromeos-intel-menlow" \
"The kernel configuration file to use. See src/platform/kernel/config/*"
DEFINE_integer revision 002 \
"The package revision to use"
DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/x86/local_packages" \
"Directory in which to place the resulting .deb package"
DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \
"Root of build output"
FLAGS_HELP="Usage: $0 [flags] <deb_patch1> <deb_patch2> ..."
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on any errors.
set -e
KERNEL_DIR="$SRC_ROOT/third_party/kernel"
KCONFIG="${KERNEL_DIR}/config/${FLAGS_config}"
# TODO: We detect the ARCH below. We can sed the FLAGS_output_root to replace
# an ARCH placeholder with the proper architecture rather than assuming x86.
mkdir -p "$FLAGS_output_root"
# Use remaining arguments passed into the script as patch names. These are
# for non-chromeos debian-style patches. The chromeos patches will be applied
# manually below.
PATCHES="$*"
# Get kernel package configuration from repo.
# TODO: Find a workaround for needing sudo for this. Maybe create a symlink
# to /tmp/kernel-pkg.conf when setting up the chroot env?
sudo cp "$KERNEL_DIR"/package/kernel-pkg.conf /etc/kernel-pkg.conf
# Parse kernel config file for target architecture information. This is needed
# to determine the full package name and also to setup the environment for
# kernel build scripts which use "uname -m" to autodetect architecture.
if [ -n $(grep 'CONFIG_X86=y' "$KCONFIG") ]
then
ARCH="i386"
elif [ -n $(grep 'CONFIG_X86_64=y' "$KCONFIG") ]
then
ARCH="x86_64"
elif [ -n $(grep 'CONFIG_ARM=y' "$KCONFIG") ]
then
ARCH="arm"
else
exit 1
fi
# Parse the config file for a line with "version" in it (in the header)
# and remove any leading text before the major number of the kernel version
FULLVERSION=$(sed -e '/version/ !d' -e 's/^[^0-9]*//' $KCONFIG)
# FULLVERSION should have the form "2.6.30-rc1-chromeos-asus-eeepc". In this
# example MAJOR is 2, MINOR is 6, EXTRA is 30, RELEASE is rc1, LOCAL is
# asus-eeepc. RC is optional since it only shows up for release candidates.
MAJOR=$(echo $FULLVERSION | sed -e 's/[^0-9].*//')
MINOR=$(echo $FULLVERSION | sed -e 's/[0-9].//' -e 's/[^0-9].*//')
EXTRA=$(echo $FULLVERSION | sed -e 's/[0-9].//' -e 's/[0-9].//' -e 's/[^0-9].*//')
VER_MME="${MAJOR}.${MINOR}.${EXTRA}"
LOCAL=$(sed -e '/CONFIG_LOCALVERSION=/ !d' -e 's/.*="-//' -e 's/"//' $KCONFIG)
RC=$(echo $FULLVERSION | sed -r \
"s/${VER_MME}-([^-]*)-*${LOCAL}/\1/")
# The tag will be appended by make-kpkg to the extra version and will show up
# in both the kernel and package names.
CHROMEOS_TAG="chromeos"
PACKAGE="linux-image-${VER_MME}-${CHROMEOS_TAG}-${LOCAL}_${FLAGS_revision}_${ARCH}.deb"
# Set up kernel source tree and prepare to start the compilation.
# TODO: Decide on proper working directory when building kernels. It should
# be somewhere under ${BUILD_ROOT}.
SRCDIR="${FLAGS_build_root}/kernels/kernel-${ARCH}-${LOCAL}"
rm -rf "$SRCDIR"
mkdir -p "$SRCDIR"
cd "$SRCDIR"
# Get kernel sources and patches.
# TODO: find a better source for the kernel source. Old versions of karmic
# aren't hosted on archive.ubuntu.com
#apt-get source linux-source-$MAJOR.$MINOR.$EXTRA
tar -xzf "$KERNEL_DIR"/linux_${VER_MME}-*.tar.gz
# Rename directory to what the patches expect
mv ubuntu-* "linux-$VER_MME"
if [ ! -z $PATCHES ]
then
# TODO: Get rid of sudo if possible. Maybe the non-chromeos kernel patches
# will be infrequent enough that we can make them part of the chroot env?
sudo apt-get install $PATCHES
fi
# Apply chromeos patches
CHROMEOS_PATCHES=`ls "$KERNEL_DIR"/patches/*.patch`
for i in ${CHROMEOS_PATCHES}
do
patch -d "linux-$VER_MME" -p1 < "$i"
done
# Move kernel config to kernel source tree and rename to .config so that
# it can be used for "make oldconfig" by make-kpkg.
cp "$KCONFIG" "linux-${VER_MME}/.config"
cd "linux-$VER_MME"
# TODO: Remove a config option which references a non-existent directory in
# ubuntu kernel sources.
sed -i '/gfs/ d' ubuntu/Makefile
# Remove stale packages. make-kpkg will dump the package in the parent
# directory. From there, it will be moved to the output directory.
rm -f "../${PACKAGE}"
rm -f "${FLAGS_output_root}/${PACKAGE}"
# Speed up compilation by running parallel jobs.
if [ ! -e "/proc/cpuinfo" ]
then
# default to a reasonable level
CONCURRENCY_LEVEL=2
else
# speed up compilation by running #cpus * 2 simultaneous jobs
CONCURRENCY_LEVEL=$(($(cat /proc/cpuinfo | grep "processor" | wc -l) * 2))
fi
# The patch listing will be added into make-kpkg with --added-patches flag.
# We need to change the formatting so they are a comma-separated values list
# rather than whitespace separated.
PATCHES_CSV=$(echo $PATCHES | sed -e 's/ \{1,\}/,/g' | sed -e 's/,$//')
# Build the kernel and make package. "setarch" is used so that scripts which
# detect architecture (like the "oldconfig" rule in kernel Makefile) don't get
# confused when cross-compiling.
make-kpkg clean
MAKEFLAGS="CONCURRENCY_LEVEL=$CONCURRENCY_LEVEL" \
setarch $ARCH make-kpkg \
--append-to-version="-$CHROMEOS_TAG" --revision="$FLAGS_revision" \
--arch="$ARCH" \
--rootcmd fakeroot \
--config oldconfig \
--initrd --bzImage kernel_image \
--added-patches "$PATCHES_CSV"
# make-kpkg dumps the newly created package in the parent directory
if [ -e "../${PACKAGE}" ]
then
mv "../${PACKAGE}" "${FLAGS_output_root}"
echo "Kernel build successful, check ${FLAGS_output_root}/${PACKAGE}"
else
echo "Kernel build failed"
exit 1
fi

68
build_kernel_setup.sh Executable file
View File

@ -0,0 +1,68 @@
#!/bin/sh
# 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.
# This script will launch the kernel build script from outside a chroot
# environment and copy the kernel package into the chromeos source repository's
# src/platform/kernel directory.
set -e
SRC_ROOT=${SRC_ROOT:-$(cd "$(dirname $0)/.." ; pwd)}
KERNEL_DATA="${SRC_ROOT}/third_party/kernel" # version-controlled kernel stuff
BUILD_SCRIPT="build_kernel.sh"
KCONFIG="$1" # kernel config file
PKGREVISION="$2" # version number to stamp on the package
ROOTFS="$3" # development environment (fakeroot)
if [ $# -lt 3 ]
then
echo "usage: $0 <kernel_config> <package_revision> <rootfs> <patch>"
echo "kernel_config: Kernel config from ${KERNEL_DATA}/config/."
echo "package_revision: The revision to stamp on the final .deb package."
echo "rootfs: Root directory of build environment"
echo "remaining arguments are assumed to be kernel patch names"
echo -n "Usage example: sh build_kernel.sh config.2.6.30-rc8-chromeos-intel-"
echo "menlow 001 ~/src/chromeos/devenv"
echo ""
exit 1
fi
# Use remaining arguments as patch names.
shift; shift; shift
PATCHES="$*"
if [ ! -d "$ROOTFS" ]
then
echo "$ROOTFS is not a directory"
exit 1
fi
# Create a tmpfs to store output from build script which this script can copy
# the output from later on. We won't know the actual filename of the output
# but since this is a new namespace we're using it should be safe to use a use
# a wildcard (e.g. linux-image*.deb) without copying the wrong .debs.
OUTPUT_DIR="${ROOTFS}/tmp"
sudo mkdir -p "$OUTPUT_DIR"
sudo mount -t tmpfs size=32M "${OUTPUT_DIR}"
do_cleanup() {
sudo umount "${OUTPUT_DIR}"
}
trap do_cleanup EXIT
# Copy kernel build helper script to chroot environment
sudo cp "${SRC_ROOT}/scripts/${BUILD_SCRIPT}" "${ROOTFS}/tmp/"
# Run the build script.
sudo chroot "$ROOTFS" "/tmp/${BUILD_SCRIPT}" "$KCONFIG" \
"$PKGREVISION" "${OUTPUT_DIR#$ROOTFS}/" "$PATCHES"
# Copy kernel package from the output directory into Chrome OS sources
# before the cleanup routine clobbers it.
echo "Copying kernel to "$KERNEL_DATA""
cp -i "$OUTPUT_DIR"/linux-image*.deb "$KERNEL_DATA"
set +e

65
build_platform_packages.sh Executable file
View File

@ -0,0 +1,65 @@
#!/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.
# 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
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on error
set -e
PLATFORM_DIR="$SRC_ROOT/platform"
PLATFORM_DIRS="assets control_panel fake_hal init installer login_manager \
memento_softwareupdate pam_google window_manager \
control_panel cros chrome wifi screenlocker cryptohome"
THIRD_PARTY_DIR="$SRC_ROOT/third_party"
THIRD_PARTY_PACKAGES="connman e2fsprogs/files gflags gtest glog \
ply-image slim/src \
wpa_supplicant xscreensaver/xscreensaver-5.08 \
xserver-xorg-core xserver-xorg-video-intel"
# Build third_party packages first, since packages and libs depend on them.
for i in $THIRD_PARTY_PACKAGES
do
echo "Building package ${i}..."
cd "$THIRD_PARTY_DIR/$i"
./make_pkg.sh
cd -
done
# Build base lib next, since packages depend on it.
echo "Building base library..."
cd "$PLATFORM_DIR/base"
scons
cd -
#Build common lib next.
echo "Building common library..."
cd "$SRC_ROOT/common"
scons
cd -
# Build platform packages
for i in $PLATFORM_DIRS
do
echo "Building package ${i}..."
cd "$PLATFORM_DIR/$i"
./make_pkg.sh
cd -
done
echo "All packages built."

32
build_tests.sh Executable file
View File

@ -0,0 +1,32 @@
#!/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.
# 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"
# Flags
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on error; print commands
set -e
PLATFORM_DIR="$SRC_ROOT/platform"
PLATFORM_DIRS="pam_google window_manager cryptohome"
# Build tests
for i in $PLATFORM_DIRS
do
echo "building $PLATFORM_DIR/$i"
cd "$PLATFORM_DIR/$i"
./make_tests.sh
cd -
done
echo "All tests built."

60
chromeos_version.sh Executable file
View File

@ -0,0 +1,60 @@
#!/bin/sh
# 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.
# ChromeOS version information
#
# This file is usually sourced by other build scripts, but can be run
# directly to see what it would do.
#
# Version numbering scheme is much like Chrome's, with the addition of
# double-incrementing branch number so trunk is always odd.
# Major/minor versions.
# Primarily for product marketing.
export CHROMEOS_VERSION_MAJOR=0
export CHROMEOS_VERSION_MINOR=2
# Branch number.
# Increment by 1 in a new release branch.
# Increment by 2 in trunk after making a release branch.
# Does not reset on a major/minor change (always increases).
# (Trunk is always odd; branches are always even).
export CHROMEOS_VERSION_BRANCH=13
# Patch number.
# Increment by 1 each release on a branch.
# Reset to 0 when increasing branch number.
export CHROMEOS_VERSION_PATCH=0
# Codename of this version
export CHROMEOS_VERSION_CODENAME="Indy"
# Version string
export CHROMEOS_VERSION_STRING=\
"${CHROMEOS_VERSION_MAJOR}.${CHROMEOS_VERSION_MINOR}"\
".${CHROMEOS_VERSION_BRANCH}.${CHROMEOS_VERSION_PATCH}"
# Official builds must set
# CHROMEOS_OFFICIAL=1
# CHROMEOS_REVISION=(the subversion revision being built).
# Note that ${FOO:-0} means default-to-0-if-unset; ${FOO:?} means die-if-unset.
if [ ${CHROMEOS_OFFICIAL:-0} -eq 1 ]
then
# Official builds (i.e., buildbot)
export CHROMEOS_VERSION_NAME="Chrome OS"
export CHROMEOS_VERSION_TRACK="dev-channel"
# CHROMEOS_REVISION must be set in the environment for official builds
export CHROMEOS_VERSION_DESCRIPTION="${CHROMEOS_VERSION_STRING} (Official Build ${CHROMEOS_REVISION:?})"
else
# Continuous builds and developer hand-builds
export CHROMEOS_VERSION_NAME="Chromium OS"
export CHROMEOS_VERSION_TRACK="developer-build"
export CHROMEOS_VERSION_DESCRIPTION="${CHROMEOS_VERSION_STRING} (Developer Build - $(date))"
fi
# Print version info
echo "ChromeOS version information:"
set | grep "CHROMEOS_VERSION" | sed 's/^/ /'

185
common.sh Normal file
View File

@ -0,0 +1,185 @@
# 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.
# Common constants for build scripts
# This must evaluate properly for both /bin/bash and /bin/sh
# All scripts should die on error unless commands are specifically excepted
# by prefixing with '!' or surrounded by 'set +e' / 'set -e'.
# TODO: Re-enable this once shflags is less prone to dying.
#set -e
# The number of jobs to pass to tools that can run in parallel (such as make
# and dpkg-buildpackage
NUM_JOBS=`cat /proc/cpuinfo | grep processor | awk '{a++} END {print a}'`
# Store location of the calling script.
TOP_SCRIPT_DIR="${TOP_SCRIPT_DIR:-$(dirname $0)}"
# Find root of source tree
if [ "x$GCLIENT_ROOT" != "x" ]
then
# GCLIENT_ROOT already set, so we're done
true
elif [ "x$COMMON_SH" != "x" ]
then
# COMMON_SH set, so assume that's us
GCLIENT_ROOT="$(dirname "$COMMON_SH")/../.."
elif [ "x$BASH_SOURCE" != "x" ]
then
# Using bash, so we can find ourselves
GCLIENT_ROOT="$(dirname "$BASH_SOURCE")/../.."
else
# Using dash or sh, we don't know where we are. $0 refers to the calling
# script, not ourselves, so that doesn't help us.
echo "Unable to determine location for common.sh. If you are sourcing"
echo "common.sh from a script run via dash or sh, you must do it in the"
echo "following way:"
echo ' COMMON_SH="$(dirname "$0")/../../scripts/common.sh"'
echo ' . "$COMMON_SH"'
echo "where the first line is the relative path from your script to"
echo "common.sh."
exit 1
fi
# Canonicalize the directories for the root dir and the calling script.
# readlink is part of coreutils and should be present even in a bare chroot.
# This is better than just using
# FOO = "$(cd $FOO ; pwd)"
# since that leaves symbolic links intact.
# Note that 'realpath' is equivalent to 'readlink -f'.
TOP_SCRIPT_DIR=`readlink -f $TOP_SCRIPT_DIR`
GCLIENT_ROOT=`readlink -f $GCLIENT_ROOT`
# Other directories should always be pathed down from GCLIENT_ROOT.
SRC_ROOT="$GCLIENT_ROOT/src"
SRC_INTERNAL="$GCLIENT_ROOT/src-internal"
SCRIPTS_DIR="$SRC_ROOT/scripts"
# Load developer's custom settings. Default location is in scripts dir,
# since that's available both inside and outside the chroot. By convention,
# settings from this file are variables starting with 'CHROMEOS_'
CHROMEOS_DEV_SETTINGS="${CHROMEOS_DEV_SETTINGS:-$SCRIPTS_DIR/.chromeos_dev}"
if [ -f $CHROMEOS_DEV_SETTINGS ]
then
# Turn on exit-on-error during custom settings processing
SAVE_OPTS=`set +o`
set -e
# Read settings
. $CHROMEOS_DEV_SETTINGS
# Restore previous state of exit-on-error
eval "$SAVE_OPTS"
fi
# Load shflags
. "$SRC_ROOT/third_party/shflags/files/src/shflags"
# Mirrors and build suites come in 3 flavors
# EXT - external source used to build local package repository
# DEV - development chroot, from local package repository
# IMG - bootable image, from local package repository
# Build suites
DEFAULT_EXT_SUITE=${CHROMEOS_EXT_SUITE:-"chromeos_dev"}
DEFAULT_DEV_SUITE=${CHROMEOS_DEV_SUITE:-"chromeos_dev"}
DEFAULT_IMG_SUITE=${CHROMEOS_IMG_SUITE:-"chromeos"}
# Package repositories (mirrors)
DEFAULT_EXT_MIRROR=${CHROMEOS_EXT_MIRROR:-"http://build.chromium.org/buildbot/packages"}
DEFAULT_DEV_MIRROR=${CHROMEOS_DEV_MIRROR:-"file://$GCLIENT_ROOT/repo/apt"}
DEFAULT_IMG_MIRROR=${CHROMEOS_IMG_MIRROR:-"file:///home/$USER/trunk/repo/apt"}
# Default location for chroot
DEFAULT_CHROOT_DIR=${CHROMEOS_CHROOT_DIR:-"$GCLIENT_ROOT/chroot"}
# All output files from build should go under $DEFAULT_BUILD_ROOT, so that
# they don't pollute the source directory.
DEFAULT_BUILD_ROOT=${CHROMEOS_BUILD_ROOT:-"$SRC_ROOT/build"}
# Detect whether we're inside a chroot or not
if [ -e /etc/debian_chroot ]
then
INSIDE_CHROOT=1
else
INSIDE_CHROOT=0
fi
# Directory locations inside the dev chroot
CHROOT_TRUNK_DIR="/home/$USER/trunk"
# -----------------------------------------------------------------------------
# Functions
# Make a package
function make_pkg_common {
# Positional parameters from calling script. :? means "fail if unset".
set -e
PKG_BASE=${1:?}
shift
set +e
# All packages are built in the chroot
assert_inside_chroot
# Command line options
DEFINE_string build_root "$DEFAULT_BUILD_ROOT" "Root of build output"
# Parse command line and update positional args
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on any errors
set -e
# Make output dir
OUT_DIR="$FLAGS_build_root/x86/local_packages"
mkdir -p "$OUT_DIR"
# Remove previous package from output dir
rm -f "$OUT_DIR"/${PKG_BASE}_*.deb
# Rebuild the package
pushd "$TOP_SCRIPT_DIR"
rm -f ../${PKG_BASE}_*.deb
dpkg-buildpackage -b -tc -us -uc -j$NUM_JOBS
mv ../${PKG_BASE}_*.deb "$OUT_DIR"
rm ../${PKG_BASE}_*.changes
popd
}
# Fail unless we're inside the chroot. This guards against messing up your
# workstation.
function assert_inside_chroot {
if [ $INSIDE_CHROOT -ne 1 ]
then
echo "This script must be run inside the chroot. Run this first:"
echo " $SCRIPTS_DIR/enter_chroot.sh"
exit 1
fi
}
# Fail if we're inside the chroot. This guards against creating or entering
# nested chroots, among other potential problems.
function assert_outside_chroot {
if [ $INSIDE_CHROOT -ne 0 ]
then
echo "This script must be run outside the chroot."
exit 1
fi
}
# Install a package if it's not already installed
function install_if_missing {
# Positional parameters from calling script. :? means "fail if unset".
PKG_NAME=${1:?}
shift
if [ -z `which $PKG_NAME` ]
then
echo "Can't find $PKG_NAME; attempting to install it."
sudo apt-get --yes --force-yes install $PKG_NAME
fi
}

445
customize_rootfs.sh Executable file
View File

@ -0,0 +1,445 @@
#!/bin/sh
# 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.
# Sets up the chromeos distribution from inside a chroot of the root fs.
# NOTE: This script should be called by build_image.sh. Do not run this
# on your own unless you know what you are doing.
set -e
# Read options from the config file created by build_image.sh.
echo "Reading options..."
cat "$(dirname $0)/customize_opts.sh"
. "$(dirname $0)/customize_opts.sh"
PACKAGE_LIST_FILE="${SETUP_DIR}/package-list-prod.txt"
PACKAGE_LIST_FILE2="${SETUP_DIR}/package-list-2.txt"
COMPONENTS=`cat $PACKAGE_LIST_FILE | grep -v ' *#' | grep -v '^ *$' | sed '/$/{N;s/\n/ /;}'`
FULLNAME="ChromeOS User"
USERNAME="chronos"
ADMIN_GROUP="admin"
DEFGROUPS="adm,dialout,cdrom,floppy,audio,dip,video"
ADMIN_USERNAME="chronosdev"
CRYPTED_PASSWD_FILE="/trunk/src/scripts/shared_user_passwd.txt"
if [ -f $CRYPTED_PASSWD_FILE ]
then
echo "Using password from $CRYPTED_PASSWD_FILE"
CRYPTED_PASSWD=$(cat $CRYPTED_PASSWD_FILE)
else
# Use a random password. unix_md5_crypt will generate a random salt.
echo "Using random password."
PASSWORD="$(base64 /dev/urandom | head -1)"
CRYPTED_PASSWD="$(echo "$PASSWORD" | openssl passwd -1 -stdin)"
PASSWORD="gone now"
fi
# Set google-specific version numbers:
# CHROMEOS_RELEASE_CODENAME is the codename of the release.
# CHROMEOS_RELEASE_DESCRIPTION is the version displayed by Chrome; see
# chrome/browser/chromeos/chromeos_version_loader.cc.
# CHROMEOS_RELEASE_NAME is a human readable name for the build.
# CHROMEOS_RELEASE_TRACK and CHROMEOS_RELEASE_VERSION are used by the software
# update service.
# TODO(skrul): Remove GOOGLE_RELEASE once Chromium is updated to look at
# CHROMEOS_RELEASE_VERSION for UserAgent data.
cat <<EOF >> /etc/lsb-release
CHROMEOS_RELEASE_CODENAME=$CHROMEOS_VERSION_CODENAME
CHROMEOS_RELEASE_DESCRIPTION=$CHROMEOS_VERSION_DESCRIPTION
CHROMEOS_RELEASE_NAME=$CHROMEOS_VERSION_NAME
CHROMEOS_RELEASE_TRACK=$CHROMEOS_VERSION_TRACK
CHROMEOS_RELEASE_VERSION=$CHROMEOS_VERSION_STRING
GOOGLE_RELEASE=$CHROMEOS_VERSION_STRING
EOF
# Set the default X11 cursor theme to inherit our cursors.
mkdir -p /usr/share/icons/default
cat <<EOF > /usr/share/icons/default/index.theme
[Icon Theme]
Inherits=chromeos-cursors
EOF
# Create the admin group and a chronos user that can act as admin.
groupadd ${ADMIN_GROUP}
echo "%admin ALL=(ALL) ALL" >> /etc/sudoers
useradd -G "${ADMIN_GROUP},${DEFGROUPS}" -g ${ADMIN_GROUP} -s /bin/bash -m \
-c "${FULLNAME}" -p ${CRYPTED_PASSWD} ${USERNAME}
# Create a directory inside of the user's home directory for storing logs.
USER_LOG_DIR=/home/${USERNAME}/logs
mkdir ${USER_LOG_DIR}
chown ${USERNAME}:${ADMIN_GROUP} ${USER_LOG_DIR}
chmod 755 ${USER_LOG_DIR}
# Create a .xsession file to start session programs.
USER_XSESSION_FILE=/home/${USERNAME}/.xsession
cat <<EOF > ${USER_XSESSION_FILE}
#!/bin/sh
BACKGROUND_FILE=background_1024x600.png
if [ -e /tmp/use_ugly_x_cursor ]; then
BACKGROUND_FILE=background_1024x600_retro.png
fi
WM=/usr/bin/chromeos-wm
IMAGES=/usr/share/chromeos-assets/images
BACKGROUND="\${IMAGES}/\${BACKGROUND_FILE}"
LOG_DIR="\${HOME}/logs"
CHROME_COMMAND="/usr/bin/chromeos-chrome"
/usr/bin/xscreensaver -no-splash &
python /opt/google/controlpanel/webapp.py &
exec "\${WM}" \\
--hotkey_overlay_image_dir="\${IMAGES}" \\
--panel_anchor_image="\${IMAGES}/panel_anchor.png" \\
--panel_bar_image="\${IMAGES}/panel_bar_bg.png" \\
--shadow_image_dir="\${IMAGES}" \\
--wm_background_image="\${BACKGROUND}" \\
--wm_chrome_command="\${CHROME_COMMAND}" \\
--wm_spawn_chrome_on_start=true \\
--v=1 \\
--log_dir="\${LOG_DIR}"
EOF
chown ${USERNAME}:${ADMIN_GROUP} ${USER_XSESSION_FILE}
chmod 700 ${USER_XSESSION_FILE}
# Create apt source.list
cat <<EOF > /etc/apt/sources.list
deb file:"$SETUP_DIR" local_packages/
deb $SERVER $SUITE main restricted multiverse universe
EOF
# Install prod packages
apt-get update
apt-get --yes --force-yes install $COMPONENTS
if [ "$SUITE" = "jaunty" ]
then
# Additional driver modules needed for chromeos-wifi on jaunty.
apt-get --yes --force-yes install linux-backports-modules-jaunty
fi
# Create kernel installation configuration to suppress warnings,
# install the kernel in /boot, and manage symlinks.
cat <<EOF > /etc/kernel-img.conf
link_in_boot = yes
do_symlinks = yes
minimal_swap = yes
clobber_modules = yes
warn_reboot = no
do_bootloader = no
do_initrd = yes
warn_initrd = no
EOF
if [ $USE_UBUNTU_KERNEL -eq 1 ]
then
KERNEL_VERSION="2.6.30-9-generic"
else
KERNEL_VERSION="2.6.30-chromeos-intel-menlow"
fi
apt-get --yes --force-yes install "linux-image-${KERNEL_VERSION}"
# Create custom initramfs
# TODO: Remove when we switch to dhendrix kernel for good.
if [ $USE_UBUNTU_KERNEL -eq 1 ]
then
cat <<EOF >> /etc/initramfs-tools/modules
intel_agp
drm
i915 modeset=1
EOF
update-initramfs -u
fi
cat <<EOF > /etc/network/interfaces
auto lo
iface lo inet loopback
EOF
cat <<EOF > /etc/resolv.conf
# Use the connman dns proxy.
nameserver 127.0.0.1
EOF
chmod a-wx /etc/resolv.conf
# If we don't create generic udev rules, then udev will try to save the
# history of various devices (i.e. always associate a given device and MAC
# address with the same wlan number). As we use a keyfob across different
# machines the ethN and wlanN keep changing.
cat <<EOF >> /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"
EOF
# Setup bootchart. Due to dependencies, this adds about 180MB!
apt-get --yes --force-yes install bootchart
# Bootchart has been dying from a SIGHUP partway through boot. Daemonize it
# so that it won't get HUP'd
# TODO(tedbo): Remove when fixed upstream.
if [ -f /etc/init.d/bootchart ]
then
sed -i 's^/lib/bootchart/collector \$HZ \$LOGS 2>/dev/null \&^start-stop-daemon --background --start --exec /lib/bootchart/collector -- \$HZ \$LOGS^' \
/etc/init.d/bootchart
fi
# Install additional packages from a second mirror, if necessary. This must
# be done after all packages from the first repository are installed; after
# the apt-get update, apt-get and debootstrap will prefer the newest package
# versions (which are probably on this second mirror).
if [ -f "$PACKAGE_LIST_FILE2" ]
then
COMPONENTS2=`cat $PACKAGE_LIST_FILE2 | grep -v ' *#' | grep -v '^ *$' | sed '/$/{N;s/\n/ /;}'`
echo "deb $SERVER2 $SUITE2 main restricted multiverse universe" \
>> /etc/apt/sources.list
apt-get update
apt-get --yes --force-yes install $COMPONENTS2
fi
# List all packages installed so far, since these are what the local
# repository needs to contain.
# TODO: better place to put the list. Must still exist after the chroot
# is dismounted, so build_image.sh can get it. That rules out /tmp and
# $SETUP_DIR (which is under /tmp).
sudo sh -c "/trunk/src/scripts/list_installed_packages.sh \
> /etc/package_list_installed.txt"
# Remove unused packages.
# TODO: How are these getting on our image, anyway?
set +e
dpkg -l | grep pulseaudio | awk '{ print $2 }' | xargs dpkg --purge
dpkg -l | grep conkeror | awk '{ print $2 }' | xargs dpkg --purge
# TODO(rspangler): fix uninstall steps which fail at tip
#dpkg -l | grep xulrunner | awk '{ print $2 }' | xargs dpkg --purge
set -e
# Clean up other useless stuff created as part of the install process.
rm -f /var/cache/apt/archives/*.deb
rm -rf "$SETUP_DIR"
# Fix issue where alsa-base (dependency of alsa-utils) is messing up our sound
# drivers. The stock modprobe settings worked fine.
# TODO: Revisit when we have decided on how sound will work on chromeos.
rm /etc/modprobe.d/alsa-base.conf
# -- Remove unneeded fonts and set default gtk font --
UNNEEDED_FONTS_TYPES=$(ls -d /usr/share/fonts/* | grep -v truetype)
UNNEEDED_TRUETYPE_FONTS=$(ls -d /usr/share/fonts/truetype/* | grep -v ttf-droid)
for i in $UNNEEDED_FONTS_TYPES $UNNEEDED_TRUETYPE_FONTS
do
rm -rf "$i"
done
# set default gtk font:
cat <<EOF > /etc/gtk-2.0/gtkrc
gtk-font-name="DroidSans 8"
EOF
# -- Handle closelid/power button events to perform shutdown --
mkdir -p /etc/acpi/events
cat <<EOF > /etc/acpi/events/lidbtn
event=button[ /]lid
action=/etc/acpi/lid.sh
EOF
cat <<EOF > /etc/acpi/lid.sh
#!/bin/sh
# On lid close:
# - lock the screen
/usr/bin/xscreensaver-command -l
# - suspend the cryptohome device
#CRYPTOHOME=/dev/mapper/cryptohome
#/usr/bin/test -b $CRYPTOHOME && /sbin/dmsetup suspend $CRYPTOHOME
# - suspend to ram
echo -n mem > /sys/power/state
# On lid open:
# - resume cryptohome device
#/usr/bin/test -b $CRYPTOHOME && /sbin/dmsetup resume $CRYPTOHOME
EOF
chmod 0755 /etc/acpi/lid.sh
cat <<EOF > /etc/acpi/events/powerbtn
event=button[ /]power
action=/etc/acpi/powerbtn.sh
EOF
cat <<EOF > /etc/acpi/powerbtn.sh
#!/bin/sh
# shutdown on power button
shutdown -h now
EOF
chmod 0755 /etc/acpi/powerbtn.sh
# -- Handle hotkeys --
# TODO(tedbo): This is specific to eeepc. Also, on the eee we can get all
# of the hotkeys except for the sleep one. Handle those?
cat <<EOF > /etc/acpi/events/hotkeys
event=hotkey ATKD
action=/etc/acpi/hotkeys.sh %e
EOF
cat <<EOF > /etc/acpi/hotkeys.sh
#!/bin/sh
case \$3 in
00000013) # Toggle sound
amixer set LineOut toggle
amixer set iSpeaker toggle
;;
00000014) # Decrease volume
amixer set LineOut 5%-
;;
00000015) # Increase volume
amixer set LineOut 5%+
;;
esac
EOF
chmod 0755 /etc/acpi/hotkeys.sh
# -- Some boot performance customizations --
# Setup our xorg.conf. This allows us to avoid HAL overhead.
# TODO: Per-device xorg.conf rather than in this script.
cat <<EOF > /etc/X11/xorg.conf
Section "ServerFlags"
Option "AutoAddDevices" "false"
Option "DontZap" "false"
EndSection
Section "InputDevice"
Identifier "Keyboard1"
Driver "kbd"
Option "AutoRepeat" "250 30"
Option "XkbRules" "xorg"
Option "XkbModel" "pc104"
Option "CoreKeyboard"
EndSection
Section "InputDevice"
Identifier "Mouse1"
Driver "synaptics"
Option "SendCoreEvents" "true"
Option "Protocol" "auto-dev"
Option "SHMConfig" "on"
Option "CorePointer"
Option "MinSpeed" "0.2"
Option "MaxSpeed" "0.5"
Option "HorizScrollDelta" "100"
Option "VertScrollDelta" "100"
Option "HorizEdgeScroll" "0"
Option "VertEdgeScroll" "1"
Option "TapButton1" "1"
Option "TapButton2" "2"
Option "MaxTapTime" "180"
Option "FingerLow" "24"
Option "FingerHigh" "50"
EndSection
# Everything after this point was added to include support for USB as a
# secondary mouse device.
Section "InputDevice"
Identifier "USBMouse"
Driver "mouse"
Option "Device" "/dev/input/mice" # multiplexed HID mouse input device
Option "Protocol" "IMPS/2"
Option "ZAxisMapping" "4 5" # support a wheel as buttons 4 and 5
Option "Emulate3Buttons" "true" # just in case it is a 2 button
EndSection
# Defines a non-default server layout which pulls in the USB Mouse as a
# secondary input device.
Section "ServerLayout"
Identifier "DefaultLayout"
# Screen "DefaultScreen"
InputDevice "Mouse1" "CorePointer"
InputDevice "USBMouse" "AlwaysCore"
InputDevice "Keyboard1" "CoreKeyboard"
EndSection
EOF
# The udev daemon takes a long time to start up and settle. We modify the
# udev init script to settle in the backround, but in order to be able to
# mount the root file system and start X we pre-propulate some devices.
# Our rcS script copies whatever devices are in /lib/udev/devices
# to the tmpfs /dev well before we start udev, so we need to disable
# the copy step that is in the udev start script.
sed -i '{ s/# This next bit can take a while/&\n\{/ }' \
/etc/init.d/udev # Add '{' after the comment line.
sed -i '{ s/kill $UDEV_MONITOR_PID/&\n\} \&/ }' \
/etc/init.d/udev # Add '} &' after the kill line.
sed -i '{ s^cp -a -f /lib/udev/devices/\* /dev^^ }' \
/etc/init.d/udev # Remove step that prepopulates /dev
UDEV_DEVICES=/lib/udev/devices
mkdir "$UDEV_DEVICES"/dri
mkdir "$UDEV_DEVICES"/input
mknod --mode=0660 "$UDEV_DEVICES"/tty0 c 4 0
mknod --mode=0660 "$UDEV_DEVICES"/tty1 c 4 1
mknod --mode=0660 "$UDEV_DEVICES"/tty2 c 4 2
mknod --mode=0666 "$UDEV_DEVICES"/tty c 5 0
mknod --mode=0666 "$UDEV_DEVICES"/ptmx c 5 2
mknod --mode=0640 "$UDEV_DEVICES"/mem c 1 1
mknod --mode=0666 "$UDEV_DEVICES"/zero c 1 5
mknod --mode=0666 "$UDEV_DEVICES"/random c 1 8
mknod --mode=0666 "$UDEV_DEVICES"/urandom c 1 9
mknod --mode=0660 "$UDEV_DEVICES"/sda b 8 0
mknod --mode=0660 "$UDEV_DEVICES"/sda1 b 8 1
mknod --mode=0660 "$UDEV_DEVICES"/sda2 b 8 2
mknod --mode=0660 "$UDEV_DEVICES"/sda3 b 8 3
mknod --mode=0660 "$UDEV_DEVICES"/sda4 b 8 4
mknod --mode=0660 "$UDEV_DEVICES"/fb0 c 29 0
mknod --mode=0660 "$UDEV_DEVICES"/dri/card0 c 226 0
mknod --mode=0640 "$UDEV_DEVICES"/input/mouse0 c 13 32
mknod --mode=0640 "$UDEV_DEVICES"/input/mice c 13 63
mknod --mode=0640 "$UDEV_DEVICES"/input/event0 c 13 64
mknod --mode=0640 "$UDEV_DEVICES"/input/event1 c 13 65
mknod --mode=0640 "$UDEV_DEVICES"/input/event2 c 13 66
mknod --mode=0640 "$UDEV_DEVICES"/input/event3 c 13 67
mknod --mode=0640 "$UDEV_DEVICES"/input/event4 c 13 68
mknod --mode=0640 "$UDEV_DEVICES"/input/event5 c 13 69
mknod --mode=0640 "$UDEV_DEVICES"/input/event6 c 13 70
mknod --mode=0640 "$UDEV_DEVICES"/input/event7 c 13 71
mknod --mode=0640 "$UDEV_DEVICES"/input/event8 c 13 72
chown root.tty "$UDEV_DEVICES"/tty*
chown root.kmem "$UDEV_DEVICES"/mem
chown root.disk "$UDEV_DEVICES"/sda*
chown root.video "$UDEV_DEVICES"/fb0
chown root.video "$UDEV_DEVICES"/dri/card0
chmod 0666 "$UDEV_DEVICES"/null # Fix misconfiguration of /dev/null
# Since we may mount read-only, our mtab should symlink to /proc
ln -sf /proc/mounts /etc/mtab
# We don't need last-good-boot if it exits
rm -f /etc/init/last-good-boot.conf
# Don't create all of the virtual consoles
rm -f /etc/init/tty1.conf
rm -f /etc/init/tty[3-6].conf
sed -i '{ s:ACTIVE_CONSOLES=.*:ACTIVE_CONSOLES="/dev/tty2": }' \
/etc/default/console-setup
# We don't use the rc.conf that triggers scripts in /etc/rc?.d/
rm -f /etc/init/rc.conf
# Start X on vt01
sed -i '{ s/xserver_arguments .*/xserver_arguments -nolisten tcp vt01/ }' \
/etc/slim.conf
# Use our own rcS init script
mv /etc/init.d/rcS /etc/init.d/rcS.orig
ln -s /etc/init.d/chromeos_init.sh /etc/init.d/rcS
# Add some tmpfs filesystems to fstab to enable Memento semantics
cat <<EOF >> /etc/fstab
tmpfs /tmp tmpfs rw,nosuid,nodev 0 0
tmphomedir /home/chronos tmpfs rw,nosuid,nodev 0 0
EOF
# List all packages still installed post-pruning
sudo sh -c "/trunk/src/scripts/list_installed_packages.sh \
> /etc/package_list_pruned.txt"

126
enter_chroot.sh Executable file
View File

@ -0,0 +1,126 @@
#!/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 enter the chroot environment
# 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 outside the chroot
assert_outside_chroot
# Define command line flags
# See http://code.google.com/p/shflags/wiki/Documentation10x
DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \
"The destination dir for the chroot environment." "d"
DEFINE_string trunk "$GCLIENT_ROOT" \
"The source trunk to bind mount within the chroot." "s"
DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts."
DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts."
DEFINE_boolean svn_rev $FLAGS_FALSE "Pass subversion revision into chroot."
# More useful help
FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"]
One or more VAR=value pairs can be specified to export variables into
the chroot environment. For example:
$0 FOO=bar BAZ=bel
If [-- \"command\"] is present, runs the command inside the chroot,
after changing directory to /$USER/trunk/src/scripts. Note that the
command should be enclosed in quotes to prevent interpretation by the
shell before getting into the chroot. For example:
$0 -- \"./build_platform_packages.sh\"
Otherwise, provides an interactive shell.
"
# Parse command line flags
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'set -e' is specified before now.
# TODO: replace shflags with something less error-prone, or contribute a fix.
set -e
function setup_env {
echo "Mounting chroot environment."
# Mount only if not already mounted
MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")"
if [ -z "$(mount | grep -F "on $MOUNTED_PATH")" ]
then
sudo mount none -t proc "$MOUNTED_PATH"
fi
MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/dev/pts")"
if [ -z "$(mount | grep -F "on $MOUNTED_PATH")" ]
then
sudo mount none -t devpts "$MOUNTED_PATH"
fi
MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")"
if [ -z "$(mount | grep -F "on $MOUNTED_PATH")" ]
then
sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH"
fi
}
function teardown_env {
echo "Unmounting chroot environment."
mount | grep "on $(readlink -f "$FLAGS_chroot")" | awk '{print $3}' \
| xargs -r -L1 sudo umount
}
if [ $FLAGS_mount -eq $FLAGS_TRUE ]
then
setup_env
echo "Make sure you run"
echo " $0 --unmount"
echo "before deleting $FLAGS_chroot"
echo "or you'll end up deleting $FLAGS_trunk too!"
exit 0
fi
if [ $FLAGS_unmount -eq $FLAGS_TRUE ]
then
teardown_env
exit 0
fi
# Make sure we unmount before exiting
trap teardown_env EXIT
setup_env
if [ $FLAGS_svn_rev -eq $FLAGS_TRUE ]
then
# Get the subversion revision to pass into the chroot.
#
# This must be determined outside the chroot because (1) there is no
# svn inside the chroot, and (2) if there were it would likely be
# the wrong version, which would mess up the .svn directories.
#
# Note that this fixes $CHROMEOS_REVISION at the time the chroot is
# entered. That's ok for the main use case of automated builds,
# which pass each command line into a separate call to enter_chroot
# so always have up-to-date info. For developer builds, there isn't
# really a single revision anyway, since the developer may have
# hand-sync'd some subdirs and edited files in others.
SVNREV="CHROMEOS_REVISION=$(svn info | grep "Revision: " | awk '{print $2}')"
fi
# Run command or interactive shell
sudo chroot "$FLAGS_chroot" sudo -i -u $USER $SVNREV "$@"
# Remove trap and explicitly unmount
trap - EXIT
teardown_env

32
extlinux.sh Executable file
View File

@ -0,0 +1,32 @@
#!/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.
# Runs our own version of extlinux, which is in the third_party directory.
# Our version is quieter and faster. extlinux will be compiled if it's not
# already.
set -e
SCRIPTS_ROOT=`dirname "$0"`
THIRD_PARTY="${SCRIPTS_ROOT}/../third_party"
BUILD_ROOT=${BUILD_ROOT:-${SCRIPTS_ROOT}/../build}
EXTLINUX_BIN="$BUILD_ROOT"/x86/obj/src/third_party/syslinux/syslinux-*/extlinux/extlinux
echo bin is "$EXTLINUX_BIN"
if [ ! -e $EXTLINUX_BIN ]
then
# compile extlinux
(cd "$SCRIPTS_ROOT/../third_party/syslinux"/syslinux-*/ && make)
if [ ! -e $EXTLINUX_BIN ]
then
echo "Can't find or compile extlinux. Sorry."
exit 1
fi
fi
# we don't want ""s around $* b/c that will group all args into a single arg
$EXTLINUX_BIN $*

87
image_to_usb.sh Executable file
View File

@ -0,0 +1,87 @@
#!/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 convert the output of build_image.sh to a usb image.
# 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"
IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images"
# Default to the most recent image
DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`"
# Script can be run either inside or outside the chroot.
if [ $INSIDE_CHROOT -eq 1 ]
then
# Inside the chroot, so output to usb.img in the same dir as the other
# images.
DEFAULT_TO="${DEFAULT_FROM}/usb.img"
DEFAULT_TO_HELP="Destination file for USB image."
else
# Outside the chroot, so output to the default device for a usb key.
DEFAULT_TO="/dev/sdb"
DEFAULT_TO_HELP="Destination device for USB keyfob."
fi
# Flags
DEFINE_string from "$DEFAULT_FROM" \
"Directory containing rootfs.image and mbr.image"
DEFINE_string to "$DEFAULT_TO" "$DEFAULT_TO_HELP"
DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" "y"
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on any errors.
set -e
# Convert args to paths. Need eval to un-quote the string so that shell
# chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work.
FLAGS_from=`eval readlink -f $FLAGS_from`
FLAGS_to=`eval readlink -f $FLAGS_to`
# Copy MBR and rootfs to output image
if [ -b "$FLAGS_to" ]
then
# Output to a block device (i.e., a real USB key), so need sudo dd
echo "Copying USB image ${FLAGS_from} to device ${FLAGS_to}..."
# Make sure this is really what the user wants, before nuking the device
if [ $FLAGS_yes -ne $FLAGS_TRUE ]
then
echo "This will erase all data on this device:"
sudo fdisk -l "$FLAGS_to" | grep Disk | head -1
read -p "Are you sure (y/N)? " SURE
SURE="${SURE:0:1}" # Get just the first character
if [ "$SURE" != "y" ]
then
echo "Ok, better safe than sorry."
exit 1
fi
fi
sudo bash -c "cat \"${FLAGS_from}/mbr.image\" \
\"${FLAGS_from}/rootfs.image\" \
| dd of=\"$FLAGS_to\" bs=4M"
sync
echo "Done."
else
# Output to a file, so just cat the source images together
echo "Copying USB image to file ${FLAGS_to}..."
cat "${FLAGS_from}/mbr.image" "${FLAGS_from}/rootfs.image" > "$FLAGS_to"
echo "Done. To copy to USB keyfob, outside the chroot, do something like:"
echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M"
echo "where /dev/sdb is the entire keyfob."
if [ $INSIDE_CHROOT -eq 1 ]
then
echo "NOTE: Since you are currently inside the chroot, and you'll need to"
echo "run dd outside the chroot, the path to the USB image will be"
echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/usb.img)."
fi
fi

42
image_to_vmware.sh Executable file
View File

@ -0,0 +1,42 @@
#!/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 convert the output of build_image.sh to a VMware image.
# 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"
IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images"
# Default to the most recent image
DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`"
DEFAULT_TO="${DEFAULT_FROM}/ide.vmdk"
# Flags
DEFINE_string from "$DEFAULT_FROM" \
"Directory containing rootfs.image and mbr.image"
DEFINE_string to "$DEFAULT_TO" \
"Destination file for VMware image"
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on any errors.
set -e
# Convert args to paths. Need eval to un-quote the string so that shell
# chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work.
FLAGS_from=`eval readlink -f $FLAGS_from`
FLAGS_to=`eval readlink -f $FLAGS_to`
# Copy MBR and rootfs to output image
qemu-img convert -f raw \
"${FLAGS_from}/mbr.image" "${FLAGS_from}/rootfs.image" \
-O vmdk "${FLAGS_to}"
echo "Done. Created VMware image ${FLAGS_to}"

144
list_installed_packages.sh Executable file
View File

@ -0,0 +1,144 @@
#!/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.
# Print a list of installed packages
#
# This list is used by make_local_repo.sh to construct a local repository
# with only those packages.
#
# Usage:
# list_installed_packages.sh > package_list.txt
# Die on error
set -e
USAGE='usage: '"$0"' [options]
options:
-v Print verbose output.
-? Print this help.
'
# Handle command line options.
# Note: Can't use shflags, since this must run inside the rootfs image.
VERBOSE=0
# Option processing using getopts
while getopts "v?" OPTVAR
do
case $OPTVAR in
"v")
VERBOSE=1
;;
"?")
echo "$USAGE";
exit 1
;;
esac
done
shift `expr $OPTIND - 1`
# Print information on a single package
function print_deb {
# Positional parameters from calling script. :? means "fail if unset".
DEB_NAME=${1:?}
# Get the installed version of the package.
DEB_VER=`dpkg-query --show -f='${Version}' $DEB_NAME`
# Get information on package from apt-cache. Use a temporary file since
# we need to extract multiple fields.
rm -f /tmp/print_deb
apt-cache show $DEB_NAME > /tmp/print_deb
# The apt cache may have more than one version of the package available.
# For example, if the user has added another repository to
# /etc/apt/sources.list to install/upgrade packages. Use bash arrays to
# hold all the results until we can find information on the version we want.
# TODO: Is there a way to do this using only awk, so we can use /bin/sh
# instead of /bin/bash?
ALL_VER=( `grep '^Version: ' < /tmp/print_deb | awk '{print $2}'` )
ALL_PRIO=( `grep '^Priority: ' < /tmp/print_deb | awk '{print $2}'` )
ALL_SECTION=( `grep '^Section: ' < /tmp/print_deb | awk '{print $2}'` )
ALL_FILENAME=( `grep '^Filename: ' < /tmp/print_deb | awk '{print $2}'` )
rm -f /tmp/print_deb
# Find only the package version the user has installed.
NUM_VER=${#ALL_VER[@]}
FOUND_MATCH=0
for ((I=0; I<$NUM_VER; I++));
do
if [ "${ALL_VER[$I]}" = "$DEB_VER" ]
then
FOUND_MATCH=1
DEB_PRIO="${ALL_PRIO[$I]}"
DEB_SECTION="${ALL_SECTION[$I]}"
DEB_FILENAME="${ALL_FILENAME[$I]}"
fi
done
# Determine if the package filename appears to be from a locally-built
# repository (as created in build_image.sh). Use ! to ignore non-zero
# exit code, since grep exits 1 if no match.
! DEB_FILENAME_IS_LOCAL=`echo $DEB_FILENAME | grep 'local_packages'`
if [ $FOUND_MATCH -eq 0 ]
then
# Can't find information on package in apt cache
if [ $VERBOSE -eq 1 ]
then
echo "Unable to locate package $DEB_NAME version $DEB_VER" 1>&2
echo "in apt cache. It may have been installed directly, or the" 1>&2
echo "cache has been updated since installation and no longer" 1>&2
echo "contains information on that version. Omitting it in the" 1>&2
echo "list, since we can't determine where it came from." 1>&2
fi
echo "# Skipped $DEB_NAME $DEB_VER: not in apt cache"
elif [ "x$DEB_FILENAME" = "x" ]
then
# No filename, so package was installed via dpkg -i.
if [ $VERBOSE -eq 1 ]
then
echo "Package $DEB_NAME appears to have been installed directly" 1>&2
echo "(perhaps using 'dpkg -i'). Omitting it in the list, since we" 1>&2
echo "can't determine where it came from." 1>&2
fi
echo "# Skipped $DEB_NAME $DEB_VER: installed directly"
elif [ "x$DEB_FILENAME_IS_LOCAL" != "x" ]
then
# Package was installed from a local_packages directory.
# For example, chromeos-wm
if [ $VERBOSE -eq 1 ]
then
echo "Package $DEB_NAME appears to have been installed from a local" 1>&2
echo "package repository. Omitting it in the list, since future" 1>&2
echo "installs will also need to be local." 1>&2
fi
echo "# Skipped $DEB_NAME $DEB_VER $DEB_FILENAME: local install"
else
# Package from external repository.
# Don't change the order of these fields; make_local_repo.sh depends
# upon this order.
echo "$DEB_NAME $DEB_VER $DEB_PRIO $DEB_SECTION $DEB_FILENAME"
fi
}
# Header
echo "# Copyright (c) 2009 The Chromium Authors. All rights reserved."
echo "# Use of this source code is governed by a BSD-style license that can be"
echo "# found in the LICENSE file."
echo
echo "# Package list created by list_installed_packages.sh"
echo "# Creation time: `date`"
echo "#"
echo "# Contents of /etc/apt/sources.list:"
cat /etc/apt/sources.list | sed 's/^/# /'
echo "#"
echo "# package_name version priority section repo_filename"
# List all installed packages
for DEB in `dpkg-query --show -f='${Package}\n'`
do
print_deb $DEB
done

201
make_chroot.sh Executable file
View File

@ -0,0 +1,201 @@
#!/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.
# This script sets up an Ubuntu chroot environment. The ideas come
# from https://wiki.ubuntu.com/DebootstrapChroot and conversations with
# tedbo. The script is passed the path to an empty folder, which will be
# populated with the files to form an Ubuntu Jaunty system with the packages
# listed in PACKAGE_LIST_FILE (below) and their dependencies. Once created,
# the password is set to PASSWORD (below). One can enter the chrooted
# environment for work by running
# enter_chroot_dev_environment.sh /path/to/chroot-root
# 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 outside the chroot
assert_outside_chroot
DEFAULT_PKGLIST="$SRC_ROOT/package_repo/package-list-dev.txt"
# Define command line flags
# See http://code.google.com/p/shflags/wiki/Documentation10x
DEFINE_string suite "$DEFAULT_DEV_SUITE" "Repository suite to base image on."
DEFINE_string mirror "$DEFAULT_DEV_MIRROR" "Local repository mirror to use."
DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \
"Destination dir for the chroot environment."
DEFINE_string pkglist "$DEFAULT_PKGLIST" \
"File listing additional packages to install."
DEFINE_boolean delete $FLAGS_FALSE "Delete an existing chroot."
DEFINE_boolean replace $FLAGS_FALSE "Overwrite existing chroot, if any."
# Parse command line flags
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'set -e' is specified before now.
# TODO: replace shflags with something less error-prone, or contribute a fix.
set -e
COMPONENTS=`cat $FLAGS_pkglist | grep -v ' *#' | grep -v '^ *$' | tr '\n' ' '`
FULLNAME="Chrome OS dev user"
DEFGROUPS="eng,admin,adm,dialout,cdrom,floppy,audio,dip,video"
PASSWORD=chronos
CRYPTED_PASSWD=$(perl -e 'print crypt($ARGV[0], "foo")', $PASSWORD)
function in_chroot {
sudo chroot "$FLAGS_chroot" "$@"
}
function bash_chroot {
# Use $* not $@ since 'bash -c' needs a single arg
sudo chroot "$FLAGS_chroot" bash -c "$*"
}
function cleanup {
# Clean up mounts
mount | grep "on $(readlink -f "$FLAGS_chroot")" | awk '{print $3}' \
| xargs -r -L1 sudo umount
}
function delete_existing {
# Delete old chroot dir
if [ -e "$FLAGS_chroot" ]
then
echo "Cleaning up old mount points..."
cleanup
echo "Deleting $FLAGS_chroot..."
sudo rm -rf "$FLAGS_chroot"
fi
}
# Install packages which may not be installed on the local system
install_if_missing debootstrap
# Add debootstrap link for the suite, if it doesn't exist.
if [ ! -e "/usr/share/debootstrap/scripts/$FLAGS_suite" ]
then
sudo ln -s /usr/share/debootstrap/scripts/hardy \
"/usr/share/debootstrap/scripts/$FLAGS_suite"
fi
# Handle deleting an existing environment
if [ $FLAGS_delete -eq $FLAGS_TRUE ]
then
delete_existing
echo "Done."
exit 0
fi
# Handle existing directory
if [ -e "$FLAGS_chroot" ]
then
if [ $FLAGS_replace -eq $FLAGS_TRUE ]
then
delete_existing
else
echo "Directory $FLAGS_chroot already exists."
echo "Use --replace if you really want to overwrite it."
exit 1
fi
fi
# Create the destination directory
mkdir -p "$FLAGS_chroot"
# Run debootstrap to create the base chroot environment
echo "Running debootstrap..."
echo "You may need to enter password for sudo now..."
sudo debootstrap --arch=i386 "$FLAGS_suite" "$FLAGS_chroot" "$FLAGS_mirror"
echo "Done running debootstrap."
# Set up necessary mounts
sudo mount none -t proc "$FLAGS_chroot/proc"
sudo mount none -t devpts "$FLAGS_chroot/dev/pts"
# ...and make sure we clean them up on exit
trap cleanup EXIT
# Set up sudoers. Inside the chroot, the user can sudo without a password.
# (Safe enough, since the only way into the chroot is to 'sudo chroot', so
# the user's already typed in one sudo password...)
bash_chroot "echo %admin ALL=\(ALL\) ALL >> /etc/sudoers"
bash_chroot "echo $USER ALL=NOPASSWD: ALL >> /etc/sudoers"
# Set up apt sources
# If a local repository is used, it will have a different path when
# bind-mounted inside the chroot
MIRROR_INSIDE="${FLAGS_mirror/$GCLIENT_ROOT/$CHROOT_TRUNK_DIR}"
bash_chroot "echo deb $MIRROR_INSIDE $FLAGS_suite \
main restricted multiverse universe > /etc/apt/sources.list"
# TODO: enable sources when needed. Currently, kernel source is checked in
# and all other sources are pulled via DEPS files.
#bash_chroot "echo deb-src $MIRROR_INSIDE $FLAGS_suite \
# main restricted multiverse universe >> /etc/apt/sources.list"
# Set /etc/debian_chroot so '(chroot)' shows up in shell prompts
CHROOT_BASE=`basename $FLAGS_chroot`
bash_chroot "echo $CHROOT_BASE > /etc/debian_chroot"
# Copy config from outside chroot into chroot
sudo cp /etc/hosts "$FLAGS_chroot/etc/hosts"
# Add ourselves as a user inside the chroot
in_chroot groupadd admin
in_chroot groupadd -g 5000 eng
in_chroot useradd -G ${DEFGROUPS} -g eng -u `id -u` -s \
/bin/bash -m -c "${FULLNAME}" -p ${CRYPTED_PASSWD} ${USER}
# Bind-mount trunk into chroot so we can install local packages
mkdir "${FLAGS_chroot}$CHROOT_TRUNK_DIR"
sudo mount --bind "$GCLIENT_ROOT" "${FLAGS_chroot}$CHROOT_TRUNK_DIR"
# Niceties for interactive logins ('enter_chroot.sh'); these are ignored
# when specifying a command to enter_chroot.sh.
# Warn less when apt-get installing packqages
echo "export LANG=C" >> "$FLAGS_chroot/home/$USER/.bashrc"
chmod a+x "$FLAGS_chroot/home/$USER/.bashrc"
# Automatically change to scripts directory
echo "cd trunk/src/scripts" >> "$FLAGS_chroot/home/$USER/.profile"
# Warn if attempting to use source control commands inside the chroot
for NOUSE in svn gcl gclient
do
echo "alias $NOUSE='echo In the chroot, it is a bad idea to run $NOUSE'" \
>> "$FLAGS_chroot/home/$USER/.profile"
done
if [ "$USER" = "chrome-bot" ]
then
# Copy ssh keys, so chroot'd chrome-bot can scp files from chrome-web.
cp -r ~/.ssh "$FLAGS_chroot/home/$USER/"
fi
# Install additional packages
echo "Installing additional packages..."
in_chroot apt-get update
bash_chroot "export DEBIAN_FRONTEND=noninteractive LANG=C && \
apt-get --yes --force-yes install $COMPONENTS"
# Clean up the chroot mounts
trap - EXIT
cleanup
if [ "$FLAGS_chroot" = "$DEFAULT_CHROOT_DIR" ]
then
CHROOT_EXAMPLE_OPT=""
else
CHROOT_EXAMPLE_OPT="--chroot=$FLAGS_chroot"
fi
echo "All set up. To enter the chroot, run:"
echo " $SCRIPTS_DIR/enter_chroot.sh $CHROOT_EXAMPLE_OPT"
echo ""
echo "CAUTION: Do *NOT* rm -rf the chroot directory; if there are stale bind"
echo "mounts you may end up deleting your source tree too. To unmount and"
echo "delete the chroot cleanly, use:"
echo " $0 --delete $CHROOT_EXAMPLE_OPT"

225
make_local_repo.sh Executable file
View File

@ -0,0 +1,225 @@
#!/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.
# 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 outside the chroot
assert_outside_chroot
DEFAULT_DEST="$GCLIENT_ROOT/repo"
DEFAULT_DEV_PKGLIST="$SRC_ROOT/package_repo/repo_list_dev.txt"
DEFAULT_IMG_PKGLIST="$SRC_ROOT/package_repo/repo_list_image.txt"
# Command line options
DEFINE_string suite "$DEFAULT_EXT_SUITE" "Ubuntu suite to pull packages from."
DEFINE_string mirror "$DEFAULT_EXT_MIRROR" "Ubuntu repository mirror to use."
DEFINE_string dest "$DEFAULT_DEST" "Destination directory for repository."
DEFINE_string devlist "$DEFAULT_DEV_PKGLIST" \
"File listing packages to use for development."
DEFINE_string imglist "$DEFAULT_IMG_PKGLIST" \
"File listing packages to use for image."
DEFINE_string devsuite "$DEFAULT_DEV_SUITE" "Dev suite to update."
DEFINE_string imgsuite "$DEFAULT_IMG_SUITE" "Image suite to update."
DEFINE_boolean updev $FLAGS_TRUE "Update development repository."
DEFINE_boolean upimg $FLAGS_TRUE "Update image repository."
# Parse command line flags
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on error
set -e
# Architectures and sections to support in local mirror
REPO_ARCH="i386 armel"
REPO_SECTIONS="main restricted multiverse universe"
# Where to store packages downloaded from external repository, inside the
# chroot.
DEB_CACHE_DIR="/var/cache/make_local_repo"
CHROOT=`readlink -f $FLAGS_dest`
REPO_SUBDIR="apt"
REPO="$CHROOT/$REPO_SUBDIR"
#------------------------------------------------------------------------------
# Functions
# Run a command in the chroot
function in_chroot {
sudo chroot "$CHROOT" "$@"
}
# Run a bash command line in the chroot
function bash_chroot {
# Use $* not $@ since 'bash -c' needs a single arg
sudo chroot "$CHROOT" bash -c "$*"
}
# Clean up chroot mount points
function cleanup_chroot_mounts {
# Clear the trap from setup_chroot_mounts, now that we're unmounting.
trap - EXIT
mount | grep "on $(readlink -f "$CHROOT")" | awk '{print $3}' \
| xargs -r -L1 sudo umount
}
# Set up chroot mount points
function setup_chroot_mounts {
if [ ! -e "$CHROOT/proc" ]; then mkdir -p "$CHROOT/proc"; fi
sudo mount none -t proc "$CHROOT/proc"
if [ ! -e "$CHROOT/dev/pts" ]; then mkdir -p "$CHROOT/dev/pts"; fi
sudo mount none -t devpts "$CHROOT/dev/pts"
# Make sure we clean up the mounts on exit
trap cleanup_chroot_mounts EXIT
}
# Make a minimal chroot
function make_chroot {
echo "Creating chroot to build local package repository..."
mkdir -p "$CHROOT"
# Install packages which may not be installed on the local system
install_if_missing debootstrap
# Add debootstrap link for the suite, if it doesn't exist.
if [ ! -e "/usr/share/debootstrap/scripts/$FLAGS_suite" ]
then
sudo ln -s /usr/share/debootstrap/scripts/gutsy \
"/usr/share/debootstrap/scripts/$FLAGS_suite"
fi
# Run debootstrap
sudo debootstrap --arch=i386 --variant=minbase \
--include=gnupg \
"$FLAGS_suite" "$CHROOT" "$FLAGS_mirror"
# Set up chroot mounts, since the package installs below need them
setup_chroot_mounts
# Install packages into chroot
bash_chroot "echo deb $FLAGS_mirror $FLAGS_suite $REPO_SECTIONS \
> /etc/apt/sources.list"
in_chroot apt-get update
in_chroot apt-get --yes --force-yes install reprepro wget
# Clean up chroot mounts
cleanup_chroot_mounts
}
# Create reprepro repository
function make_repo {
echo "Creating repository directory..."
sudo rm -rf "$REPO"
sudo mkdir -p "$REPO"
sudo chown $USER "$REPO"
mkdir -p "$REPO/conf"
mkdir -p "$REPO/incoming"
# Create the distributions conf file
CONF="$REPO/conf/distributions"
rm -f "$CONF"
cat <<EOF > $CONF
Origin: $FLAGS_mirror
Label: Chrome OS Dev
Suite: stable
Codename: $FLAGS_devsuite
Version: 3.1
Architectures: $REPO_ARCH
Components: $REPO_SECTIONS
Description: Chrome OS Development
Origin: $FLAGS_mirror
Label: Chrome OS
Suite: stable
Codename: $FLAGS_imgsuite
Version: 3.1
Architectures: $REPO_ARCH
Components: $REPO_SECTIONS
Description: Chrome OS Image
EOF
}
# Update a suite in the repository from a list of packages
function update_suite {
SUITE="${1:?}"
PKGLIST="${2:?}"
echo "Updating $SUITE from $PKGLIST..."
# Clear the suite first
# Since packages are either source or not, this removes all of them.
in_chroot reprepro -b "$REPO_SUBDIR" removefilter "$SUITE" "!Source"
in_chroot reprepro -b "$REPO_SUBDIR" removefilter "$SUITE" "Source"
# Add packages to the suite
echo "Downloading packages..."
for DEB in `grep -v '^#' < $PKGLIST | awk '{print $1}'`
do
echo "Adding $DEB..."
DEB_PRIO=`cat $PKGLIST | grep '^'$DEB' ' | awk '{print $3}'`
DEB_SECTION=`cat $PKGLIST | grep '^'$DEB' ' | awk '{print $4}'`
DEB_PATH=`cat $PKGLIST | grep '^'$DEB' ' | awk '{print $5}'`
DEB_FILE="$DEB_CACHE_DIR/"`basename $DEB_PATH`
# Download the package if necessary
if [ ! -e "$CHROOT/$DEB_FILE" ]
then
in_chroot wget --no-verbose "$FLAGS_mirror/${DEB_PATH}" -O "$DEB_FILE"
fi
# Copy the file into the target suite with the correct priority
in_chroot reprepro -b "$REPO_SUBDIR" -P "$DEB_PRIO" -S "$DEB_SECTION" \
includedeb "$SUITE" "$DEB_FILE"
done
}
#------------------------------------------------------------------------------
# Create a minimal chroot in which we can run reprepro, if one doesn't
# already exist. Necessary since the version of reprepro available on
# older systems is buggy.
if [ ! -e "$CHROOT" ]
then
make_chroot
fi
# Set up chroot mounts
setup_chroot_mounts
# Create/update repo. Need to run this every time so we rebuild the
# distributions file.
make_repo
# Create cache directory for downloaded .debs. This needs to be outside the
# repository so we can delete and rebuild the repository without needing to
# re-download all the .debs.
if [ ! -e "$CHROOT/$DEB_CACHE_DIR" ]
then
sudo mkdir -p "$CHROOT/$DEB_CACHE_DIR"
sudo chown $USER "$CHROOT/$DEB_CACHE_DIR"
fi
# Update the development and image suites
if [ $FLAGS_updev -eq $FLAGS_TRUE ]
then
update_suite $FLAGS_devsuite $FLAGS_devlist
fi
if [ $FLAGS_upimg -eq $FLAGS_TRUE ]
then
update_suite $FLAGS_imgsuite $FLAGS_imglist
fi
# Clean up the chroot mounts
cleanup_chroot_mounts
echo "Done."

204
mk_arm_sd_image.py Executable file
View File

@ -0,0 +1,204 @@
#!/usr/bin/env python
# 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 generate ARM beagleboard SD card image from kernel, root fs
This script must be passed a uImage file and a tarred up root filesystem.
It also needs EITHER an output device or a file + size. If you use a real
device, the entire device will be used. if you specify a file, the file
will be truncated to the given length and be formatted as a disk image.
To copy a disk image to a device (e.g. /dev/sdb):
# dd if=disk_image.img of=/dev/sdb bs=4M
"""
from optparse import OptionParser
import math
import os
import re
import shutil
import subprocess
import sys
def DieWithUsage(exec_path):
print 'usage:', exec_path, ' [-f file] [-s filesize] [-d device] ', \
'path/to/uImage path/to/armel-rootfs.tgz'
print 'You must pass either -d or both -f and -s'
print 'size may end in k, m, or g for kibibyte, mebibytes, gibibytes.'
print 'This will erase all data on the device or in the file passed.'
print 'This script must be run as root.'
sys.exit(1)
def ParseFilesize(size):
if size == '':
return -1
multiplier = 1
number_part = size[:-1]
last_char = size[-1]
if (last_char == 'k') or (last_char == 'K'):
multiplier = 1024
elif (last_char == 'm') or (last_char == 'M'):
multiplier = 1024 * 1024
elif (last_char == 'g') or (last_char == 'G'):
multiplier = 1024 * 1024 * 1024
else:
number_part = size
return long(number_part) * multiplier
def ParseArgs(argv):
use_file = False
file_size = 0
device_path = ''
uimage_path = ''
rootfs_path = ''
parser = OptionParser()
parser.add_option('-f', action='store', type='string', dest='filename')
parser.add_option('-s', action='store', type='string', dest='filesize')
parser.add_option('-d', action='store', type='string', dest='devname')
(options, args) = parser.parse_args()
# check for valid arg presence
if len(args) != 2:
DieWithUsage(argv[0])
if (options.filename != None) != (options.filesize != None):
DieWithUsage(argv[0])
if not (bool((options.filename != None) and (options.filesize != None)) ^
bool(options.devname != None)):
DieWithUsage(argv[0])
# check the device isn't a partition
if options.devname != None:
if (options.devname[-1] >= '0') and (options.devname[-1] <= '9'):
print 'Looks like you specified a partition device, rather than the ' \
'entire device. try using -d',options.devname[:-1]
DieWithUsage(argv[0])
# if size passed, parse size
if options.filesize != None:
file_size = ParseFilesize(options.filesize)
if file_size < 0:
DieWithUsage(argv[0])
if options.devname != None:
device_path = options.devname
if options.filename != None:
use_file = True
device_path = options.filename
uimage_path = args[0]
rootfs_path = args[1]
# print args
if use_file:
print "file size:", file_size
print "dev path:", device_path
print "uimage:", uimage_path
print 'rootfs:', rootfs_path
return use_file, file_size, device_path, uimage_path, rootfs_path
def CreateSparseFile(path, size):
fd = os.open(path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0644)
if (fd < 0):
print 'os.open() failed'
exit(1)
os.ftruncate(fd, size)
os.close(fd)
# creates the partion table with the first partition having enough
# space for the uimage, the second partition takingn the rest of the space
def CreatePartitions(uimage_path, device_path):
# get size of first partition in mebibytes
statinfo = os.stat(uimage_path)
first_part_size = int(math.ceil(statinfo.st_size / (1024.0 * 1024.0)) + 1)
System('echo -e ",' + str(first_part_size) \
+ ',c,*\\n,,83,-" | sfdisk -uM \'' + device_path + '\'')
# uses losetup to set up two loopback devices for the two partitions
# returns the two loopback device paths
def SetupLoopbackDevices(device_path):
sector_size = 512 # bytes
# get size of partitons
output = subprocess.Popen(['sfdisk', '-d', device_path],
stdout=subprocess.PIPE).communicate()[0]
m = re.search('start=\\s+(\\d+), size=\\s+(\\d+),.*?start=\\s+(\\d+), size=\\s+(\\d+),', output, re.DOTALL)
part1_start = long(m.group(1)) * sector_size
part1_size = long(m.group(2)) * sector_size
part2_start = long(m.group(3)) * sector_size
part2_size = long(m.group(4)) * sector_size
if part1_start < 1 or part1_size < 1 or part2_start < 1 or part2_size < 1:
print 'failed to read partition table'
sys.exit(1)
return SetupLoopbackDevice(device_path, part1_start, part1_size), \
SetupLoopbackDevice(device_path, part2_start, part2_size)
# returns loopback device path
def SetupLoopbackDevice(path, start, size):
# get a device
device = subprocess.Popen(['losetup', '-f'],
stdout=subprocess.PIPE).communicate()[0].rstrip()
if device == '':
print 'can\'t get device'
sys.exit(1)
System('losetup -o ' + str(start) + ' --sizelimit ' + str(size) + ' ' + device + ' ' + path)
return device
def DeleteLoopbackDevice(dev):
System('losetup -d ' + dev)
def FormatDevices(first, second):
System('mkfs.msdos -F 32 ' + first)
System('mkfs.ext3 ' + second)
# returns mounted paths
def MountFilesystems(paths):
i = 0
ret = []
for path in paths:
i = i + 1
mntpoint = 'mnt' + str(i)
System('mkdir ' + mntpoint)
System('mount ' + path + ' ' + mntpoint)
ret.append(mntpoint)
return ret
def UnmountFilesystems(mntpoints):
for mntpoint in mntpoints:
System('umount ' + mntpoint)
os.rmdir(mntpoint)
def System(cmd):
print 'system(' + cmd + ')'
p = subprocess.Popen(cmd, shell=True)
return os.waitpid(p.pid, 0)
def main(argv):
(use_file, file_size, device_path, uimage_path, rootfs_path) = ParseArgs(argv)
if use_file:
CreateSparseFile(device_path, file_size)
CreatePartitions(uimage_path, device_path)
if use_file:
(dev1, dev2) = SetupLoopbackDevices(device_path)
else:
dev1 = device_path + '1'
dev2 = device_path + '2'
FormatDevices(dev1, dev2)
(mnt1, mnt2) = MountFilesystems([dev1, dev2])
# copy data in
shutil.copy(uimage_path, mnt1 + '/uImage')
System('tar xzpf ' + rootfs_path + ' -C ' + mnt2)
UnmountFilesystems([mnt1, mnt2])
if use_file:
DeleteLoopbackDevice(dev1)
DeleteLoopbackDevice(dev2)
print 'all done!'
if use_file:
print 'you may want to run dd if=' + device_path + ' of=/some/device bs=4M'
if __name__ == '__main__':
main(sys.argv)

129
mk_memento_images.sh Executable file
View File

@ -0,0 +1,129 @@
#!/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.
# This script takes a path to a rootfs.ext2 which was generated by
# build_image.sh and generates an image that can be used for auto
# update.
set -e
if [ -z "$1" ]
then
echo "usage: $0 path/to/rootfs.image"
exit 1
fi
if [ $(whoami) = "root" ]
then
echo "run $0 as non root"
exit 1
fi
FINAL_OUT_FILE=$(dirname "$1")/update.tgz
UNCOMPRESSED_OUT_FILE="$FINAL_OUT_FILE.uncompressed"
MOUNTPOINT="/tmp/mk_memento_images_mntpoint"
ORIGINAL_LABEL=$(sudo /sbin/e2label "$1")
# copy original over to the new file
cp "$1" "$UNCOMPRESSED_OUT_FILE"
# next steps require fs to be mounted. unmount if we die early
function cleanup_mount {
sudo umount "$MOUNTPOINT" || true
rmdir "$MOUNTPOINT"
}
mkdir -p "$MOUNTPOINT"
sudo mount -o loop "$UNCOMPRESSED_OUT_FILE" "$MOUNTPOINT"
trap cleanup_mount INT TERM EXIT
# make an empty postinst script. the quotes around EOF mean don't evaluate
# anything inside this HEREDOC.
cat <<"EOF" | sudo dd of="$MOUNTPOINT/postinst"
#!/bin/sh
set -e
# see if we're booted from hard drive or USB. We should not have booted from
# USB.
INITRD=$(cat /proc/cmdline | tr ' ' '\n' | grep ^initrd= | wc -l)
if [ "0" != "$INITRD" ]
then
# we're usb. abort.
exit 1
fi
# update /boot/extlinux.conf
INSTALL_ROOT=`dirname "$0"`
INSTALL_DEV="$1"
STATEFUL_PARTITION=$(echo "$INSTALL_DEV" | tr 12 44)
STATEFUL_PARTITION_DIR=/tmp/stateful_partition
# set default label to chromeos-hd
sed -i 's/^DEFAULT .*/DEFAULT chromeos-hd/' "$INSTALL_ROOT"/boot/extlinux.conf
sed -i "{ s:HDROOT:$INSTALL_DEV: }" "$INSTALL_ROOT"/boot/extlinux.conf
# fix fstab
# keep in sync with src/platform/installer/chromeos_install.sh
# TODO: Figure out if we can mount rootfs read-only
cat <<ENDFSTAB | sudo dd of="$INSTALL_ROOT"/etc/fstab
/dev/root / rootfs ro 0 0
tmpfs /tmp tmpfs rw,nosuid,nodev 0 0
$STATEFUL_PARTITION /mnt/stateful_partition ext3 rw 0 1
/mnt/stateful_partition/home /home bind defaults,bind 0 0
/mnt/stateful_partition/var /var bind defaults,bind 0 0
ENDFSTAB
mkdir -p "$INSTALL_ROOT"/mnt/stateful_partition
chmod 0755 "$INSTALL_ROOT"/mnt
chmod 0755 "$INSTALL_ROOT"/mnt/stateful_partition
# Creates an empty resolv.conf file with the right permissions to avoid
# it being clobbered by connman/dhclient.
# We assume the stateful partition at /mnt/stateful_partition will still be
# there when we boot into the new image
mkdir -p /mnt/stateful_partition/etc
# Default to Pacific timezone
# If user already has a timezone set, this won't replace it
ln -s /usr/share/zoneinfo/US/Pacific \
/mnt/stateful_partition/etc/localtime || true
ln -sf /mnt/stateful_partition/etc/localtime \
"$INSTALL_ROOT"/etc/localtime
EOF
sudo chmod 0755 "$MOUNTPOINT/postinst"
# done with mounting
trap - INT TERM EXIT
cleanup_mount
# Fix up the file system label. We prefix with 'A'
NEW_LABEL="A${ORIGINAL_LABEL}"
sudo /sbin/tune2fs -L "$NEW_LABEL" "$UNCOMPRESSED_OUT_FILE"
# compress and hash
CS_AND_RET_CODES=$(gzip -c "$UNCOMPRESSED_OUT_FILE" | \
tee "$FINAL_OUT_FILE" | openssl sha1 -binary | \
openssl base64 | tr '\n' ' '; \
echo ${PIPESTATUS[*]})
EXPECTED_RET_CODES="0 0 0 0 0"
set -- $CS_AND_RET_CODES
CALC_CS="$1"
shift
RET_CODES="$@"
if [ "$RET_CODES" != "$EXPECTED_RET_CODES" ]
then
echo compression/hash failed. $RET_CODES
exit 1
fi
rm "$UNCOMPRESSED_OUT_FILE"
echo Success. hash is "$CALC_CS"

139
recursive_dep.py Normal file
View File

@ -0,0 +1,139 @@
#!/usr/bin/env python
# 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.
from sets import Set
import subprocess
import sys
import time
preferred_virtual_pkg_providers = {
'<debconf-2.0>': 'debconf',
'<libgl1>': 'libgl1-mesa-glx',
'<modutils>': 'module-init-tools',
'<x-terminal-emulator>': 'xvt',
'<xserver-xorg-input-4>': 'xserver-xorg-input-kbd',
'<xserver-xorg-video-5>': 'xserver-xorg-video-dummy'
}
# if we have a set of packages to choose from, we see if any packages we
# can choose from are in this list (starting from element 0). if we find a
# match, we use that, otherwise the script just picks one from the set
preferred_packages = [
'debconf',
'debconf-english',
'ttf-bitstream-vera',
'libgl1-mesa-glx',
'module-init-tools',
'<x-terminal-emulator>',
'xserver-xorg-input-kbd',
'xserver-xorg-video-dummy',
'<xserver-xorg-input-4>',
'<xserver-xorg-video-5>',
'udev'
]
def isVirtualPackage(packagename):
return packagename.startswith('<') and packagename.endswith('>')
def providerForVirtualPkg(packagename):
# check for any pre-chosen packages
if packagename in preferred_virtual_pkg_providers:
return preferred_virtual_pkg_providers[packagename]
name = packagename.strip('<>')
lines = subprocess.Popen(['apt-cache', 'showpkg', name],
stdout=subprocess.PIPE).communicate()[0].split('\n')
if len(lines) < 2:
print 'too few lines!', packagename
sys.exit(1)
got_reverse_provides_line = False
for line in lines:
if got_reverse_provides_line:
# just take the first one
provider = line.split(' ')[0]
if provider == '':
print 'no provider for', packagename
sys.exit(1)
print '"' + provider + '" provides "' + packagename + '"'
return provider
got_reverse_provides_line = line.startswith('Reverse Provides:')
print 'didn\'t find a provider for', packagename
sys.exit(1)
def getDepsFor(packagename):
results = subprocess.Popen(['apt-cache', 'depends', packagename],
stdout=subprocess.PIPE).communicate()[0]
lines = results.split('\n')
if len(lines) < 2:
print 'too few lines!', packagename
sys.exit(1)
ret = Set()
prefix = ' Depends: '
# If a package depends on any in a set of packages then each possible package
# in the set, except for the last one, will have a pipe before Depends.
# For example:
# Depends: foo
# Depends: bar
# |Depends: baz
# |Depends: bat
# |Depends: flower
# Depends: candle
# Depends: trunk
# means this package depends on foo, bar, trunk, and any one of baz, bat,
# flower, and candle.
# I couldn't find this documented anywhere.
set_prefix = ' |Depends: '
dep_set = Set()
for line in lines:
if line.startswith(set_prefix):
dep_set.add(line[len(set_prefix):])
continue
if not line.startswith(prefix):
dep_set.clear()
continue
pkgname = line[len(prefix):]
if len(dep_set) > 0:
dep_set.add(pkgname)
# we need to pick one from dep_set
found_pref = False
for pref in preferred_packages:
if pref in dep_set:
print 'using pref to choose "' + pref + '" from set ' + str(dep_set)
pkgname = pref
found_pref = True
break
if not found_pref:
print 'chose "' + pkgname + '" from set ' + str(dep_set)
dep_set.clear()
ret.add(pkgname)
print packagename + ' has deps: ' + str(ret)
return ret
def main(argv):
checked = Set()
unchecked = Set()
for arg in argv[1:]:
unchecked.add(arg)
while True:
directdeps = Set()
for pkg in unchecked:
if isVirtualPackage(pkg):
pkg = providerForVirtualPkg(pkg)
directdeps = directdeps.union(getDepsFor(pkg))
checked.add(pkg)
directdeps = directdeps.difference(checked)
unchecked = directdeps
if len(unchecked) == 0:
print 'done'
checked_list = list(checked)
checked_list.sort()
print 'all:', checked_list
print 'total of ' + str(len(checked_list)) + ' items'
sys.exit(0)
if __name__ == '__main__':
main(sys.argv)

32
run_tests.sh Executable file
View File

@ -0,0 +1,32 @@
#!/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.
# 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"
# Flags
DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \
"Root of build output"
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on error; print commands
set -ex
# Run tests
TESTS_DIR="$FLAGS_build_root/x86/tests"
cd "$TESTS_DIR"
# TODO: standardize test names - should all end in "_test" so we can find
# and run them without listing them explicitly.
./pam_google_unittests
for i in *_test; do ./${i}; done
cd -
echo "All tests passed."

35
set_shared_user_password.sh Executable file
View File

@ -0,0 +1,35 @@
#!/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 set the password for the shared user account. Stores the
# MD5crypt'd password to a file, for use by customize_rootfs.sh.
# 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_HELP="USAGE: $0 [flags]"
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on any errors.
set -e
# Get password
read -p "Enter password for shared user account: " PASSWORD
CRYPTED_PASSWD_FILE=$SCRIPTS_DIR/shared_user_passwd.txt
CRYPTED_PASSWD="$(echo "$PASSWORD" | openssl passwd -1 -stdin)"
PASSWORD="gone now"
echo "$CRYPTED_PASSWD" > $CRYPTED_PASSWD_FILE
echo "Shared user password set in $CRYPTED_PASSWD_FILE"