Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 3 | # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 7 | # Prints the arguments and dies. |
| 8 | print_and_die() { |
| 9 | echo $* |
| 10 | exit 1 |
| 11 | } |
| 12 | |
Chris Sosa | 4a1e819 | 2010-12-13 14:22:41 -0800 | [diff] [blame^] | 13 | # Set up PORTAGE variables to be rooted in /usr/local/portage. |
| 14 | setup_portage_vars() { |
| 15 | export PORTDIR=/usr/local/portage |
| 16 | export PKGDIR=/usr/local/portage |
| 17 | export DISTDIR=/usr/local/portage/distfiles |
| 18 | export PORTAGE_BINHOST="${DEVKIT_URL}/static/pkgroot/${BOARD_NAME}/packages" |
| 19 | export PORTAGE_TMPDIR=/tmp |
| 20 | export CONFIG_PROTECT="-*" |
| 21 | export FEATURES="-sandbox" |
| 22 | # Accept keywords only for stable ebuilds by default. |
| 23 | [ -z "$ACCEPT_KEYWORDS" ] && ACCEPT_KEYWORDS="arm x86 ~arm ~x86" |
| 24 | export ACCEPT_KEYWORDS |
| 25 | export ROOT=/ |
| 26 | } |
| 27 | |
jglasgow | cc71f3a | 2010-03-12 14:30:21 -0500 | [diff] [blame] | 28 | set -e |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 29 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 30 | # Get variables for the devserver from the lsb-release file. |
| 31 | DEVKIT_URL=$(grep ^CHROMEOS_DEVSERVER /etc/lsb-release | cut -d = -f 2-) |
| 32 | BOARD_NAME=$(grep ^CHROMEOS_RELEASE_BOARD /etc/lsb-release | cut -d = -f 2-) |
| 33 | [ -z "${BOARD_NAME}" ] && print_and_die "No board in /etc/lsb-release" |
| 34 | [ -z "${DEVKIT_URL}" ] && print_and_die "No dev server url in /etc/lsb-release" |
| 35 | |
Chris Sosa | 4a1e819 | 2010-12-13 14:22:41 -0800 | [diff] [blame^] | 36 | setup_portage_vars |
| 37 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 38 | # Determine if we should send a build command to the devserver. |
| 39 | BUILD=1 |
| 40 | if [ x$1 == x-n ]; then |
| 41 | BUILD=0 |
David James | e3d542a | 2010-09-24 16:21:19 -0700 | [diff] [blame] | 42 | shift |
| 43 | fi |
jglasgow | cc71f3a | 2010-03-12 14:30:21 -0500 | [diff] [blame] | 44 | |
Chris Sosa | 605fe88 | 2010-04-22 17:01:32 -0700 | [diff] [blame] | 45 | # Package name is the last argument. |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 46 | # TODO(sosa) - Support multiple packages. |
| 47 | PACKAGE_NAME=${!#} |
Chris Sosa | 605fe88 | 2010-04-22 17:01:32 -0700 | [diff] [blame] | 48 | |
David James | e3d542a | 2010-09-24 16:21:19 -0700 | [diff] [blame] | 49 | # If no package name is provided skip to emerge options. |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 50 | [[ ${PACKAGE_NAME} == -* ]] && BUILD=0 |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 51 | |
| 52 | mount -o remount,rw / |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 53 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 54 | # Re-mount /tmp as exec. |
Frank Swiderski | dc13081 | 2010-10-08 15:42:28 -0700 | [diff] [blame] | 55 | mount -o remount,exec /tmp |
Chris Sosa | 4a1e819 | 2010-12-13 14:22:41 -0800 | [diff] [blame^] | 56 | trap "mount -o remount,noexec /tmp" EXIT |
Frank Swiderski | dc13081 | 2010-10-08 15:42:28 -0700 | [diff] [blame] | 57 | |
Mandeep Singh Baines | ea6b7a5 | 2010-08-17 14:03:57 -0700 | [diff] [blame] | 58 | # Delete the local binary package cache. |
Chris Sosa | 4a1e819 | 2010-12-13 14:22:41 -0800 | [diff] [blame^] | 59 | rm -rf "${PKGDIR}/packages" |
Mandeep Singh Baines | ea6b7a5 | 2010-08-17 14:03:57 -0700 | [diff] [blame] | 60 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 61 | if [ ${BUILD} == 1 ]; then |
| 62 | echo "Building ${PACKAGE_NAME}" |
Chris Sosa | 605fe88 | 2010-04-22 17:01:32 -0700 | [diff] [blame] | 63 | ESCAPED_PACKAGE=$(python -c \ |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 64 | "import urllib; print urllib.quote('''${PACKAGE_NAME}''')") |
jglasgow | cc71f3a | 2010-03-12 14:30:21 -0500 | [diff] [blame] | 65 | ESCAPED_BOARD=$(python -c \ |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 66 | "import urllib; print urllib.quote('''${BOARD_NAME}''')") |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 67 | |
Chris Sosa | 605fe88 | 2010-04-22 17:01:32 -0700 | [diff] [blame] | 68 | wget $DEVKIT_URL/build \ |
| 69 | --post-data="pkg=${ESCAPED_PACKAGE}&board=${ESCAPED_BOARD}" |
jglasgow | cc71f3a | 2010-03-12 14:30:21 -0500 | [diff] [blame] | 70 | fi |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 71 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 72 | echo "Emerging ${PACKAGE_NAME}" |
Chris Sosa | 4a1e819 | 2010-12-13 14:22:41 -0800 | [diff] [blame^] | 73 | emerge --getbinpkgonly --usepkgonly "$@" |