blob: df86bbe0c7fb30224a66b6b42879974ff61bc1d9 [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
Allen Martin9ced6402012-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
Kenneth Waters512eb162010-06-02 10:19:12 -070041DEPEND="net-misc/openssh
42 net-misc/wget"
43
44# Check for EAPI 2 or 3
45case "${EAPI:-0}" in
46 3|2) ;;
47 1|0|:) DEPEND="EAPI-UNSUPPORTED" ;;
48esac
49
50cros-binary_check_file() {
51 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
Nick Sanders97c10552011-03-11 21:25:36 -080052 elog "Checking for cached $target"
Kenneth Waters512eb162010-06-02 10:19:12 -070053 if [[ -z "${CROS_BINARY_SUM}" ]]; then
Allen Martin9ced6402012-03-27 04:51:34 +000054 return 1
Kenneth Waters512eb162010-06-02 10:19:12 -070055 else
56 echo "${CROS_BINARY_SUM} ${target}" |
57 sha1sum -c --quiet >/dev/null 2>&1
58 return
59 fi
60}
61
62cros-binary_fetch() {
Allen Martin9ced6402012-03-27 04:51:34 +000063 local uri=${CROS_BINARY_URI}
64 if [[ ! -z "${CROS_BINARY_LOCAL_URI_BASE}" ]]; then
65 uri="${CROS_BINARY_LOCAL_URI_BASE}/${CROS_BINARY_URI##*/}"
66 fi
67
68 local scheme="${uri%%://*}"
69 local non_scheme=${uri##*//}
Kenneth Waters512eb162010-06-02 10:19:12 -070070 local netloc=${non_scheme%%/*}
Anton Staaff1afc3b2010-11-01 14:35:36 -070071 local server=${netloc%%:*}
72 local port=${netloc##*:}
Kenneth Waters512eb162010-06-02 10:19:12 -070073 local path=${non_scheme#*/}
74
Anton Staaff1afc3b2010-11-01 14:35:36 -070075 if [[ -z "${port}" ]]; then
76 port="22"
77 fi
78
Kenneth Watersc3345172010-11-09 10:06:19 -080079 local scp_args="-qo BatchMode=yes -oCheckHostIP=no -P ${port}"
Allen Martin9ced6402012-03-27 04:51:34 +000080 local target="${CROS_BINARY_STORE_DIR}/${uri##*/}"
Kenneth Waters512eb162010-06-02 10:19:12 -070081
82 addwrite "${CROS_BINARY_STORE_DIR}"
83 if [[ ! -d "${CROS_BINARY_STORE_DIR}" ]]; then
84 mkdir -p "${CROS_BINARY_STORE_DIR}" ||
85 die "Failed to mkdir ${CROS_BINARY_STORE_DIR}"
86 fi
87
88 if ! cros-binary_check_file; then
89 rm -f "${target}"
90 case "${scheme}" in
91 http|https)
Allen Martin9ced6402012-03-27 04:51:34 +000092 wget "${uri}" -O "${target}" -nv -nc ||
Kenneth Waters512eb162010-06-02 10:19:12 -070093 rm -f "${target}"
94 ;;
95
96 ssh)
Nick Sanders97c10552011-03-11 21:25:36 -080097 elog "Running: scp ${scp_args} ${server}:/${path} ${target}"
Anton Staaff1afc3b2010-11-01 14:35:36 -070098 scp ${scp_args} "${server}:/${path}" "${target}" ||
Kenneth Waters512eb162010-06-02 10:19:12 -070099 rm -f "${target}"
100 ;;
101
102 file)
103 if [[ "${non_scheme:0:1}" == "/" ]]; then
104 cp "${non_scheme}" "${target}" || rm -f "${target}"
105 else
106 cp "${FILESDIR}/${non_scheme}" "${target}" ||
107 rm -f "${target}"
108 fi
109 ;;
110
111 *)
Allen Martin9ced6402012-03-27 04:51:34 +0000112 die "Protocol for '${uri}' is unsupported."
Kenneth Waters512eb162010-06-02 10:19:12 -0700113 ;;
114 esac
Allen Martin9ced6402012-03-27 04:51:34 +0000115
116 # if no checksum, generate a new one
117 if [[ -z "${CROS_BINARY_SUM}" ]]; then
118 local sha1=( $(sha1sum "${target}") )
119 elog "cros-binary ${target} is not checksummed. Use:"
120 elog "CROS_BINARY_SUM=\"${sha1[0]}\""
121 CROS_BINARY_SUM="${sha1[0]}"
122 fi
Nick Sanders97c10552011-03-11 21:25:36 -0800123 else
124 elog "Not downloading, cached copy available in ${target}"
Kenneth Waters512eb162010-06-02 10:19:12 -0700125 fi
126
Allen Martin9ced6402012-03-27 04:51:34 +0000127 cros-binary_check_file || die "Failed to fetch ${uri}."
Kenneth Waters512eb162010-06-02 10:19:12 -0700128}
129
130cros-binary_src_unpack() {
131 cros-binary_fetch
132}
133
134cros-binary_src_install() {
135 local target="${CROS_BINARY_STORE_DIR}/${CROS_BINARY_URI##*/}"
136
137 local extension="${CROS_BINARY_URI##*.}"
138 local flags
139
140 case "${CROS_BINARY_URI##*.}" in
141 gz|tgz) flags="z";;
142 bz2|tbz2) flags="j";;
143 *) die "Unsupported binary file format ${CROS_BINARY_URI##*.}"
144 esac
145
146 cd "${D}" || die
Puneet Kumar0cc9c652010-08-25 13:35:17 -0700147 tar "${flags}xpf" "${target}" ${CROS_BINARY_INSTALL_FLAGS} || die "Failed to unpack"
Kenneth Waters512eb162010-06-02 10:19:12 -0700148}
149
150EXPORT_FUNCTIONS src_unpack src_install
151