Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 1 | #! /usr/bin/env bash |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 2 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 3 | # COPYRIGHT NOTICE STARTS HERE |
| 4 | # |
| 5 | # Copyright 2018 © Samsung Electronics Co., Ltd. |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | # |
| 19 | # COPYRIGHT NOTICE ENDS HERE |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 20 | |
| 21 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 22 | # boilerplate |
| 23 | RELATIVE_PATH=../ # relative path from this script to 'common-functions.sh' |
| 24 | if [ "$IS_COMMON_FUNCTIONS_SOURCED" != YES ] ; then |
| 25 | SCRIPT_DIR=$(dirname "${0}") |
| 26 | LOCAL_PATH=$(readlink -f "$SCRIPT_DIR") |
| 27 | . "${LOCAL_PATH}"/"${RELATIVE_PATH}"/common-functions.sh |
| 28 | fi |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 29 | |
Tomáš Levora | 51ec4d1 | 2019-02-27 17:00:25 +0100 | [diff] [blame^] | 30 | LIST="${1}" |
| 31 | IMG_DIR="${2}" |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 32 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 33 | if [[ -z "$IMG_DIR" ]]; then |
| 34 | IMG_DIR="./images" |
| 35 | fi |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 36 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 37 | echo "Creating ${IMG_DIR}" |
| 38 | if [[ ! -d "${IMG_DIR}" ]]; then |
| 39 | mkdir -p "${IMG_DIR}" |
| 40 | fi |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 41 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 42 | save_image() { |
| 43 | local name_tag=$1 |
| 44 | echo "$name_tag" |
| 45 | local img_name=$(echo "${name_tag}" | tr /: __) |
| 46 | local img_path="${IMG_DIR}/${img_name}.tar" |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 47 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 48 | if [[ ! -f "${img_path}" ]] ; then |
| 49 | echo "[DEBUG] save ${name_tag} to ${img_path}" |
| 50 | echo "${name_tag}" >> $IMG_DIR/_image_list.txt |
| 51 | retry docker -l error save -o "${img_path}" ${name_tag} |
| 52 | else |
| 53 | echo "[DEBUG] ${name_tag} already saved" |
| 54 | fi |
| 55 | } |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 56 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 57 | echo "Save all images" |
| 58 | line=1 |
Tomáš Levora | 51ec4d1 | 2019-02-27 17:00:25 +0100 | [diff] [blame^] | 59 | lines=$(wc -l ${LIST}) |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 60 | while read -r image; do |
| 61 | echo "== pkg #$line of $lines ==" |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 62 | |
Tomáš Levora | 51ec4d1 | 2019-02-27 17:00:25 +0100 | [diff] [blame^] | 63 | save_image "${image}" |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 64 | line=$((line+1)) |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 65 | |
Tomáš Levora | 51ec4d1 | 2019-02-27 17:00:25 +0100 | [diff] [blame^] | 66 | done < "${LIST}" |