Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 1 | # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 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 | |
| 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_URI |
| 15 | # @DESCRIPTION: |
| 16 | # URI for the binary may be one of: |
| 17 | # http:// |
| 18 | # https:// |
| 19 | # ssh:// |
| 20 | # file:// (file is relative to the files directory) |
| 21 | # TODO: Add "->" support if we get file collisions |
| 22 | : ${CROS_BINARY_URI:=} |
| 23 | |
| 24 | # @ECLASS-VARIABLE: CROS_BINARY_SUM |
| 25 | # @DESCRIPTION: |
| 26 | # Optional SHA-1 sum of the file to be fetched |
| 27 | : ${CROS_BINARY_SUM:=} |
| 28 | |
Puneet Kumar | 0cc9c65 | 2010-08-25 13:35:17 -0700 | [diff] [blame] | 29 | # @ECLASS-VARIABLE: CROS_BINARY_INSTALL_FLAGS |
| 30 | # @DESCRIPTION: |
| 31 | # Optional Flags to use while installing the binary |
| 32 | : ${CROS_BINARY_INSTALL_FLAGS:=} |
| 33 | |
Allen Martin | 9ced640 | 2012-03-27 04:51:34 +0000 | [diff] [blame] | 34 | # @ECLASS-VARIABLE: CROS_BINARY_LOCAL_URI_BASE |
| 35 | # @DESCRIPTION: |
| 36 | # Optional URI to override CROS_BINARY_URI location. If this variable |
| 37 | # is used the filename from CROS_BINARY_URI will be used, but the path |
| 38 | # to the binary will be changed. |
| 39 | : ${CROS_BINARY_LOCAL_URI_BASE:=} |
| 40 | |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 41 | DEPEND="net-misc/openssh |
| 42 | net-misc/wget" |
| 43 | |
| 44 | # Check for EAPI 2 or 3 |
| 45 | case "${EAPI:-0}" in |
| 46 | 3|2) ;; |
| 47 | 1|0|:) DEPEND="EAPI-UNSUPPORTED" ;; |
| 48 | esac |
| 49 | |
| 50 | cros-binary_check_file() { |
| 51 | local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}" |
Nick Sanders | 97c1055 | 2011-03-11 21:25:36 -0800 | [diff] [blame] | 52 | elog "Checking for cached $target" |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 53 | if [[ -z "${CROS_BINARY_SUM}" ]]; then |
Allen Martin | 9ced640 | 2012-03-27 04:51:34 +0000 | [diff] [blame] | 54 | return 1 |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 55 | else |
| 56 | echo "${CROS_BINARY_SUM} ${target}" | |
| 57 | sha1sum -c --quiet >/dev/null 2>&1 |
| 58 | return |
| 59 | fi |
| 60 | } |
| 61 | |
| 62 | cros-binary_fetch() { |
Allen Martin | 9ced640 | 2012-03-27 04:51:34 +0000 | [diff] [blame] | 63 | local uri=${CROS_BINARY_URI} |
| 64 | if [[ ! -z "${CROS_BINARY_LOCAL_URI_BASE}" ]]; then |
| 65 | uri="${CROS_BINARY_LOCAL_URI_BASE}/${CROS_BINARY_URI##*/}" |
| 66 | fi |
| 67 | |
| 68 | local scheme="${uri%%://*}" |
| 69 | local non_scheme=${uri##*//} |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 70 | local netloc=${non_scheme%%/*} |
Anton Staaf | f1afc3b | 2010-11-01 14:35:36 -0700 | [diff] [blame] | 71 | local server=${netloc%%:*} |
| 72 | local port=${netloc##*:} |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 73 | local path=${non_scheme#*/} |
| 74 | |
Anton Staaf | f1afc3b | 2010-11-01 14:35:36 -0700 | [diff] [blame] | 75 | if [[ -z "${port}" ]]; then |
| 76 | port="22" |
| 77 | fi |
| 78 | |
Kenneth Waters | c334517 | 2010-11-09 10:06:19 -0800 | [diff] [blame] | 79 | local scp_args="-qo BatchMode=yes -oCheckHostIP=no -P ${port}" |
Allen Martin | 9ced640 | 2012-03-27 04:51:34 +0000 | [diff] [blame] | 80 | local target="${CROS_BINARY_STORE_DIR}/${uri##*/}" |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 81 | |
| 82 | addwrite "${CROS_BINARY_STORE_DIR}" |
| 83 | if [[ ! -d "${CROS_BINARY_STORE_DIR}" ]]; then |
| 84 | mkdir -p "${CROS_BINARY_STORE_DIR}" || |
| 85 | die "Failed to mkdir ${CROS_BINARY_STORE_DIR}" |
| 86 | fi |
| 87 | |
| 88 | if ! cros-binary_check_file; then |
| 89 | rm -f "${target}" |
| 90 | case "${scheme}" in |
| 91 | http|https) |
Allen Martin | 9ced640 | 2012-03-27 04:51:34 +0000 | [diff] [blame] | 92 | wget "${uri}" -O "${target}" -nv -nc || |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 93 | rm -f "${target}" |
| 94 | ;; |
| 95 | |
| 96 | ssh) |
Nick Sanders | 97c1055 | 2011-03-11 21:25:36 -0800 | [diff] [blame] | 97 | elog "Running: scp ${scp_args} ${server}:/${path} ${target}" |
Anton Staaf | f1afc3b | 2010-11-01 14:35:36 -0700 | [diff] [blame] | 98 | scp ${scp_args} "${server}:/${path}" "${target}" || |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 99 | rm -f "${target}" |
| 100 | ;; |
| 101 | |
| 102 | file) |
| 103 | if [[ "${non_scheme:0:1}" == "/" ]]; then |
| 104 | cp "${non_scheme}" "${target}" || rm -f "${target}" |
| 105 | else |
| 106 | cp "${FILESDIR}/${non_scheme}" "${target}" || |
| 107 | rm -f "${target}" |
| 108 | fi |
| 109 | ;; |
| 110 | |
| 111 | *) |
Allen Martin | 9ced640 | 2012-03-27 04:51:34 +0000 | [diff] [blame] | 112 | die "Protocol for '${uri}' is unsupported." |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 113 | ;; |
| 114 | esac |
Allen Martin | 9ced640 | 2012-03-27 04:51:34 +0000 | [diff] [blame] | 115 | |
| 116 | # if no checksum, generate a new one |
| 117 | if [[ -z "${CROS_BINARY_SUM}" ]]; then |
| 118 | local sha1=( $(sha1sum "${target}") ) |
| 119 | elog "cros-binary ${target} is not checksummed. Use:" |
| 120 | elog "CROS_BINARY_SUM=\"${sha1[0]}\"" |
| 121 | CROS_BINARY_SUM="${sha1[0]}" |
| 122 | fi |
Nick Sanders | 97c1055 | 2011-03-11 21:25:36 -0800 | [diff] [blame] | 123 | else |
| 124 | elog "Not downloading, cached copy available in ${target}" |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 125 | fi |
| 126 | |
Allen Martin | 9ced640 | 2012-03-27 04:51:34 +0000 | [diff] [blame] | 127 | cros-binary_check_file || die "Failed to fetch ${uri}." |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | cros-binary_src_unpack() { |
| 131 | cros-binary_fetch |
| 132 | } |
| 133 | |
| 134 | cros-binary_src_install() { |
| 135 | local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}" |
| 136 | |
| 137 | local extension="${CROS_BINARY_URI##*.}" |
| 138 | local flags |
| 139 | |
| 140 | case "${CROS_BINARY_URI##*.}" in |
| 141 | gz|tgz) flags="z";; |
| 142 | bz2|tbz2) flags="j";; |
| 143 | *) die "Unsupported binary file format ${CROS_BINARY_URI##*.}" |
| 144 | esac |
| 145 | |
| 146 | cd "${D}" || die |
Puneet Kumar | 0cc9c65 | 2010-08-25 13:35:17 -0700 | [diff] [blame] | 147 | tar "${flags}xpf" "${target}" ${CROS_BINARY_INSTALL_FLAGS} || die "Failed to unpack" |
Kenneth Waters | 512eb16 | 2010-06-02 10:19:12 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | EXPORT_FUNCTIONS src_unpack src_install |
| 151 | |