blob: 76da784447ae821fca9fa81ba972214052b946e2 [file] [log] [blame]
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -08001#!/bin/bash
2
Chris Sosa136418c2010-11-10 16:27:14 -08003# Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -08004# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
Chris Sosa136418c2010-11-10 16:27:14 -08007# Prints the arguments and dies.
8print_and_die() {
9 echo $*
10 exit 1
11}
12
Chris Sosa4a1e8192010-12-13 14:22:41 -080013# Set up PORTAGE variables to be rooted in /usr/local/portage.
14setup_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
jglasgowcc71f3a2010-03-12 14:30:21 -050028set -e
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080029
Chris Sosa136418c2010-11-10 16:27:14 -080030# Get variables for the devserver from the lsb-release file.
31DEVKIT_URL=$(grep ^CHROMEOS_DEVSERVER /etc/lsb-release | cut -d = -f 2-)
32BOARD_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 Sosa4a1e8192010-12-13 14:22:41 -080036setup_portage_vars
37
Chris Sosa136418c2010-11-10 16:27:14 -080038# Determine if we should send a build command to the devserver.
39BUILD=1
40if [ x$1 == x-n ]; then
41 BUILD=0
David Jamese3d542a2010-09-24 16:21:19 -070042 shift
43fi
jglasgowcc71f3a2010-03-12 14:30:21 -050044
Chris Sosa605fe882010-04-22 17:01:32 -070045# Package name is the last argument.
Chris Sosa136418c2010-11-10 16:27:14 -080046# TODO(sosa) - Support multiple packages.
47PACKAGE_NAME=${!#}
Chris Sosa605fe882010-04-22 17:01:32 -070048
David Jamese3d542a2010-09-24 16:21:19 -070049# If no package name is provided skip to emerge options.
Chris Sosa136418c2010-11-10 16:27:14 -080050[[ ${PACKAGE_NAME} == -* ]] && BUILD=0
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080051
52mount -o remount,rw /
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080053
Chris Sosa136418c2010-11-10 16:27:14 -080054# Re-mount /tmp as exec.
Frank Swiderskidc130812010-10-08 15:42:28 -070055mount -o remount,exec /tmp
Chris Sosa4a1e8192010-12-13 14:22:41 -080056trap "mount -o remount,noexec /tmp" EXIT
Frank Swiderskidc130812010-10-08 15:42:28 -070057
Mandeep Singh Bainesea6b7a52010-08-17 14:03:57 -070058# Delete the local binary package cache.
Chris Sosa4a1e8192010-12-13 14:22:41 -080059rm -rf "${PKGDIR}/packages"
Mandeep Singh Bainesea6b7a52010-08-17 14:03:57 -070060
Chris Sosa136418c2010-11-10 16:27:14 -080061if [ ${BUILD} == 1 ]; then
62 echo "Building ${PACKAGE_NAME}"
Chris Sosa605fe882010-04-22 17:01:32 -070063 ESCAPED_PACKAGE=$(python -c \
Chris Sosa136418c2010-11-10 16:27:14 -080064 "import urllib; print urllib.quote('''${PACKAGE_NAME}''')")
jglasgowcc71f3a2010-03-12 14:30:21 -050065 ESCAPED_BOARD=$(python -c \
Chris Sosa136418c2010-11-10 16:27:14 -080066 "import urllib; print urllib.quote('''${BOARD_NAME}''')")
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080067
Chris Sosa605fe882010-04-22 17:01:32 -070068 wget $DEVKIT_URL/build \
69 --post-data="pkg=${ESCAPED_PACKAGE}&board=${ESCAPED_BOARD}"
jglasgowcc71f3a2010-03-12 14:30:21 -050070fi
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080071
Chris Sosa136418c2010-11-10 16:27:14 -080072echo "Emerging ${PACKAGE_NAME}"
Chris Sosa4a1e8192010-12-13 14:22:41 -080073emerge --getbinpkgonly --usepkgonly "$@"