feat(MEN-3052): Automatic decompression of input files
Previously the user would have to manually decompress an input image prior to
handing it over to mender-convert. With this change, files compressed in the
formats: lzma, gzip, or zip archives will be automatically decompressed,
converted, and then recompressed.
Note that the zip archive can only contain one image file, otherwise the
conversion will fail. Thus if the archive contains multiple files, human
interaction is required. This simply involves unzipping the archive yourself,
and then pass in the image, just like in the old workflow.
Ticket: https://tracker.mender.io/browse/MEN-3052
Changelog: Added automatic decompression of input images, so that the convert
tool now accepts compressed input images in the formats: lzma, gzip, and zip.
The images will also be recompressed to the input format automatically.
Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
5 years ago
|
|
|
#
|
|
|
|
# Copyright 2020 Northern.tech AS
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
source modules/zip.sh
|
|
|
|
source modules/log.sh
|
|
|
|
|
|
|
|
# compression_type
|
|
|
|
#
|
|
|
|
# $1 - Path to the compressed disk image
|
|
|
|
#
|
|
|
|
# @return - The MENDER_COMPRESS_IMAGE compression type
|
|
|
|
#
|
|
|
|
function compression_type () {
|
|
|
|
if [[ $# -ne 1 ]]; then
|
|
|
|
log_fatal "compression_type() requires one argument"
|
|
|
|
fi
|
|
|
|
local -r disk_image="${1}"
|
|
|
|
case "${disk_image}" in
|
|
|
|
*.img | *.sdimg | *.wic | *.rpi-sdimg)
|
feat(MEN-3052): Automatic decompression of input files
Previously the user would have to manually decompress an input image prior to
handing it over to mender-convert. With this change, files compressed in the
formats: lzma, gzip, or zip archives will be automatically decompressed,
converted, and then recompressed.
Note that the zip archive can only contain one image file, otherwise the
conversion will fail. Thus if the archive contains multiple files, human
interaction is required. This simply involves unzipping the archive yourself,
and then pass in the image, just like in the old workflow.
Ticket: https://tracker.mender.io/browse/MEN-3052
Changelog: Added automatic decompression of input images, so that the convert
tool now accepts compressed input images in the formats: lzma, gzip, and zip.
The images will also be recompressed to the input format automatically.
Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
5 years ago
|
|
|
echo "none"
|
|
|
|
;;
|
|
|
|
*.gz)
|
|
|
|
echo "gzip"
|
|
|
|
;;
|
|
|
|
*.zip)
|
|
|
|
echo "zip"
|
|
|
|
;;
|
|
|
|
*.xz )
|
|
|
|
echo "lzma"
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
log_fatal "Unsupported compression type: ${disk_image}. Please uncompress the image yourself."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# Decompresses the given input image
|
|
|
|
#
|
|
|
|
# $1 - Path to the compressed image
|
|
|
|
# $2 - Path to the output directory
|
|
|
|
#
|
|
|
|
# @return - Name of the uncompressed image
|
|
|
|
#
|
|
|
|
function decompress_image () {
|
|
|
|
if [[ $# -ne 2 ]]; then
|
|
|
|
log_fatal "decompress_image() requires an image argument and an output directory"
|
|
|
|
fi
|
|
|
|
local -r input_image="${1}"
|
|
|
|
local -r output_dir="${2}"
|
|
|
|
local disk_image="${output_dir}/$(basename ${input_image})"
|
|
|
|
case "$(compression_type ${disk_image})" in
|
|
|
|
none )
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
gzip )
|
|
|
|
log_info "Decompressing ${disk_image}..."
|
|
|
|
disk_image=${disk_image%.gz}
|
|
|
|
zcat "${input_image}" > "${disk_image}"
|
|
|
|
;;
|
|
|
|
zip )
|
|
|
|
log_info "Decompressing ${disk_image}..."
|
|
|
|
filename="$(zip_get_imgname ${input_image})"
|
|
|
|
unzip "${input_image}" -d "${output_dir}" &>/dev/null
|
|
|
|
disk_image="$(dirname ${disk_image})/${filename}"
|
|
|
|
;;
|
|
|
|
lzma )
|
|
|
|
log_info "Decompressing ${disk_image}..."
|
|
|
|
disk_image=${disk_image%.xz}
|
|
|
|
xzcat "${input_image}" > "${disk_image}"
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
log_fatal "Unsupported input image format: ${input_image}. We support: '.img', '.gz', '.zip', '.xz'."
|
feat(MEN-3052): Automatic decompression of input files
Previously the user would have to manually decompress an input image prior to
handing it over to mender-convert. With this change, files compressed in the
formats: lzma, gzip, or zip archives will be automatically decompressed,
converted, and then recompressed.
Note that the zip archive can only contain one image file, otherwise the
conversion will fail. Thus if the archive contains multiple files, human
interaction is required. This simply involves unzipping the archive yourself,
and then pass in the image, just like in the old workflow.
Ticket: https://tracker.mender.io/browse/MEN-3052
Changelog: Added automatic decompression of input images, so that the convert
tool now accepts compressed input images in the formats: lzma, gzip, and zip.
The images will also be recompressed to the input format automatically.
Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
5 years ago
|
|
|
;;
|
|
|
|
esac
|
|
|
|
echo "${disk_image}"
|
|
|
|
}
|