Yo Chiang | 45c81a6 | 2020-02-26 15:33:27 +0800 | [diff] [blame] | 1 | #!/bin/bash |
Yo Chiang | 06cc62e | 2020-03-07 15:36:29 +0800 | [diff] [blame] | 2 | # |
| 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 Chiang | 45c81a6 | 2020-02-26 15:33:27 +0800 | [diff] [blame] | 16 | |
Yo Chiang | fe9bb15 | 2020-02-27 16:38:39 +0800 | [diff] [blame] | 17 | set -ex |
Yo Chiang | 45c81a6 | 2020-02-26 15:33:27 +0800 | [diff] [blame] | 18 | |
| 19 | function usage { |
| 20 | cat <<EOF |
| 21 | Usage: $0 src_product target_product src_dir [dist_dir] |
| 22 | |
| 23 | Create artifacts for |target_product| from the artifacts of |src_product|. |
| 24 | |
| 25 | src_product |
| 26 | Product name to copy artifacts from. e.g. aosp_arm64 |
| 27 | |
| 28 | target_product |
| 29 | Product name to copy artifacts to. e.g. aosp_arm64_pubsign |
| 30 | |
| 31 | src_dir |
| 32 | Directory containing source artifacts. |
| 33 | |
| 34 | dist_dir |
| 35 | Optional. If given then generate any artifact under dist_dir. |
| 36 | Otherwise generate under environment variable DIST_DIR. |
| 37 | EOF |
| 38 | } |
| 39 | |
| 40 | if [[ $# -lt 3 ]]; then |
| 41 | usage |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | SRC_PRODUCT="$1" |
| 46 | TARGET_PRODUCT="$2" |
| 47 | SRC_DIR="$3" |
| 48 | |
| 49 | if [[ $# -ge 4 ]]; then |
| 50 | DIST_DIR="$4" |
| 51 | fi |
| 52 | |
| 53 | readonly SRC_PRODUCT |
| 54 | readonly TARGET_PRODUCT |
| 55 | readonly SRC_DIR |
| 56 | readonly DIST_DIR |
| 57 | |
| 58 | if [[ -z "${DIST_DIR}" ]]; then |
| 59 | echo >&2 '$DIST_DIR is not specified' |
| 60 | exit 1 |
| 61 | fi |
| 62 | |
| 63 | # Create output directory if not already present |
Yo Chiang | fe9bb15 | 2020-02-27 16:38:39 +0800 | [diff] [blame] | 64 | mkdir -p "${DIST_DIR}" || true |
| 65 | |
Yo Chiang | 45c81a6 | 2020-02-26 15:33:27 +0800 | [diff] [blame] | 66 | if [[ ! -d "${DIST_DIR}" ]]; then |
Yo Chiang | fe9bb15 | 2020-02-27 16:38:39 +0800 | [diff] [blame] | 67 | echo >&2 'Cannot create $DIST_DIR or $DIST_DIR is non-existence' |
| 68 | exit 1 |
Yo Chiang | 45c81a6 | 2020-02-26 15:33:27 +0800 | [diff] [blame] | 69 | fi |
| 70 | |
Yo Chiang | fe9bb15 | 2020-02-27 16:38:39 +0800 | [diff] [blame] | 71 | # Show the artifacts to be copied in the log |
| 72 | echo "Artifacts to copy:" |
| 73 | find "${SRC_DIR}" || true |
| 74 | echo |
| 75 | |
Yo Chiang | 45c81a6 | 2020-02-26 15:33:27 +0800 | [diff] [blame] | 76 | # Don't copy logs/ and files whose name starts with $SRC_PRODUCT |
| 77 | rsync --verbose --archive --copy-links --exclude='logs' \ |
Yo Chiang | fe9bb15 | 2020-02-27 16:38:39 +0800 | [diff] [blame] | 78 | --exclude='*.zip' "${SRC_DIR}/" "${DIST_DIR}" |
Yo Chiang | 45c81a6 | 2020-02-26 15:33:27 +0800 | [diff] [blame] | 79 | |
Yo Chiang | fe9bb15 | 2020-02-27 16:38:39 +0800 | [diff] [blame] | 80 | # Rename ${SRC_PRODUCT}-xxx.zip to ${TARGET_PRODUCT}-xxx.zip |
Yo Chiang | abdcbb3 | 2020-02-28 15:43:53 +0800 | [diff] [blame] | 81 | ZIP_PATHNAMES="$(find -L "${SRC_DIR}" -type f -name '*.zip')" |
Yo Chiang | fe9bb15 | 2020-02-27 16:38:39 +0800 | [diff] [blame] | 82 | |
| 83 | echo "ZIP files to be copied and renamed:" |
| 84 | echo "${ZIP_PATHNAMES}" |
| 85 | echo |
| 86 | |
| 87 | for SRC_PATHNAME in ${ZIP_PATHNAMES} ; do |
| 88 | SRC_FILENAME="$(basename ${SRC_PATHNAME})" |
| 89 | TARGET_FILENAME="${SRC_FILENAME/${SRC_PRODUCT}/${TARGET_PRODUCT}}" |
Yo Chiang | abdcbb3 | 2020-02-28 15:43:53 +0800 | [diff] [blame] | 90 | cp --verbose --archive --dereference "${SRC_PATHNAME}" "${DIST_DIR}/${TARGET_FILENAME}" |
Yo Chiang | 45c81a6 | 2020-02-26 15:33:27 +0800 | [diff] [blame] | 91 | done |