blob: a97afeaf1d1518b07c09b52179761e65f28d8550 [file] [log] [blame]
Kenneth Waters16b91022010-06-02 10:19:12 -07001# 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 Kumare5a47262010-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
Kenneth Waters16b91022010-06-02 10:19:12 -070034DEPEND="net-misc/openssh
35 net-misc/wget"
36
37# Check for EAPI 2 or 3
38case "${EAPI:-0}" in
39 3|2) ;;
40 1|0|:) DEPEND="EAPI-UNSUPPORTED" ;;
41esac
42
43cros-binary_check_file() {
44 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
Nick Sanders573e6242011-03-11 21:25:36 -080045 elog "Checking for cached $target"
Kenneth Waters16b91022010-06-02 10:19:12 -070046 if [[ -z "${CROS_BINARY_SUM}" ]]; then
47 [[ -r "${target}" ]]
48 return
49 else
50 echo "${CROS_BINARY_SUM} ${target}" |
51 sha1sum -c --quiet >/dev/null 2>&1
52 return
53 fi
54}
55
56cros-binary_fetch() {
57 local scheme="${CROS_BINARY_URI%%://*}"
58 local non_scheme=${CROS_BINARY_URI##*//}
59 local netloc=${non_scheme%%/*}
Anton Staaf1831c762010-11-01 14:35:36 -070060 local server=${netloc%%:*}
61 local port=${netloc##*:}
Kenneth Waters16b91022010-06-02 10:19:12 -070062 local path=${non_scheme#*/}
63
Anton Staaf1831c762010-11-01 14:35:36 -070064 if [[ -z "${port}" ]]; then
65 port="22"
66 fi
67
Kenneth Watersdf8f48b2010-11-09 10:06:19 -080068 local scp_args="-qo BatchMode=yes -oCheckHostIP=no -P ${port}"
Kenneth Waters16b91022010-06-02 10:19:12 -070069 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
70
71 addwrite "${CROS_BINARY_STORE_DIR}"
72 if [[ ! -d "${CROS_BINARY_STORE_DIR}" ]]; then
73 mkdir -p "${CROS_BINARY_STORE_DIR}" ||
74 die "Failed to mkdir ${CROS_BINARY_STORE_DIR}"
75 fi
76
77 if ! cros-binary_check_file; then
78 rm -f "${target}"
79 case "${scheme}" in
80 http|https)
81 wget "${CROS_BINARY_URI}" -O "${target}" -nv -nc ||
82 rm -f "${target}"
83 ;;
84
85 ssh)
Nick Sanders573e6242011-03-11 21:25:36 -080086 elog "Running: scp ${scp_args} ${server}:/${path} ${target}"
Anton Staaf1831c762010-11-01 14:35:36 -070087 scp ${scp_args} "${server}:/${path}" "${target}" ||
Kenneth Waters16b91022010-06-02 10:19:12 -070088 rm -f "${target}"
89 ;;
90
91 file)
92 if [[ "${non_scheme:0:1}" == "/" ]]; then
93 cp "${non_scheme}" "${target}" || rm -f "${target}"
94 else
95 cp "${FILESDIR}/${non_scheme}" "${target}" ||
96 rm -f "${target}"
97 fi
98 ;;
99
100 *)
101 die "Protocol for '${CROS_BINARY_URI}' is unsupported."
102 ;;
103 esac
Nick Sanders573e6242011-03-11 21:25:36 -0800104 else
105 elog "Not downloading, cached copy available in ${target}"
Kenneth Waters16b91022010-06-02 10:19:12 -0700106 fi
107
108 cros-binary_check_file || die "Failed to fetch ${CROS_BINARY_URI}."
109}
110
111cros-binary_src_unpack() {
112 cros-binary_fetch
113}
114
115cros-binary_src_install() {
116 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
117
118 local extension="${CROS_BINARY_URI##*.}"
119 local flags
120
121 case "${CROS_BINARY_URI##*.}" in
122 gz|tgz) flags="z";;
123 bz2|tbz2) flags="j";;
124 *) die "Unsupported binary file format ${CROS_BINARY_URI##*.}"
125 esac
126
127 cd "${D}" || die
Puneet Kumare5a47262010-08-25 13:35:17 -0700128 tar "${flags}xpf" "${target}" ${CROS_BINARY_INSTALL_FLAGS} || die "Failed to unpack"
Kenneth Waters16b91022010-06-02 10:19:12 -0700129}
130
131EXPORT_FUNCTIONS src_unpack src_install
132