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 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 30 | IMG_DIR="$1" |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 31 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 32 | if [[ -z "$IMG_DIR" ]]; then |
| 33 | IMG_DIR="./images" |
| 34 | fi |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 35 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 36 | echo "Creating ${IMG_DIR}" |
| 37 | if [[ ! -d "${IMG_DIR}" ]]; then |
| 38 | mkdir -p "${IMG_DIR}" |
| 39 | fi |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 40 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 41 | save_image() { |
| 42 | local name_tag=$1 |
| 43 | echo "$name_tag" |
| 44 | local img_name=$(echo "${name_tag}" | tr /: __) |
| 45 | local img_path="${IMG_DIR}/${img_name}.tar" |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 46 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 47 | if [[ ! -f "${img_path}" ]] ; then |
| 48 | echo "[DEBUG] save ${name_tag} to ${img_path}" |
| 49 | echo "${name_tag}" >> $IMG_DIR/_image_list.txt |
| 50 | retry docker -l error save -o "${img_path}" ${name_tag} |
| 51 | else |
| 52 | echo "[DEBUG] ${name_tag} already saved" |
| 53 | fi |
| 54 | } |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 55 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 56 | echo "Save all images" |
| 57 | line=1 |
| 58 | lines=$(docker images|grep -v 'IMAGE ID'|wc -l) |
| 59 | while read -r image; do |
| 60 | echo "== pkg #$line of $lines ==" |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 61 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 62 | name=$(echo $image|awk '{print $1}') |
| 63 | tag=$(echo $image|awk '{print $2}') |
| 64 | save_image "$name:$tag" |
| 65 | line=$((line+1)) |
Petr Ospalý | 03e6124 | 2019-01-03 16:54:50 +0100 | [diff] [blame] | 66 | |
Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 67 | done <<< "$(docker images|grep -v 'IMAGE ID'|awk '{printf("%s %s\n", $1, $2)}'|column -t)" |