blob: 8790e3a7c53de6b7db1f154aec269b61448105fd [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
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 Kumar0cc9c652010-08-25 13:35:17 -070029# @ECLASS-VARIABLE: CROS_BINARY_INSTALL_FLAGS
30# @DESCRIPTION:
31# Optional Flags to use while installing the binary
32: ${CROS_BINARY_INSTALL_FLAGS:=}
33
Allen Martin967a8242012-03-27 04:51:34 +000034# @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
Mike Frysinger4ed918e2012-05-09 15:44:12 -040041# Check for EAPI 2+
Kenneth Waters512eb162010-06-02 10:19:12 -070042case "${EAPI:-0}" in
Mike Frysinger4ed918e2012-05-09 15:44:12 -040043 4|3|2) ;;
44 *) die "unsupported EAPI" ;;
Kenneth Waters512eb162010-06-02 10:19:12 -070045esac
46
47cros-binary_check_file() {
48 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
Nick Sanders97c10552011-03-11 21:25:36 -080049 elog "Checking for cached $target"
Kenneth Waters512eb162010-06-02 10:19:12 -070050 if [[ -z "${CROS_BINARY_SUM}" ]]; then
Allen Martin967a8242012-03-27 04:51:34 +000051 return 1
Kenneth Waters512eb162010-06-02 10:19:12 -070052 else
53 echo "${CROS_BINARY_SUM} ${target}" |
54 sha1sum -c --quiet >/dev/null 2>&1
55 return
56 fi
57}
58
59cros-binary_fetch() {
Allen Martin967a8242012-03-27 04:51:34 +000060 local uri=${CROS_BINARY_URI}
61 if [[ ! -z "${CROS_BINARY_LOCAL_URI_BASE}" ]]; then
62 uri="${CROS_BINARY_LOCAL_URI_BASE}/${CROS_BINARY_URI##*/}"
63 fi
64
65 local scheme="${uri%%://*}"
Allen Martin7b2240d2012-11-13 13:17:35 -080066 local non_scheme=${uri#*://}
Kenneth Waters512eb162010-06-02 10:19:12 -070067 local netloc=${non_scheme%%/*}
Anton Staaff1afc3b2010-11-01 14:35:36 -070068 local server=${netloc%%:*}
69 local port=${netloc##*:}
Kenneth Waters512eb162010-06-02 10:19:12 -070070 local path=${non_scheme#*/}
71
Anton Staaff1afc3b2010-11-01 14:35:36 -070072 if [[ -z "${port}" ]]; then
73 port="22"
74 fi
75
Kenneth Watersc3345172010-11-09 10:06:19 -080076 local scp_args="-qo BatchMode=yes -oCheckHostIP=no -P ${port}"
Allen Martin967a8242012-03-27 04:51:34 +000077 local target="${CROS_BINARY_STORE_DIR}/${uri##*/}"
Kenneth Waters512eb162010-06-02 10:19:12 -070078
79 addwrite "${CROS_BINARY_STORE_DIR}"
80 if [[ ! -d "${CROS_BINARY_STORE_DIR}" ]]; then
81 mkdir -p "${CROS_BINARY_STORE_DIR}" ||
82 die "Failed to mkdir ${CROS_BINARY_STORE_DIR}"
83 fi
84
85 if ! cros-binary_check_file; then
86 rm -f "${target}"
87 case "${scheme}" in
88 http|https)
Allen Martin967a8242012-03-27 04:51:34 +000089 wget "${uri}" -O "${target}" -nv -nc ||
Kenneth Waters512eb162010-06-02 10:19:12 -070090 rm -f "${target}"
91 ;;
92
93 ssh)
Nick Sanders97c10552011-03-11 21:25:36 -080094 elog "Running: scp ${scp_args} ${server}:/${path} ${target}"
Anton Staaff1afc3b2010-11-01 14:35:36 -070095 scp ${scp_args} "${server}:/${path}" "${target}" ||
Kenneth Waters512eb162010-06-02 10:19:12 -070096 rm -f "${target}"
97 ;;
98
99 file)
100 if [[ "${non_scheme:0:1}" == "/" ]]; then
101 cp "${non_scheme}" "${target}" || rm -f "${target}"
102 else
103 cp "${FILESDIR}/${non_scheme}" "${target}" ||
104 rm -f "${target}"
105 fi
106 ;;
107
108 *)
Allen Martin967a8242012-03-27 04:51:34 +0000109 die "Protocol for '${uri}' is unsupported."
Kenneth Waters512eb162010-06-02 10:19:12 -0700110 ;;
111 esac
Allen Martin967a8242012-03-27 04:51:34 +0000112
113 # if no checksum, generate a new one
114 if [[ -z "${CROS_BINARY_SUM}" ]]; then
115 local sha1=( $(sha1sum "${target}") )
116 elog "cros-binary ${target} is not checksummed. Use:"
117 elog "CROS_BINARY_SUM=\"${sha1[0]}\""
118 CROS_BINARY_SUM="${sha1[0]}"
119 fi
Nick Sanders97c10552011-03-11 21:25:36 -0800120 else
121 elog "Not downloading, cached copy available in ${target}"
Kenneth Waters512eb162010-06-02 10:19:12 -0700122 fi
123
Allen Martin967a8242012-03-27 04:51:34 +0000124 cros-binary_check_file || die "Failed to fetch ${uri}."
Kenneth Waters512eb162010-06-02 10:19:12 -0700125}
126
127cros-binary_src_unpack() {
128 cros-binary_fetch
129}
130
131cros-binary_src_install() {
132 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
133
134 local extension="${CROS_BINARY_URI##*.}"
135 local flags
136
137 case "${CROS_BINARY_URI##*.}" in
138 gz|tgz) flags="z";;
139 bz2|tbz2) flags="j";;
140 *) die "Unsupported binary file format ${CROS_BINARY_URI##*.}"
141 esac
142
143 cd "${D}" || die
Puneet Kumar0cc9c652010-08-25 13:35:17 -0700144 tar "${flags}xpf" "${target}" ${CROS_BINARY_INSTALL_FLAGS} || die "Failed to unpack"
Kenneth Waters512eb162010-06-02 10:19:12 -0700145}
146
147EXPORT_FUNCTIONS src_unpack src_install
148