blob: 4c7645566849adb95b6f3c63f6e089ae660fcc51 [file] [log] [blame]
Piotr Perzanowski6d14adb2018-12-18 17:00:08 +01001#! /usr/bin/env bash
Petr Ospalý03e61242019-01-03 16:54:50 +01002
Piotr Perzanowski6d14adb2018-12-18 17:00:08 +01003# 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ý03e61242019-01-03 16:54:50 +010020
21
Piotr Perzanowski6d14adb2018-12-18 17:00:08 +010022# boilerplate
23RELATIVE_PATH=../ # relative path from this script to 'common-functions.sh'
24if [ "$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
28fi
Petr Ospalý03e61242019-01-03 16:54:50 +010029
Tomáš Levora51ec4d12019-02-27 17:00:25 +010030LIST="${1}"
31IMG_DIR="${2}"
Petr Ospalý03e61242019-01-03 16:54:50 +010032
Piotr Perzanowski6d14adb2018-12-18 17:00:08 +010033if [[ -z "$IMG_DIR" ]]; then
34 IMG_DIR="./images"
35fi
Petr Ospalý03e61242019-01-03 16:54:50 +010036
Piotr Perzanowski6d14adb2018-12-18 17:00:08 +010037echo "Creating ${IMG_DIR}"
38if [[ ! -d "${IMG_DIR}" ]]; then
39 mkdir -p "${IMG_DIR}"
40fi
Petr Ospalý03e61242019-01-03 16:54:50 +010041
Piotr Perzanowski6d14adb2018-12-18 17:00:08 +010042save_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ý03e61242019-01-03 16:54:50 +010047
Piotr Perzanowski6d14adb2018-12-18 17:00:08 +010048 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ý03e61242019-01-03 16:54:50 +010056
Piotr Perzanowski6d14adb2018-12-18 17:00:08 +010057echo "Save all images"
58line=1
Tomáš Levora51ec4d12019-02-27 17:00:25 +010059lines=$(wc -l ${LIST})
Piotr Perzanowski6d14adb2018-12-18 17:00:08 +010060while read -r image; do
61 echo "== pkg #$line of $lines =="
Petr Ospalý03e61242019-01-03 16:54:50 +010062
Tomáš Levora51ec4d12019-02-27 17:00:25 +010063 save_image "${image}"
Piotr Perzanowski6d14adb2018-12-18 17:00:08 +010064 line=$((line+1))
Petr Ospalý03e61242019-01-03 16:54:50 +010065
Tomáš Levora51ec4d12019-02-27 17:00:25 +010066done < "${LIST}"