blob: a1de9f99928a1c8d4b4fd580d92eb231d15d2e37 [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
29DEPEND="net-misc/openssh
30 net-misc/wget"
31
32# Check for EAPI 2 or 3
33case "${EAPI:-0}" in
34 3|2) ;;
35 1|0|:) DEPEND="EAPI-UNSUPPORTED" ;;
36esac
37
38cros-binary_check_file() {
39 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
40 if [[ -z "${CROS_BINARY_SUM}" ]]; then
41 [[ -r "${target}" ]]
42 return
43 else
44 echo "${CROS_BINARY_SUM} ${target}" |
45 sha1sum -c --quiet >/dev/null 2>&1
46 return
47 fi
48}
49
50cros-binary_fetch() {
51 local scheme="${CROS_BINARY_URI%%://*}"
52 local non_scheme=${CROS_BINARY_URI##*//}
53 local netloc=${non_scheme%%/*}
54 local path=${non_scheme#*/}
55
56 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
57
58 addwrite "${CROS_BINARY_STORE_DIR}"
59 if [[ ! -d "${CROS_BINARY_STORE_DIR}" ]]; then
60 mkdir -p "${CROS_BINARY_STORE_DIR}" ||
61 die "Failed to mkdir ${CROS_BINARY_STORE_DIR}"
62 fi
63
64 if ! cros-binary_check_file; then
65 rm -f "${target}"
66 case "${scheme}" in
67 http|https)
68 wget "${CROS_BINARY_URI}" -O "${target}" -nv -nc ||
69 rm -f "${target}"
70 ;;
71
72 ssh)
73 scp -qo BatchMode=yes "${netloc}:${path}" "${target}" ||
74 rm -f "${target}"
75 ;;
76
77 file)
78 if [[ "${non_scheme:0:1}" == "/" ]]; then
79 cp "${non_scheme}" "${target}" || rm -f "${target}"
80 else
81 cp "${FILESDIR}/${non_scheme}" "${target}" ||
82 rm -f "${target}"
83 fi
84 ;;
85
86 *)
87 die "Protocol for '${CROS_BINARY_URI}' is unsupported."
88 ;;
89 esac
90 fi
91
92 cros-binary_check_file || die "Failed to fetch ${CROS_BINARY_URI}."
93}
94
95cros-binary_src_unpack() {
96 cros-binary_fetch
97}
98
99cros-binary_src_install() {
100 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
101
102 local extension="${CROS_BINARY_URI##*.}"
103 local flags
104
105 case "${CROS_BINARY_URI##*.}" in
106 gz|tgz) flags="z";;
107 bz2|tbz2) flags="j";;
108 *) die "Unsupported binary file format ${CROS_BINARY_URI##*.}"
109 esac
110
111 cd "${D}" || die
112 tar "${flags}xpf" "${target}" || die "Failed to unpack"
113}
114
115EXPORT_FUNCTIONS src_unpack src_install
116