3 # ============LICENSE_START=======================================================
4 # Copyright (C) 2021 The Nordix Foundation. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
26 #-------------------------------------------------------------------------------
27 # Print the help message which includes the usage, the expected parameters
28 # and their default values if they are not specified
29 #-------------------------------------------------------------------------------
32 # NOTE: shellcheck complains quoting in the example so SC2086 is disabled
33 # shellcheck disable=SC2086
36 Usage: $(basename ${0}) [-l <file with list of docker images>] [-p <number in parallel>] [-c <container-tool>] [-v] [-h]
38 -l: File with list of docker images. (Default /tmp/docker-list.tmp)
39 -c: container command. (Default docker)
40 -p: number in parallel. (Default 4)
41 -v: Increase verbosity and keep logs for troubleshooting. (Default false)
50 #-------------------------------------------------------------------------------
51 # Parse the arguments that are passed to the script
52 # If an argument is not specified, default values for those are set
54 # The priority order is
55 # - arguments: overrides the default values and values set as environment
56 # values. highest prio.
57 # - env vars: overrides the default values but not the values set from command
59 # - default values: only takes effect if the user doesn't specify the value
60 # of an argument either as an env var or from command line. lowest prio.
61 #-------------------------------------------------------------------------------
62 function parse_cmdline_opts() {
64 # set variables to the values set in env - otherwise, set them to defaults
65 LISTOFDOCKERIMAGES=${LISTOFDOCKERIMAGES:-"/tmp/docker-list.tmp"}
66 PARALLELNU=${PARALLELNU:-4}
68 CONTAINER_TOOL="docker"
70 while getopts ":hl:p:c:v" o; do
73 l) LISTOFDOCKERIMAGES="${OPTARG}" ;;
74 p) PARALLELNU="${OPTARG}" ;;
75 c) CONTAINER_TOOL="${OPTARG}" ;;
76 v) VERBOSITY="true" ;;
77 *) echo "ERROR: Invalid option '-${OPTARG}'"; usage ;;
82 export LISTOFDOCKERIMAGES="${LISTOFDOCKERIMAGES}"
83 export PARALLELNU="${PARALLELNU}"
84 export VERBOSITY="${VERBOSITY}"
85 export CONTAINER_TOOL="${CONTAINER_TOOL}"
88 parse_cmdline_opts "$@"
90 xargs -n 1 -P "$PARALLELNU" "$CONTAINER_TOOL" pull < "$LISTOFDOCKERIMAGES"