blob: 092bd6c89b1b6a185b1199fd602e3d1775e56141 [file] [log] [blame]
Chris Sosa687f0a62010-04-02 14:06:29 -07001#!/bin/bash
2
3# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
Chris Sosa96bd5f62010-04-09 08:54:26 -07007# Script that emerges packages and their dependencies from a host development
Chris Sosa687f0a62010-04-02 14:06:29 -07008# machine onto a target Chromium OS device
9#
10# NOTE: This script must be run from the chromiumos build chroot environment.
11#
12
13# Load common constants. This should be the first executable line.
14# The path to common.sh should be relative to your script's location.
15. "$(dirname "$0")/../../scripts/common.sh"
16
17# Script must be run inside the chroot
18assert_inside_chroot
19
20get_default_board
21
22# Flags
23DEFINE_string board "$DEFAULT_BOARD" \
24 "The board to build packages for."
25DEFINE_boolean usepkg $FLAGS_FALSE \
26 "Use binary packages to bootstrap build when possible."
27DEFINE_string build_root "/build" \
28 "The root location for board sysroots."
29DEFINE_integer jobs -1 \
30 "How many packages to build in parallel at maximum."
31DEFINE_boolean unmerge $FLAGS_FALSE \
32 "Whether to unmerge the package versus emerge it."
33DEFINE_integer retries -1 \
34 "On build failure, the number of times to retry"
35DEFINE_boolean onstatefuldev $FLAGS_TRUE \
36 "Build packages and install them into stateful partition on device."
37DEFINE_boolean installmask $FLAGS_TRUE \
38 "Use INSTALL_MASK to shrink the resulting image."
39DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance"
40
41# Parse command line
42FLAGS_HELP="usage: $0 [flags]"
43FLAGS "$@" || exit 1
44eval set -- "${FLAGS_ARGV}"
45
46# Die on any errors.
47set -e
48
49# Checks $1 and prints out $2 is required before exiting if $1 does not exist
50check_args() {
51 if [ -z "${1}" ] ; then
52 echo "Error: ${2} is required."
53 exit 1
54 fi
55}
56
57# Clean up function for mount point
58cleanup_sshfs_mount() {
59 echo "Cleaning up mount point"
Chris Sosa96bd5f62010-04-09 08:54:26 -070060 sudo umount "${REMOTE_ROOT_DIR}"
Chris Sosa687f0a62010-04-02 14:06:29 -070061}
62
63check_args "${FLAGS_board}"
64check_args "${FLAGS_ARGV}" "Emerge package name"
65
Chris Sosa687f0a62010-04-02 14:06:29 -070066EMERGE_FLAGS=""
Chris Sosa96bd5f62010-04-09 08:54:26 -070067[[ $FLAGS_usepkg -eq $FLAGS_TRUE ]] &&
Chris Sosa687f0a62010-04-02 14:06:29 -070068 EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg --usepkg --with-bdeps y"
69
70INSTALL_MASK=""
71[[ ${FLAGS_installmask} -eq ${FLAGS_TRUE} ]] && \
72 INSTALL_MASK="${DEFAULT_INSTALL_MASK}"
73
74EMERGE_JOBS=
75[[ ${FLAGS_jobs} -ne -1 ]] && EMERGE_JOBS="--jobs=${FLAGS_jobs}"
76
77# Duplicate from build_packages to get host packages on system.
78
79# Skip building on host if we are unmerging.
80if [ ${FLAGS_unmerge} -eq ${FLAGS_FALSE} ] ; then
81 eretry sudo emerge -uDNv $EMERGE_FLAGS world
82
83 # Build request and install them onto the sysroot
84 for emerge_request in $FLAGS_ARGV; do
85 eretry sudo emerge-${FLAGS_board} -uDNv \
86 $(remove_quotes "${emerge_request}")
87 done
88fi
89
90# Name is unique per client. This allows one to run gmergefs in parallel
91# with multiple clients.
92REMOTE_ROOT_DIR="${FLAGS_build_root}/${FLAGS_board}/gmergefs/${FLAGS_remote}"
93
94# Default is to install on stateful dev, otherwise install on root.
95REMOTE_RELATIVE_PATH=""
96[ ${FLAGS_onstatefuldev} -eq $FLAGS_TRUE ] && \
97 REMOTE_RELATIVE_PATH="mnt/stateful_partition/dev_image"
98REMOTE_PATH="${REMOTE_ROOT_DIR}/${REMOTE_RELATIVE_PATH}"
99
100# Create directory for remote image
101sudo mkdir -p "${REMOTE_ROOT_DIR}"
102
103# Mount remote fs into chroot
104echo "Enter password for remote machine"
105sudo sshfs -o idmap=user -o allow_other -o nonempty -o transform_symlinks \
106 "root@${FLAGS_remote}:/" "${REMOTE_ROOT_DIR}"
Chris Sosa96bd5f62010-04-09 08:54:26 -0700107
Chris Sosa687f0a62010-04-02 14:06:29 -0700108trap cleanup_sshfs_mount EXIT
109
110# Ensure root path is created for emerge
111sudo mkdir -p "${REMOTE_PATH}"
112
113# Same arguments used in build_image to emerge these packages onto the target
114for emerge_request in $FLAGS_ARGV; do
115 if [ ${FLAGS_unmerge} -eq ${FLAGS_FALSE} ] ; then
116 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${FLAGS_board} \
117 --root="${REMOTE_PATH}" --root-deps=rdeps \
118 --usepkgonly $(remove_quotes "${emerge_request}") $EMERGE_JOBS
119 else
120 sudo emerge-${FLAGS_board} --unmerge \
121 --root="${REMOTE_PATH}" $(remove_quotes "${emerge_request}")
122 fi
123done
124
Chris Sosa96bd5f62010-04-09 08:54:26 -0700125# Update ld.so.cache of root partition if installing to /usr/local
126if [ ${FLAGS_onstatefuldev} -eq $FLAGS_TRUE ] ; then
127 # Re-run ldconfig to fix /etc/ldconfig.so.cache
128 sudo /sbin/ldconfig -r "${REMOTE_ROOT_DIR}"
129fi
130
Chris Sosa687f0a62010-04-02 14:06:29 -0700131sync
Chris Sosa96bd5f62010-04-09 08:54:26 -0700132sudo umount "${REMOTE_ROOT_DIR}"
Chris Sosa687f0a62010-04-02 14:06:29 -0700133
Chris Sosa96bd5f62010-04-09 08:54:26 -0700134trap - EXIT