blob: 1ce63e4f4bb339535c3fe4f5e604a71b31abeea2 [file] [log] [blame]
Mike Frysinger4ed918e2012-05-09 15:44:12 -04001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Kenneth Waters512eb162010-06-02 10:19:12 -07002# Distributed under the terms of the GNU General Public License v2
3
4#
5# Original Author: The Chromium OS Authors <chromium-os-dev@chromium.org>
6# Purpose: Install binary packages for Chromium OS
7#
8
Wu-cheng Liac5df002015-12-23 14:18:41 +00009# @ECLASS-VARIABLE: CROS_BINARY_STORE_DIR
10# @DESCRIPTION:
11# Storage directory for Chrome OS Binaries
12: ${CROS_BINARY_STORE_DIR:=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/cros-binary}
13
14# @ECLASS-VARIABLE: CROS_BINARY_FETCH_REQUIRED
15# @DESCRIPTION:
16# Internal variable controlling whether cros-binary_fetch is actually ran.
17: ${CROS_BINARY_FETCH_REQUIRED:=true}
Brian Harringcf0c7662012-12-19 23:06:44 -080018
19# @ECLASS-FUNCTION: cros-binary_add_uri
20# @DESCRIPTION:
21# Add a fetch uri to SRC_URI for the given uri. See
22# CROS_BINARY_URI for what is accepted. Note you cannot
23# intermix a non-rewritten ssh w/ (http|https|gs).
24cros-binary_add_uri()
25{
26 if [[ $# -ne 1 ]]; then
27 die "cros-binary_add_uri takes exactly one argument; $# given."
28 fi
29 local uri="$1"
30 if [[ "${uri}" =~ ^ssh://([^@]+)@git.chromium.org[^/]*/(.*)$ ]]; then
31 uri="gs://chromeos-binaries/HOME/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
32 fi
33 case "${uri}" in
34 http://*|https://*|gs://*)
35 SRC_URI+=" ${uri}"
36 CROS_BINARY_FETCH_REQUIRED=false
37 CROS_BINARY_STORE_DIR="${DISTDIR}"
38 ;;
39 *)
40 die "Unknown protocol: ${uri}"
41 ;;
42 esac
Mike Frysinger6300c4b2013-04-06 22:48:39 -040043 RESTRICT+=" mirror"
Brian Harringcf0c7662012-12-19 23:06:44 -080044}
45
46# @ECLASS-FUNCTION: cros-binary_add_gs_uri
47# @DESCRIPTION:
48# Wrapper around cros-binary_add_uri. Invoked with 3 arguments;
49# the bcs user, the overlay, and the filename (or bcs://<uri> for
50# backwards compatibility).
51cros-binary_add_gs_uri() {
52 if [[ $# -ne 3 ]]; then
53 die "cros-binary_add_bcs_uri needs 3 arguments; $# given."
54 fi
55 # Strip leading bcs://...
56 [[ "${3:0:6}" == "bcs://" ]] && set -- "${1}" "${2}" "${3#bcs://}"
57 cros-binary_add_uri "gs://chromeos-binaries/HOME/$1/$2/$3"
58}
59
60# @ECLASS-FUNCTION: cros-binary_add_overlay_uri
61# @DESCRIPTION:
62# Wrapper around cros-binary_add_bcs_uri. Invoked with 2 arguments;
63# the basic board target (x86-alex for example), and the filename; that filename
64# is automatically prefixed with "${CATEGORY}/${PN}/" .
65cros-binary_add_overlay_uri() {
66 if [[ $# -ne 2 ]]; then
67 die "cros-binary_add_bcs_uri_simple needs 2 arguments; $# given."
68 fi
69 cros-binary_add_gs_uri bcs-"$1" overlay-"$1" "${CATEGORY}/${PN}/$2"
70}
71
Kenneth Waters512eb162010-06-02 10:19:12 -070072# @ECLASS-VARIABLE: CROS_BINARY_URI
73# @DESCRIPTION:
74# URI for the binary may be one of:
75# http://
76# https://
77# ssh://
Brian Harringcf0c7662012-12-19 23:06:44 -080078# gs://
Kenneth Waters512eb162010-06-02 10:19:12 -070079# file:// (file is relative to the files directory)
Brian Harringcf0c7662012-12-19 23:06:44 -080080# Additionally, all bcs ssh:// urls are rewritten to gs:// automatically
81# the appropriate GS bucket- although cros-binary_add_uri is the preferred
82# way to do that.
83# TODO: Deprecate this variable's support for ssh and http/https.
Kenneth Waters512eb162010-06-02 10:19:12 -070084: ${CROS_BINARY_URI:=}
Brian Harringcf0c7662012-12-19 23:06:44 -080085if [[ -n "${CROS_BINARY_URI}" ]]; then
86 cros-binary_add_uri "${CROS_BINARY_URI}"
87fi
Kenneth Waters512eb162010-06-02 10:19:12 -070088
Wu-cheng Liac5df002015-12-23 14:18:41 +000089# @ECLASS-VARIABLE: CROS_BINARY_SUM
90# @DESCRIPTION:
91# Optional SHA-1 sum of the file to be fetched
92: ${CROS_BINARY_SUM:=}
93
Puneet Kumar0cc9c652010-08-25 13:35:17 -070094# @ECLASS-VARIABLE: CROS_BINARY_INSTALL_FLAGS
95# @DESCRIPTION:
96# Optional Flags to use while installing the binary
97: ${CROS_BINARY_INSTALL_FLAGS:=}
98
Allen Martin967a8242012-03-27 04:51:34 +000099# @ECLASS-VARIABLE: CROS_BINARY_LOCAL_URI_BASE
100# @DESCRIPTION:
101# Optional URI to override CROS_BINARY_URI location. If this variable
102# is used the filename from CROS_BINARY_URI will be used, but the path
103# to the binary will be changed.
104: ${CROS_BINARY_LOCAL_URI_BASE:=}
105
Mike Frysinger4ed918e2012-05-09 15:44:12 -0400106# Check for EAPI 2+
Kenneth Waters512eb162010-06-02 10:19:12 -0700107case "${EAPI:-0}" in
Mike Frysinger4ed918e2012-05-09 15:44:12 -0400108 4|3|2) ;;
109 *) die "unsupported EAPI" ;;
Kenneth Waters512eb162010-06-02 10:19:12 -0700110esac
111
112cros-binary_check_file() {
113 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
Nick Sanders97c10552011-03-11 21:25:36 -0800114 elog "Checking for cached $target"
Kenneth Waters512eb162010-06-02 10:19:12 -0700115 if [[ -z "${CROS_BINARY_SUM}" ]]; then
Allen Martin967a8242012-03-27 04:51:34 +0000116 return 1
Kenneth Waters512eb162010-06-02 10:19:12 -0700117 else
118 echo "${CROS_BINARY_SUM} ${target}" |
119 sha1sum -c --quiet >/dev/null 2>&1
120 return
121 fi
122}
123
124cros-binary_fetch() {
Wu-cheng Liac5df002015-12-23 14:18:41 +0000125 ${CROS_BINARY_FETCH_REQUIRED} || return 0
126 local uri=${CROS_BINARY_URI}
127 if [[ ! -z "${CROS_BINARY_LOCAL_URI_BASE}" ]]; then
128 uri="${CROS_BINARY_LOCAL_URI_BASE}/${CROS_BINARY_URI##*/}"
129 fi
130
131 local scheme="${uri%%://*}"
132 local non_scheme=${uri#*://}
133 local netloc=${non_scheme%%/*}
134 local server=${netloc%%:*}
135 local port=${netloc##*:}
136 local path=${non_scheme#*/}
137
138 if [[ -z "${port}" ]]; then
139 port="22"
140 fi
141
142 local scp_args="-qo BatchMode=yes -oCheckHostIP=no -P ${port}"
143 local target="${CROS_BINARY_STORE_DIR}/${uri##*/}"
144
145 addwrite "${CROS_BINARY_STORE_DIR}"
146 if [[ ! -d "${CROS_BINARY_STORE_DIR}" ]]; then
147 mkdir -p "${CROS_BINARY_STORE_DIR}" ||
148 die "Failed to mkdir ${CROS_BINARY_STORE_DIR}"
149 fi
150
151 if ! cros-binary_check_file; then
152 rm -f "${target}"
153 case "${scheme}" in
154 http|https|ftp)
155 wget "${uri}" -O "${target}" -nv -nc ||
156 rm -f "${target}"
157 ;;
158
159 ssh)
160 elog "Running: scp ${scp_args} ${server}:/${path} ${target}"
161 scp ${scp_args} "${server}:/${path}" "${target}" ||
162 rm -f "${target}"
163 ;;
164
165 file)
166 if [[ "${non_scheme:0:1}" == "/" ]]; then
167 cp "${non_scheme}" "${target}" || rm -f "${target}"
168 else
169 cp "${FILESDIR}/${non_scheme}" "${target}" ||
170 rm -f "${target}"
171 fi
172 ;;
173
174 *)
175 die "Protocol for '${uri}' is unsupported."
176 ;;
177 esac
178
179 # if no checksum, generate a new one
180 if [[ -z "${CROS_BINARY_SUM}" ]]; then
181 local sha1=( $(sha1sum "${target}") )
182 elog "cros-binary ${target} is not checksummed. Use:"
183 elog "CROS_BINARY_SUM=\"${sha1[0]}\""
184 CROS_BINARY_SUM="${sha1[0]}"
185 fi
186 else
187 elog "Not downloading, cached copy available in ${target}"
188 fi
189
190 cros-binary_check_file || die "Failed to fetch ${uri}."
Kenneth Waters512eb162010-06-02 10:19:12 -0700191}
192
193cros-binary_src_unpack() {
Wu-cheng Liac5df002015-12-23 14:18:41 +0000194 cros-binary_fetch
Kenneth Waters512eb162010-06-02 10:19:12 -0700195}
196
197cros-binary_src_install() {
Brian Harringcf0c7662012-12-19 23:06:44 -0800198 local target="${CROS_BINARY_URI##*/}"
199 if ${CROS_BINARY_FETCH_REQUIRED}; then
200 target="${CROS_BINARY_STORE_DIR}/${target}"
201 else
202 target="${DISTDIR}/${target}"
203 fi
Kenneth Waters512eb162010-06-02 10:19:12 -0700204
205 local extension="${CROS_BINARY_URI##*.}"
206 local flags
207
208 case "${CROS_BINARY_URI##*.}" in
209 gz|tgz) flags="z";;
210 bz2|tbz2) flags="j";;
211 *) die "Unsupported binary file format ${CROS_BINARY_URI##*.}"
212 esac
213
214 cd "${D}" || die
Puneet Kumar0cc9c652010-08-25 13:35:17 -0700215 tar "${flags}xpf" "${target}" ${CROS_BINARY_INSTALL_FLAGS} || die "Failed to unpack"
Kenneth Waters512eb162010-06-02 10:19:12 -0700216}
217
Wu-cheng Liac5df002015-12-23 14:18:41 +0000218EXPORT_FUNCTIONS src_unpack src_install
Kenneth Waters512eb162010-06-02 10:19:12 -0700219