blob: 567ba5a9268fda3e69944e969b3cd70ebd7fe542 [file] [log] [blame]
Kenneth Waters512eb162010-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 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
Kenneth Waters512eb162010-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%%/*}
59 local path=${non_scheme#*/}
60
61 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
62
63 addwrite "${CROS_BINARY_STORE_DIR}"
64 if [[ ! -d "${CROS_BINARY_STORE_DIR}" ]]; then
65 mkdir -p "${CROS_BINARY_STORE_DIR}" ||
66 die "Failed to mkdir ${CROS_BINARY_STORE_DIR}"
67 fi
68
69 if ! cros-binary_check_file; then
70 rm -f "${target}"
71 case "${scheme}" in
72 http|https)
73 wget "${CROS_BINARY_URI}" -O "${target}" -nv -nc ||
74 rm -f "${target}"
75 ;;
76
77 ssh)
78 scp -qo BatchMode=yes "${netloc}:${path}" "${target}" ||
79 rm -f "${target}"
80 ;;
81
82 file)
83 if [[ "${non_scheme:0:1}" == "/" ]]; then
84 cp "${non_scheme}" "${target}" || rm -f "${target}"
85 else
86 cp "${FILESDIR}/${non_scheme}" "${target}" ||
87 rm -f "${target}"
88 fi
89 ;;
90
91 *)
92 die "Protocol for '${CROS_BINARY_URI}' is unsupported."
93 ;;
94 esac
95 fi
96
97 cros-binary_check_file || die "Failed to fetch ${CROS_BINARY_URI}."
98}
99
100cros-binary_src_unpack() {
101 cros-binary_fetch
102}
103
104cros-binary_src_install() {
105 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
106
107 local extension="${CROS_BINARY_URI##*.}"
108 local flags
109
110 case "${CROS_BINARY_URI##*.}" in
111 gz|tgz) flags="z";;
112 bz2|tbz2) flags="j";;
113 *) die "Unsupported binary file format ${CROS_BINARY_URI##*.}"
114 esac
115
116 cd "${D}" || die
Puneet Kumar0cc9c652010-08-25 13:35:17 -0700117 tar "${flags}xpf" "${target}" ${CROS_BINARY_INSTALL_FLAGS} || die "Failed to unpack"
Kenneth Waters512eb162010-06-02 10:19:12 -0700118}
119
120EXPORT_FUNCTIONS src_unpack src_install
121