Mike Frysinger | 4ed918e | 2012-05-09 15:44:12 -0400 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 2 | # 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 Li | ac5df00 | 2015-12-23 14:18:41 +0000 | [diff] [blame] | 9 | # @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 Harring | cf0c766 | 2012-12-19 23:06:44 -0800 | [diff] [blame] | 18 | |
| 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). |
| 24 | cros-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 Frysinger | 6300c4b | 2013-04-06 22:48:39 -0400 | [diff] [blame] | 43 | RESTRICT+=" mirror" |
Brian Harring | cf0c766 | 2012-12-19 23:06:44 -0800 | [diff] [blame] | 44 | } |
| 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). |
| 51 | cros-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}/" . |
| 65 | cros-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 Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 72 | # @ECLASS-VARIABLE: CROS_BINARY_URI |
| 73 | # @DESCRIPTION: |
| 74 | # URI for the binary may be one of: |
| 75 | # http:// |
| 76 | # https:// |
| 77 | # ssh:// |
Brian Harring | cf0c766 | 2012-12-19 23:06:44 -0800 | [diff] [blame] | 78 | # gs:// |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 79 | # file:// (file is relative to the files directory) |
Brian Harring | cf0c766 | 2012-12-19 23:06:44 -0800 | [diff] [blame] | 80 | # 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 Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 84 | : ${CROS_BINARY_URI:=} |
Brian Harring | cf0c766 | 2012-12-19 23:06:44 -0800 | [diff] [blame] | 85 | if [[ -n "${CROS_BINARY_URI}" ]]; then |
| 86 | cros-binary_add_uri "${CROS_BINARY_URI}" |
| 87 | fi |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 88 | |
Wu-cheng Li | ac5df00 | 2015-12-23 14:18:41 +0000 | [diff] [blame] | 89 | # @ECLASS-VARIABLE: CROS_BINARY_SUM |
| 90 | # @DESCRIPTION: |
| 91 | # Optional SHA-1 sum of the file to be fetched |
| 92 | : ${CROS_BINARY_SUM:=} |
| 93 | |
Puneet Kumar | 0cc9c65 | 2010-08-25 13:35:17 -0700 | [diff] [blame] | 94 | # @ECLASS-VARIABLE: CROS_BINARY_INSTALL_FLAGS |
| 95 | # @DESCRIPTION: |
| 96 | # Optional Flags to use while installing the binary |
| 97 | : ${CROS_BINARY_INSTALL_FLAGS:=} |
| 98 | |
Allen Martin | 967a824 | 2012-03-27 04:51:34 +0000 | [diff] [blame] | 99 | # @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 Frysinger | 4ed918e | 2012-05-09 15:44:12 -0400 | [diff] [blame] | 106 | # Check for EAPI 2+ |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 107 | case "${EAPI:-0}" in |
Mike Frysinger | 4ed918e | 2012-05-09 15:44:12 -0400 | [diff] [blame] | 108 | 4|3|2) ;; |
| 109 | *) die "unsupported EAPI" ;; |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 110 | esac |
| 111 | |
| 112 | cros-binary_check_file() { |
| 113 | local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}" |
Nick Sanders | 97c1055 | 2011-03-11 21:25:36 -0800 | [diff] [blame] | 114 | elog "Checking for cached $target" |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 115 | if [[ -z "${CROS_BINARY_SUM}" ]]; then |
Allen Martin | 967a824 | 2012-03-27 04:51:34 +0000 | [diff] [blame] | 116 | return 1 |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 117 | else |
| 118 | echo "${CROS_BINARY_SUM} ${target}" | |
| 119 | sha1sum -c --quiet >/dev/null 2>&1 |
| 120 | return |
| 121 | fi |
| 122 | } |
| 123 | |
| 124 | cros-binary_fetch() { |
Wu-cheng Li | ac5df00 | 2015-12-23 14:18:41 +0000 | [diff] [blame] | 125 | ${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 Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | cros-binary_src_unpack() { |
Wu-cheng Li | ac5df00 | 2015-12-23 14:18:41 +0000 | [diff] [blame] | 194 | cros-binary_fetch |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | cros-binary_src_install() { |
Brian Harring | cf0c766 | 2012-12-19 23:06:44 -0800 | [diff] [blame] | 198 | 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 Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 204 | |
| 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 Kumar | 0cc9c65 | 2010-08-25 13:35:17 -0700 | [diff] [blame] | 215 | tar "${flags}xpf" "${target}" ${CROS_BINARY_INSTALL_FLAGS} || die "Failed to unpack" |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Wu-cheng Li | ac5df00 | 2015-12-23 14:18:41 +0000 | [diff] [blame] | 218 | EXPORT_FUNCTIONS src_unpack src_install |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 219 | |