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 | |
Chris Sosa | 4c9b2f9 | 2010-12-13 16:09:06 -0800 | [diff] [blame^] | 28 | # Prompts the user to change the root to /usr/local. |
| 29 | change_portage_root() { |
| 30 | read -p "Do you wish to install this program into /usr/local? (Y/n) " input |
| 31 | if [[ ${input} = [Nn]* ]]; then |
| 32 | echo "Better safe than sorry." |
| 33 | exit 1 |
| 34 | fi |
| 35 | export ROOT=/usr/local |
| 36 | } |
| 37 | |
jglasgow | cc71f3a | 2010-03-12 14:30:21 -0500 | [diff] [blame] | 38 | set -e |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 39 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 40 | # Get variables for the devserver from the lsb-release file. |
| 41 | DEVKIT_URL=$(grep ^CHROMEOS_DEVSERVER /etc/lsb-release | cut -d = -f 2-) |
| 42 | BOARD_NAME=$(grep ^CHROMEOS_RELEASE_BOARD /etc/lsb-release | cut -d = -f 2-) |
| 43 | [ -z "${BOARD_NAME}" ] && print_and_die "No board in /etc/lsb-release" |
| 44 | [ -z "${DEVKIT_URL}" ] && print_and_die "No dev server url in /etc/lsb-release" |
| 45 | |
Chris Sosa | 4a1e819 | 2010-12-13 14:22:41 -0800 | [diff] [blame] | 46 | setup_portage_vars |
| 47 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 48 | # Determine if we should send a build command to the devserver. |
| 49 | BUILD=1 |
| 50 | if [ x$1 == x-n ]; then |
| 51 | BUILD=0 |
David James | e3d542a | 2010-09-24 16:21:19 -0700 | [diff] [blame] | 52 | shift |
| 53 | fi |
jglasgow | cc71f3a | 2010-03-12 14:30:21 -0500 | [diff] [blame] | 54 | |
Chris Sosa | 605fe88 | 2010-04-22 17:01:32 -0700 | [diff] [blame] | 55 | # Package name is the last argument. |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 56 | # TODO(sosa) - Support multiple packages. |
| 57 | PACKAGE_NAME=${!#} |
Chris Sosa | 605fe88 | 2010-04-22 17:01:32 -0700 | [diff] [blame] | 58 | |
David James | e3d542a | 2010-09-24 16:21:19 -0700 | [diff] [blame] | 59 | # If no package name is provided skip to emerge options. |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 60 | [[ ${PACKAGE_NAME} == -* ]] && BUILD=0 |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 61 | |
Chris Sosa | 4c9b2f9 | 2010-12-13 16:09:06 -0800 | [diff] [blame^] | 62 | mount -o remount,rw / || change_portage_root |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 63 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 64 | # Re-mount /tmp as exec. |
Frank Swiderski | dc13081 | 2010-10-08 15:42:28 -0700 | [diff] [blame] | 65 | mount -o remount,exec /tmp |
Chris Sosa | 4a1e819 | 2010-12-13 14:22:41 -0800 | [diff] [blame] | 66 | trap "mount -o remount,noexec /tmp" EXIT |
Frank Swiderski | dc13081 | 2010-10-08 15:42:28 -0700 | [diff] [blame] | 67 | |
Mandeep Singh Baines | ea6b7a5 | 2010-08-17 14:03:57 -0700 | [diff] [blame] | 68 | # Delete the local binary package cache. |
Chris Sosa | 4a1e819 | 2010-12-13 14:22:41 -0800 | [diff] [blame] | 69 | rm -rf "${PKGDIR}/packages" |
Mandeep Singh Baines | ea6b7a5 | 2010-08-17 14:03:57 -0700 | [diff] [blame] | 70 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 71 | if [ ${BUILD} == 1 ]; then |
| 72 | echo "Building ${PACKAGE_NAME}" |
Chris Sosa | 605fe88 | 2010-04-22 17:01:32 -0700 | [diff] [blame] | 73 | ESCAPED_PACKAGE=$(python -c \ |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 74 | "import urllib; print urllib.quote('''${PACKAGE_NAME}''')") |
jglasgow | cc71f3a | 2010-03-12 14:30:21 -0500 | [diff] [blame] | 75 | ESCAPED_BOARD=$(python -c \ |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 76 | "import urllib; print urllib.quote('''${BOARD_NAME}''')") |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 77 | |
Chris Sosa | 605fe88 | 2010-04-22 17:01:32 -0700 | [diff] [blame] | 78 | wget $DEVKIT_URL/build \ |
| 79 | --post-data="pkg=${ESCAPED_PACKAGE}&board=${ESCAPED_BOARD}" |
jglasgow | cc71f3a | 2010-03-12 14:30:21 -0500 | [diff] [blame] | 80 | fi |
Ryan Cairns | dd1ceb8 | 2010-03-02 21:35:01 -0800 | [diff] [blame] | 81 | |
Chris Sosa | 136418c | 2010-11-10 16:27:14 -0800 | [diff] [blame] | 82 | echo "Emerging ${PACKAGE_NAME}" |
Chris Sosa | 4a1e819 | 2010-12-13 14:22:41 -0800 | [diff] [blame] | 83 | emerge --getbinpkgonly --usepkgonly "$@" |