Skip to content

Commit acd22ac

Browse files
committed
Add code to ignore packages that have no version
1 parent 03d4495 commit acd22ac

File tree

5 files changed

+47
-21
lines changed

5 files changed

+47
-21
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ All notable changes to this project will be documented in this file.
55

66
This changelog was automatically generated using [Caretaker](https://github.com/DevelopersToolbox/caretaker) by [Wolf Software](https://github.com/WolfSoftware)
77

8+
### [v0.1.1](https://github.com/DockerToolbox/version-helper/compare/v0.1.0...v0.1.1)
9+
10+
> Released on May, 24th 2021
11+
12+
- Add code to ignore packages that have no version [`[head]`](https://github.com/DockerToolbox/version-helper/commit/)
13+
814
### [v0.1.0](https://github.com/DockerToolbox/version-helper/releases/v0.1.0)
915

1016
> Released on February, 19th 2021
1117
12-
- The initial commit [`[head]`](https://github.com/DockerToolbox/version-helper/commit/)
18+
- The initial commit [`[03d4495]`](https://github.com/DockerToolbox/version-helper/commit/03d44954e6b185a749c7168fe6502a12aa6f9508)
1319

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ docker run --rm -v "${GRABBER_SCRIPT}":/version-grabber --env-file="${CONFIG_FIL
9494

9595
This is a set of example output using the same [config file](config/config.example) but different operating systems, each time we let the tag default to latest.
9696

97+
> If no version can be found then the package is omitted from the list.
98+
9799
### Alpine
98100

99101
```shell

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.1.1

src/get-versions.sh

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ PREREQ_COMMANDS=( "docker" )
2525
# A set of global flags that we use for configuration. #
2626
# -------------------------------------------------------------------------------- #
2727

28+
NO_HEADERS=false
2829
USE_COLOURS=true # Should we use colours in our output ?
2930
WIDTH=120
31+
3032
# -------------------------------------------------------------------------------- #
3133
# The wrapper function #
3234
# -------------------------------------------------------------------------------- #
@@ -56,8 +58,9 @@ function usage()
5658
fi
5759

5860
cat <<EOF
59-
Usage: $0 [ -h ] [ -c value ] [ -g value ] [ -o value ] [ -s value ] [ -t value ]
61+
Usage: $0 [ -h ] [ -p ] [ -c value ] [ -g value ] [ -o value ] [ -s value ] [ -t value ]
6062
-h : Print this screen
63+
-p : Package list only (No headers or other information)
6164
-c : config file name (including path)
6265
-g : version grabber script (including path) [Default: ~/bin/version-grabber.sh]
6366
-o : which operating system to use (docker container)
@@ -82,11 +85,14 @@ function process_arguments()
8285
usage
8386
fi
8487

85-
while getopts ":hc:g:o:s:t:" arg; do
88+
while getopts ":hpc:g:o:s:t:" arg; do
8689
case $arg in
8790
h)
8891
usage
8992
;;
93+
p)
94+
NO_HEADERS=true
95+
;;
9096
c)
9197
CONFIG_FILE=$(realpath "${OPTARG}")
9298
if [[ ! -r "${CONFIG_FILE}" ]]; then
@@ -231,15 +237,18 @@ function show_success()
231237

232238
function draw_header
233239
{
234-
local config_string_raw config_string
235-
config_string_raw="Config File: $(basename "${CONFIG_FILE}") Grabber Script: $(basename "${GRABBER_SCRIPT}") Docker Container: ${OSNAME}:${TAGNAME} Shell: ${SHELLNAME}"
236-
config_string="${green}Config File:${reset} $(basename "${CONFIG_FILE}") ${green}Grabber Script:${reset} $(basename "${GRABBER_SCRIPT}") ${green}Docker Container:${reset} ${OSNAME}:${TAGNAME} ${green}Shell:${reset} ${SHELLNAME}"
240+
if [[ "${NO_HEADERS}" = false ]]; then
237241

238-
draw_line
239-
center_text "Docker package version grabber"
240-
draw_line
241-
center_text "${config_string}" "${#config_string_raw}"
242-
draw_line
242+
local config_string_raw config_string
243+
config_string_raw="Config File: $(basename "${CONFIG_FILE}") Grabber Script: $(basename "${GRABBER_SCRIPT}") Docker Container: ${OSNAME}:${TAGNAME} Shell: ${SHELLNAME}"
244+
config_string="${green}Config File:${reset} $(basename "${CONFIG_FILE}") ${green}Grabber Script:${reset} $(basename "${GRABBER_SCRIPT}") ${green}Docker Container:${reset} ${OSNAME}:${TAGNAME} ${green}Shell:${reset} ${SHELLNAME}"
245+
246+
draw_line
247+
center_text "Docker package version grabber"
248+
draw_line
249+
center_text "${config_string}" "${#config_string_raw}"
250+
draw_line
251+
fi
243252
}
244253

245254
# -------------------------------------------------------------------------------- #
@@ -281,13 +290,16 @@ function center_text()
281290

282291
function draw_line()
283292
{
284-
local start=$'\e(0' end=$'\e(B' line='qqqqqqqqqqqqqqqq'
293+
if [[ "${NO_HEADERS}" = false ]]; then
285294

286-
while ((${#line} < "${WIDTH}"));
287-
do
288-
line+="$line";
289-
done
290-
printf '%s%s%s\n' "$start" "${line:0:WIDTH}" "$end"
295+
local start=$'\e(0' end=$'\e(B' line='qqqqqqqqqqqqqqqq'
296+
297+
while ((${#line} < "${WIDTH}"));
298+
do
299+
line+="$line";
300+
done
301+
printf '%s%s%s\n' "$start" "${line:0:WIDTH}" "$end"
302+
fi
291303
}
292304

293305

src/version-grabber.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ function get_apk_versions()
2929

3030
for package in $packages; do
3131
version=$(apk policy "${package}" 2>/dev/null | sed -n 2p | sed 's/:$//g' | sed 's/^[[:space:]]*//')
32-
output="${output}\\t\t$package=$version \\ \n"
32+
if [[ -n "${version}" ]]; then
33+
output="${output}\\t\t$package=$version \\ \n"
34+
fi
3335
done
3436
output=${output::-5}
3537
echo -e "${output}"
@@ -57,7 +59,9 @@ function get_apt_versions()
5759

5860
for package in $packages; do
5961
version=$(apt-cache policy "${package}" 2>/dev/null | grep 'Candidate:' | awk -F ' ' '{print $2}')
60-
output="${output}\t\t$package=$version \\ \n"
62+
if [[ -n "${version}" ]]; then
63+
output="${output}\t\t$package=$version \\ \n"
64+
fi
6165
done
6266
output=${output::-5}
6367
echo -e "${output}"
@@ -85,7 +89,9 @@ function get_yum_versions()
8589

8690
for package in $packages; do
8791
version=$(yum info "${package}" 2>/dev/null | grep '^Version' | head -n 1 | awk -F ' : ' '{print $2}')
88-
output="${output}\t\t$package-$version \\ \n"
92+
if [[ -n "${version}" ]]; then
93+
output="${output}\t\t$package-$version \\ \n"
94+
fi
8995
done
9096
output=${output::-5}
9197
echo -e "${output}"

0 commit comments

Comments
 (0)