Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally check for presence of pv and use - feedback sought #86

Open
wants to merge 1 commit into
base: flatcar-master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions bin/flatcar-install
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ function ensure_tool() {
command -v "${tool}" >/dev/null || { echo "error: command '${tool}' not found" >&2 ; exit 1; }
}

function have_tool() {
local tool="${1}"
command -v "${tool}"
}

if command -v lbzip2 >/dev/null; then
BZIP_UTIL=lbzip2
else
Expand All @@ -19,7 +24,16 @@ fi

toolset=( blockdev btrfstune cp cut dd gawk gpg grep head ls lsblk mkdir mkfifo mktemp mount rm sed sort tee udevadm wget wipefs )

optional_tools=( pv )

for t in "${toolset[@]}"; do ensure_tool "${t}"; done
for t in "${optional_tools[@]}"; do
declare -r have_"${t}"=$(have_tool "${t}")
h="have_${t}"
if [ -z "${!h}" ] ; then
echo "info: optional command '${t}' not found"
fi
done

error_output() {
echo "Error: return code $? from $BASH_COMMAND" >&2
Expand Down Expand Up @@ -572,9 +586,9 @@ function install_from_file() {

echo "Writing ${IMAGE_FILE}..."
if [[ "${IMAGE_FILE}" =~ \.bz2$ ]]; then
${BZIP_UTIL} -cd "${IMAGE_FILE}" | write_to_disk
${have_pv:-cat} "${IMAGE_FILE}" | ${BZIP_UTIL} -cd | write_to_disk
Copy link
Member

@pothos pothos Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR!
Could we do | "${have_pv:-cat}" | write_do_disk to show the same stats in both cases?

Copy link
Author

@nhi-vanye nhi-vanye Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems pv needs to be the first stage in the pipeline in order to include an ETA; when its streaming between stdin and out it doesn't know the total size...

Fitting it into the other places would obviously be easier in stream mode...

So I guess its code simplicity (streaming) vs features (first in pipeline) - I'm not tied to having an ETA so do you have a preferred approach ?

else
write_to_disk < "${IMAGE_FILE}"
${have_pv:-cat} "${IMAGE_FILE}" | write_to_disk
fi

VERSION_SUMMARY+=" (from ${IMAGE_FILE})"
Expand Down