blob: e6426d0ffede672e7c2aeb257b35ed4e9efa08ad [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
Chris Sosa4c9b2f92010-12-13 16:09:06 -080028# Prompts the user to change the root to /usr/local.
29change_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
jglasgowcc71f3a2010-03-12 14:30:21 -050038set -e
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080039
Chris Sosa136418c2010-11-10 16:27:14 -080040# Get variables for the devserver from the lsb-release file.
41DEVKIT_URL=$(grep ^CHROMEOS_DEVSERVER /etc/lsb-release | cut -d = -f 2-)
42BOARD_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 Sosa4a1e8192010-12-13 14:22:41 -080046setup_portage_vars
47
Chris Sosa136418c2010-11-10 16:27:14 -080048# Determine if we should send a build command to the devserver.
49BUILD=1
50if [ x$1 == x-n ]; then
51 BUILD=0
David Jamese3d542a2010-09-24 16:21:19 -070052 shift
53fi
jglasgowcc71f3a2010-03-12 14:30:21 -050054
Chris Sosa605fe882010-04-22 17:01:32 -070055# Package name is the last argument.
Chris Sosa136418c2010-11-10 16:27:14 -080056# TODO(sosa) - Support multiple packages.
57PACKAGE_NAME=${!#}
Chris Sosa605fe882010-04-22 17:01:32 -070058
David Jamese3d542a2010-09-24 16:21:19 -070059# If no package name is provided skip to emerge options.
Chris Sosa136418c2010-11-10 16:27:14 -080060[[ ${PACKAGE_NAME} == -* ]] && BUILD=0
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080061
Chris Sosa4c9b2f92010-12-13 16:09:06 -080062mount -o remount,rw / || change_portage_root
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080063
Chris Sosa136418c2010-11-10 16:27:14 -080064# Re-mount /tmp as exec.
Frank Swiderskidc130812010-10-08 15:42:28 -070065mount -o remount,exec /tmp
Chris Sosa4a1e8192010-12-13 14:22:41 -080066trap "mount -o remount,noexec /tmp" EXIT
Frank Swiderskidc130812010-10-08 15:42:28 -070067
Mandeep Singh Bainesea6b7a52010-08-17 14:03:57 -070068# Delete the local binary package cache.
Chris Sosa4a1e8192010-12-13 14:22:41 -080069rm -rf "${PKGDIR}/packages"
Mandeep Singh Bainesea6b7a52010-08-17 14:03:57 -070070
Chris Sosa136418c2010-11-10 16:27:14 -080071if [ ${BUILD} == 1 ]; then
72 echo "Building ${PACKAGE_NAME}"
Chris Sosa605fe882010-04-22 17:01:32 -070073 ESCAPED_PACKAGE=$(python -c \
Chris Sosa136418c2010-11-10 16:27:14 -080074 "import urllib; print urllib.quote('''${PACKAGE_NAME}''')")
jglasgowcc71f3a2010-03-12 14:30:21 -050075 ESCAPED_BOARD=$(python -c \
Chris Sosa136418c2010-11-10 16:27:14 -080076 "import urllib; print urllib.quote('''${BOARD_NAME}''')")
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080077
Chris Sosa605fe882010-04-22 17:01:32 -070078 wget $DEVKIT_URL/build \
79 --post-data="pkg=${ESCAPED_PACKAGE}&board=${ESCAPED_BOARD}"
jglasgowcc71f3a2010-03-12 14:30:21 -050080fi
Ryan Cairnsdd1ceb82010-03-02 21:35:01 -080081
Chris Sosa136418c2010-11-10 16:27:14 -080082echo "Emerging ${PACKAGE_NAME}"
Chris Sosa4a1e8192010-12-13 14:22:41 -080083emerge --getbinpkgonly --usepkgonly "$@"