blob: ab7f4812fa7ca64656c28c39563a983351fcf791 [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##*/}"
45 if [[ -z "${CROS_BINARY_SUM}" ]]; then
46 [[ -r "${target}" ]]
47 return
48 else
49 echo "${CROS_BINARY_SUM} ${target}" |
50 sha1sum -c --quiet >/dev/null 2>&1
51 return
52 fi
53}
54
55cros-binary_fetch() {
56 local scheme="${CROS_BINARY_URI%%://*}"
57 local non_scheme=${CROS_BINARY_URI##*//}
58 local netloc=${non_scheme%%/*}
Anton Staaf1831c762010-11-01 14:35:36 -070059 local server=${netloc%%:*}
60 local port=${netloc##*:}
Kenneth Waters16b91022010-06-02 10:19:12 -070061 local path=${non_scheme#*/}
62
Anton Staaf1831c762010-11-01 14:35:36 -070063 if [[ -z "${port}" ]]; then
64 port="22"
65 fi
66
67 local scp_args="-qo BatchMode=yes -P ${port}"
Kenneth Waters16b91022010-06-02 10:19:12 -070068 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
69
70 addwrite "${CROS_BINARY_STORE_DIR}"
71 if [[ ! -d "${CROS_BINARY_STORE_DIR}" ]]; then
72 mkdir -p "${CROS_BINARY_STORE_DIR}" ||
73 die "Failed to mkdir ${CROS_BINARY_STORE_DIR}"
74 fi
75
76 if ! cros-binary_check_file; then
77 rm -f "${target}"
78 case "${scheme}" in
79 http|https)
80 wget "${CROS_BINARY_URI}" -O "${target}" -nv -nc ||
81 rm -f "${target}"
82 ;;
83
84 ssh)
Anton Staaf1831c762010-11-01 14:35:36 -070085 scp ${scp_args} "${server}:/${path}" "${target}" ||
Kenneth Waters16b91022010-06-02 10:19:12 -070086 rm -f "${target}"
87 ;;
88
89 file)
90 if [[ "${non_scheme:0:1}" == "/" ]]; then
91 cp "${non_scheme}" "${target}" || rm -f "${target}"
92 else
93 cp "${FILESDIR}/${non_scheme}" "${target}" ||
94 rm -f "${target}"
95 fi
96 ;;
97
98 *)
99 die "Protocol for '${CROS_BINARY_URI}' is unsupported."
100 ;;
101 esac
102 fi
103
104 cros-binary_check_file || die "Failed to fetch ${CROS_BINARY_URI}."
105}
106
107cros-binary_src_unpack() {
108 cros-binary_fetch
109}
110
111cros-binary_src_install() {
112 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
113
114 local extension="${CROS_BINARY_URI##*.}"
115 local flags
116
117 case "${CROS_BINARY_URI##*.}" in
118 gz|tgz) flags="z";;
119 bz2|tbz2) flags="j";;
120 *) die "Unsupported binary file format ${CROS_BINARY_URI##*.}"
121 esac
122
123 cd "${D}" || die
Puneet Kumare5a47262010-08-25 13:35:17 -0700124 tar "${flags}xpf" "${target}" ${CROS_BINARY_INSTALL_FLAGS} || die "Failed to unpack"
Kenneth Waters16b91022010-06-02 10:19:12 -0700125}
126
127EXPORT_FUNCTIONS src_unpack src_install
128