blob: 8da7ad70de08d06f9a8fd83a4a5546e9bf622ed8 [file] [log] [blame]
Yo Chiang45c81a62020-02-26 15:33:27 +08001#!/bin/bash
Yo Chiang06cc62e2020-03-07 15:36:29 +08002#
3# Copyright (C) 2020 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Yo Chiang45c81a62020-02-26 15:33:27 +080016
Yo Chiangfe9bb152020-02-27 16:38:39 +080017set -ex
Yo Chiang45c81a62020-02-26 15:33:27 +080018
19function usage {
20 cat <<EOF
21Usage: $0 src_product target_product src_dir [dist_dir]
22
23Create artifacts for |target_product| from the artifacts of |src_product|.
24
25src_product
26 Product name to copy artifacts from. e.g. aosp_arm64
27
28target_product
29 Product name to copy artifacts to. e.g. aosp_arm64_pubsign
30
31src_dir
32 Directory containing source artifacts.
33
34dist_dir
35 Optional. If given then generate any artifact under dist_dir.
36 Otherwise generate under environment variable DIST_DIR.
37EOF
38}
39
40if [[ $# -lt 3 ]]; then
41 usage
42 exit 1
43fi
44
45SRC_PRODUCT="$1"
46TARGET_PRODUCT="$2"
47SRC_DIR="$3"
48
49if [[ $# -ge 4 ]]; then
50 DIST_DIR="$4"
51fi
52
53readonly SRC_PRODUCT
54readonly TARGET_PRODUCT
55readonly SRC_DIR
56readonly DIST_DIR
57
58if [[ -z "${DIST_DIR}" ]]; then
59 echo >&2 '$DIST_DIR is not specified'
60 exit 1
61fi
62
63# Create output directory if not already present
Yo Chiangfe9bb152020-02-27 16:38:39 +080064mkdir -p "${DIST_DIR}" || true
65
Yo Chiang45c81a62020-02-26 15:33:27 +080066if [[ ! -d "${DIST_DIR}" ]]; then
Yo Chiangfe9bb152020-02-27 16:38:39 +080067 echo >&2 'Cannot create $DIST_DIR or $DIST_DIR is non-existence'
68 exit 1
Yo Chiang45c81a62020-02-26 15:33:27 +080069fi
70
Yo Chiangfe9bb152020-02-27 16:38:39 +080071# Show the artifacts to be copied in the log
72echo "Artifacts to copy:"
73find "${SRC_DIR}" || true
74echo
75
Yo Chiang45c81a62020-02-26 15:33:27 +080076# Don't copy logs/ and files whose name starts with $SRC_PRODUCT
77rsync --verbose --archive --copy-links --exclude='logs' \
Yo Chiangfe9bb152020-02-27 16:38:39 +080078 --exclude='*.zip' "${SRC_DIR}/" "${DIST_DIR}"
Yo Chiang45c81a62020-02-26 15:33:27 +080079
Yo Chiangfe9bb152020-02-27 16:38:39 +080080# Rename ${SRC_PRODUCT}-xxx.zip to ${TARGET_PRODUCT}-xxx.zip
Yo Chiangabdcbb32020-02-28 15:43:53 +080081ZIP_PATHNAMES="$(find -L "${SRC_DIR}" -type f -name '*.zip')"
Yo Chiangfe9bb152020-02-27 16:38:39 +080082
83echo "ZIP files to be copied and renamed:"
84echo "${ZIP_PATHNAMES}"
85echo
86
87for SRC_PATHNAME in ${ZIP_PATHNAMES} ; do
88 SRC_FILENAME="$(basename ${SRC_PATHNAME})"
89 TARGET_FILENAME="${SRC_FILENAME/${SRC_PRODUCT}/${TARGET_PRODUCT}}"
Yo Chiangabdcbb32020-02-28 15:43:53 +080090 cp --verbose --archive --dereference "${SRC_PATHNAME}" "${DIST_DIR}/${TARGET_FILENAME}"
Yo Chiang45c81a62020-02-26 15:33:27 +080091done