mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 05:26:58 +02:00
By default, pv automatically infers and uses the full width of the terminal. This generally makes sense for a console application, but in the case of pv it just causes the progress bar to be ridiculously wide when run on wide terminals, to the point it's hard to read. This CL is setting it to 80 characters, the widely accepted standard width for a terminal, in cases where the terminal appears to be larger than 80 columns. Note that: * Even with -w, pv appears to be resizing the progress bar as the terminal width changes midway through the run. This means that if a user widens the window, then the progress bar will go wide again and there's nothing to be done about it. * Theoretically, in very rare cases this may lead to a progress bar the exceeds the width of the terminal (i.e. set to 80 columns on a terminal that has just shrunk to fewer columns). The odds for such timing are close to nil and even then the damage is minimal. * This will work for non-terminal runs, or otherwise runs where stty does not produce any output. * To avoid the initialization overhead for all common.sh inclusion, replacing the variable with a function that prints the pv/cat command. BUG=None TEST=Ran ./image_to_usb on wide and narrow terminal windows, it works. Change-Id: I549df1dd29e93909ea646ae9b9e09d9a588ad382 Reviewed-on: https://gerrit.chromium.org/gerrit/40937 Commit-Queue: Gilad Arnold <garnold@chromium.org> Reviewed-by: Gilad Arnold <garnold@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org>
50 lines
1.4 KiB
Bash
50 lines
1.4 KiB
Bash
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
# Common library file to be sourced by build_image,
|
|
# mod_image_for_test.sh, and mod_image_for_recovery.sh. This
|
|
# file ensures that library source files needed by all the scripts
|
|
# are included once, and also takes care of certain bookeeping tasks
|
|
# common to all the scripts.
|
|
|
|
# SCRIPT_ROOT must be set prior to sourcing this file
|
|
. "${SCRIPT_ROOT}/common.sh" || exit 1
|
|
|
|
# All scripts using this file must be run inside the chroot.
|
|
restart_in_chroot_if_needed "$@"
|
|
|
|
INSTALLER_ROOT=/usr/lib/installer
|
|
. "${INSTALLER_ROOT}/chromeos-common.sh" || exit 1
|
|
|
|
locate_gpt
|
|
|
|
should_build_image() {
|
|
# Fast pass back if we should build all incremental images.
|
|
local image_name
|
|
local image_to_build
|
|
|
|
for image_name in "$@"; do
|
|
for image_to_build in ${IMAGES_TO_BUILD}; do
|
|
[ "${image_to_build}" = "${image_name}" ] && return 0
|
|
done
|
|
done
|
|
|
|
return 1
|
|
}
|
|
|
|
# Utility function for creating a copy of an image prior to
|
|
# modification from the BUILD_DIR:
|
|
# $1: source filename
|
|
# $2: destination filename
|
|
copy_image() {
|
|
local src="${BUILD_DIR}/$1"
|
|
local dst="${BUILD_DIR}/$2"
|
|
if should_build_image $1; then
|
|
echo "Creating $2 from $1..."
|
|
$(pv_cat_cmd) "${src}" >"${dst}" || die "Cannot copy $1 to $2"
|
|
else
|
|
mv "${src}" "${dst}" || die "Cannot move $1 to $2"
|
|
fi
|
|
}
|