mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-21 13:41:20 +02:00
build_library: Add generation of disk space usage
This could replace an ad-hoc calculations we do in package-diff.
This commit is contained in:
parent
1c1c0099c7
commit
edc90b4e59
@ -274,6 +274,30 @@ write_contents_with_technical_details() {
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
# Generate a report like the following:
|
||||
#
|
||||
# File Size Used Avail Use% Type
|
||||
# /boot 127M 62M 65M 50% vfat
|
||||
# /usr 983M 721M 212M 78% ext2
|
||||
# / 6,0G 13M 5,6G 1% ext4
|
||||
# SUM 7,0G 796M 5,9G 12% -
|
||||
write_disk_space_usage() {
|
||||
info "Writing ${2##*/}"
|
||||
pushd "${1}" >/dev/null
|
||||
# The sed's first command turns './<path>' into '/<path> ', second
|
||||
# command replaces '- ' with 'SUM' for the total row. All this to
|
||||
# keep the numbers neatly aligned in columns.
|
||||
sudo df \
|
||||
--human-readable \
|
||||
--total \
|
||||
--output='file,size,used,avail,pcent,fstype' \
|
||||
./boot ./usr ./ | \
|
||||
sed \
|
||||
-e 's#^\.\(/[^ ]*\)#\1 #' \
|
||||
-e 's/^- /SUM/' >"${2}"
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
# "equery list" a potentially uninstalled board package
|
||||
query_available_package() {
|
||||
local pkg="$1"
|
||||
@ -656,6 +680,7 @@ finish_image() {
|
||||
local image_kconfig="${10}"
|
||||
local image_initrd_contents="${11}"
|
||||
local image_initrd_contents_wtd="${12}"
|
||||
local image_disk_space_usage="${13}"
|
||||
|
||||
local install_grub=0
|
||||
local disk_img="${BUILD_DIR}/${image_name}"
|
||||
@ -757,9 +782,6 @@ EOF
|
||||
"${BUILD_DIR}/${image_kconfig}"
|
||||
fi
|
||||
|
||||
write_contents "${root_fs_dir}" "${BUILD_DIR}/${image_contents}"
|
||||
write_contents_with_technical_details "${root_fs_dir}" "${BUILD_DIR}/${image_contents_wtd}"
|
||||
|
||||
# Zero all fs free space to make it more compressible so auto-update
|
||||
# payloads become smaller, not fatal since it won't work on linux < 3.2
|
||||
sudo fstrim "${root_fs_dir}" || true
|
||||
@ -814,18 +836,6 @@ EOF
|
||||
>"${BUILD_DIR}/pcrs/kernel.config"
|
||||
fi
|
||||
|
||||
if [[ -n "${image_initrd_contents}" ]] || [[ -n "${image_initrd_contents_wtd}" ]]; then
|
||||
"${BUILD_LIBRARY_DIR}/extract-initramfs-from-vmlinuz.sh" "${root_fs_dir}/boot/flatcar/vmlinuz-a" "${BUILD_DIR}/tmp_initrd_contents"
|
||||
if [[ -n "${image_initrd_contents}" ]]; then
|
||||
write_contents "${BUILD_DIR}/tmp_initrd_contents" "${BUILD_DIR}/${image_initrd_contents}"
|
||||
fi
|
||||
|
||||
if [[ -n "${image_initrd_contents_wtd}" ]]; then
|
||||
write_contents_with_technical_details "${BUILD_DIR}/tmp_initrd_contents" "${BUILD_DIR}/${image_initrd_contents_wtd}"
|
||||
fi
|
||||
rm -rf "${BUILD_DIR}/tmp_initrd_contents"
|
||||
fi
|
||||
|
||||
rm -rf "${BUILD_DIR}"/configroot
|
||||
cleanup_mounts "${root_fs_dir}"
|
||||
trap - EXIT
|
||||
@ -868,4 +878,31 @@ EOF
|
||||
popd >/dev/null
|
||||
rm -rf "${BUILD_DIR}/pcrs"
|
||||
fi
|
||||
|
||||
# Mount the final image again, as readonly, to generate some reports.
|
||||
"${BUILD_LIBRARY_DIR}/disk_util" --disk_layout="${disk_layout}" \
|
||||
mount --read_only "${disk_img}" "${root_fs_dir}"
|
||||
trap "cleanup_mounts '${root_fs_dir}'" EXIT
|
||||
|
||||
write_contents "${root_fs_dir}" "${BUILD_DIR}/${image_contents}"
|
||||
write_contents_with_technical_details "${root_fs_dir}" "${BUILD_DIR}/${image_contents_wtd}"
|
||||
|
||||
if [[ -n "${image_initrd_contents}" ]] || [[ -n "${image_initrd_contents_wtd}" ]]; then
|
||||
"${BUILD_LIBRARY_DIR}/extract-initramfs-from-vmlinuz.sh" "${root_fs_dir}/boot/flatcar/vmlinuz-a" "${BUILD_DIR}/tmp_initrd_contents"
|
||||
if [[ -n "${image_initrd_contents}" ]]; then
|
||||
write_contents "${BUILD_DIR}/tmp_initrd_contents" "${BUILD_DIR}/${image_initrd_contents}"
|
||||
fi
|
||||
|
||||
if [[ -n "${image_initrd_contents_wtd}" ]]; then
|
||||
write_contents_with_technical_details "${BUILD_DIR}/tmp_initrd_contents" "${BUILD_DIR}/${image_initrd_contents_wtd}"
|
||||
fi
|
||||
rm -rf "${BUILD_DIR}/tmp_initrd_contents"
|
||||
fi
|
||||
|
||||
if [[ -n "${image_disk_space_usage}" ]]; then
|
||||
write_disk_space_usage "${root_fs_dir}" "${BUILD_DIR}/${image_disk_space_usage}"
|
||||
fi
|
||||
|
||||
cleanup_mounts "${root_fs_dir}"
|
||||
trap - EXIT
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ create_prod_image() {
|
||||
local image_shim="${image_name%.bin}.shim"
|
||||
local image_initrd_contents="${image_name%.bin}_initrd_contents.txt"
|
||||
local image_initrd_contents_wtd="${image_name%.bin}_initrd_contents_wtd.txt"
|
||||
local image_disk_usage="${image_name%.bin}_disk_usage.txt"
|
||||
|
||||
start_image "${image_name}" "${disk_layout}" "${root_fs_dir}" "${update_group}"
|
||||
|
||||
@ -141,7 +142,8 @@ EOF
|
||||
"${image_shim}" \
|
||||
"${image_kconfig}" \
|
||||
"${image_initrd_contents}" \
|
||||
"${image_initrd_contents_wtd}"
|
||||
"${image_initrd_contents_wtd}" \
|
||||
"${image_disk_usage}"
|
||||
|
||||
# Upload
|
||||
local to_upload=(
|
||||
@ -156,6 +158,7 @@ EOF
|
||||
"${BUILD_DIR}/${image_kconfig}"
|
||||
"${BUILD_DIR}/${image_initrd_contents}"
|
||||
"${BUILD_DIR}/${image_initrd_contents_wtd}"
|
||||
"${BUILD_DIR}/${image_disk_usage}"
|
||||
)
|
||||
|
||||
local files_to_evaluate=( "${BUILD_DIR}/${image_name}" )
|
||||
|
Loading…
x
Reference in New Issue
Block a user