Browse Source

Reformat: All files with shfmt

Changelog: None
Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
2.4.x
Ole Petter 4 years ago
parent
commit
ae6a9e1b03
No known key found for this signature in database GPG Key ID: A7100375167A7B21
  1. 2
      configs/images/raspberrypi_raspbian_config
  2. 1
      configs/mender_convert_config
  3. 4
      mender-convert
  4. 4
      modules/cliparser.sh
  5. 1
      modules/config.sh
  6. 6
      modules/deb.sh
  7. 20
      modules/decompressinput.sh
  8. 59
      modules/disk.sh
  9. 3
      modules/git.sh
  10. 3
      modules/log.sh
  11. 14
      modules/probe.sh
  12. 6
      modules/testscfg.sh
  13. 2
      modules/zip.sh
  14. 4
      scripts/bootstrap-rootfs-overlay-demo-server.sh
  15. 4
      scripts/bootstrap-rootfs-overlay-hosted-server.sh
  16. 4
      scripts/bootstrap-rootfs-overlay-production-server.sh

2
configs/images/raspberrypi_raspbian_config

@ -21,7 +21,7 @@ function grow_data_partition() {
log_info "to fill all the available space on the storage media"
run_and_log_cmd "sudo mkdir -p work/rpi/etc/systemd/system/"
run_and_log_cmd "sudo mkdir -p work/rootfs/etc/systemd/system/data.mount.wants/"
cat <<-EOF > work/rpi/etc/systemd/system/mender-grow-data.service
cat <<- EOF > work/rpi/etc/systemd/system/mender-grow-data.service
[Unit]
Description=Mender service to grow data partition size
DefaultDependencies=no

1
configs/mender_convert_config

@ -32,7 +32,6 @@ MENDER_ARTIFACT_COMPRESSION="gzip"
# this.
MENDER_ENABLE_SYSTEMD=y
# Custom mkfs options for creating the rootfs partition
MENDER_ROOT_PART_MKFS_OPTS=""

4
mender-convert

@ -83,7 +83,7 @@ trap trap_exit EXIT
source modules/git.sh
if [ -z "$MENDER_CONVERT_VERSION" ];then
if [ -z "$MENDER_CONVERT_VERSION" ]; then
MENDER_CONVERT_VERSION=$(git_mender_convert_version)
fi
@ -105,7 +105,7 @@ while (("$#")); do
esac
done
mender_convert_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
mender_convert_dir=$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd)
if [ "${mender_convert_dir}" != "${PWD}" ]; then
echo "You must execute mender-convert from the root directory: ${mender_convert_dir}"
exit 1

4
modules/cliparser.sh

@ -13,8 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
function parse_cli_options () {
while (( "$#" )); do
function parse_cli_options() {
while (("$#")); do
case "$1" in
-o | --overlay)
overlays+=("${2}")

1
modules/config.sh

@ -21,7 +21,6 @@ for config in "${configs[@]}"; do
source "${config}"
done
# Fine grained partition variables override device/number variables where applicable
disk_override_partition_variable "MENDER_BOOT_PART_NUMBER" "${MENDER_BOOT_PART}"
disk_override_partition_variable "MENDER_ROOTFS_PART_A_NUMBER" "${MENDER_ROOTFS_PART_A}"

6
modules/deb.sh

@ -26,7 +26,7 @@ source modules/log.sh
#
# @return - Filename of the downloaded package
#
function deb_from_repo_dist_get () {
function deb_from_repo_dist_get() {
if [[ $# -lt 5 || $# -gt 7 ]]; then
log_fatal "deb_from_repo_dist_get() requires 5 arguments"
fi
@ -65,7 +65,7 @@ function deb_from_repo_dist_get () {
#
# @return - Filename of the downloaded package
#
function deb_from_repo_pool_get () {
function deb_from_repo_pool_get() {
if [[ $# -ne 5 ]]; then
log_fatal "deb_from_repo_pool_get() requires 5 arguments"
fi
@ -92,7 +92,7 @@ function deb_from_repo_pool_get () {
# $1 - Deb package
# $2 - Dest directory
#
function deb_extract_package () {
function deb_extract_package() {
if [[ $# -ne 2 ]]; then
log_fatal "deb_extract_package() requires 2 arguments"
fi

20
modules/decompressinput.sh

@ -22,7 +22,7 @@ source modules/log.sh
#
# @return - The MENDER_COMPRESS_IMAGE compression type
#
function compression_type () {
function compression_type() {
if [[ $# -ne 1 ]]; then
log_fatal "compression_type() requires one argument"
fi
@ -37,10 +37,10 @@ function compression_type () {
*.zip)
echo "zip"
;;
*.xz )
*.xz)
echo "lzma"
;;
* )
*)
log_fatal "Unsupported compression type: ${disk_image}. Please uncompress the image yourself."
;;
esac
@ -53,7 +53,7 @@ function compression_type () {
#
# @return - Name of the uncompressed image
#
function decompress_image () {
function decompress_image() {
if [[ $# -ne 2 ]]; then
log_fatal "decompress_image() requires an image argument and an output directory"
fi
@ -61,26 +61,26 @@ function decompress_image () {
local -r output_dir="${2}"
local disk_image="${output_dir}/$(basename ${input_image})"
case "$(compression_type ${disk_image})" in
none )
none)
:
;;
gzip )
gzip)
log_info "Decompressing ${disk_image}..."
disk_image=${disk_image%.gz}
zcat "${input_image}" > "${disk_image}"
;;
zip )
zip)
log_info "Decompressing ${disk_image}..."
filename="$(zip_get_imgname ${input_image})"
unzip "${input_image}" -d "${output_dir}" &>/dev/null
unzip "${input_image}" -d "${output_dir}" &> /dev/null
disk_image="$(dirname ${disk_image})/${filename}"
;;
lzma )
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'."
;;
esac

59
modules/disk.sh

@ -48,9 +48,8 @@ disk_get_part_value() {
#
# $1 - path to disk image
disk_get_part_nums() {
partx --show $1 | tail -n +2 |
while read line
do
partx --show $1 | tail -n +2 \
| while read line; do
echo $line | awk '{printf "%d\n", $1}'
done
}
@ -69,14 +68,14 @@ disk_extract_part() {
#
# $1 - MiB value
disk_mb_to_sectors() {
echo "$(( (${1} * 1024 * 1024) / 512 ))"
echo "$(((${1} * 1024 * 1024) / 512))"
}
# Convert 512 sectors to MiB
#
# $1 - number of 512 sectors
disk_sectors_to_mb() {
echo "$(( (${1} * 512) / 1024 / 1024 ))"
echo "$(((${1} * 512) / 1024 / 1024))"
}
# Align value (result is number of 512 sectors)
@ -84,14 +83,14 @@ disk_sectors_to_mb() {
# $1 - value to align (number of 512 sectors)
# $2 - alignment in bytes
disk_align_sectors() {
local size_in_bytes=$(( ${1} * 512))
local reminder=$(( ${size_in_bytes} % ${2} ))
local size_in_bytes=$((${1} * 512))
local reminder=$((${size_in_bytes} % ${2}))
if [ $reminder -ne 0 ]; then
size_in_bytes=$(( $size_in_bytes - $reminder + ${2} ))
size_in_bytes=$(($size_in_bytes - $reminder + ${2}))
fi
echo "$(( $size_in_bytes / 512 ))"
echo "$(($size_in_bytes / 512))"
}
# Write file at offset of another file
@ -115,9 +114,9 @@ disk_create_file_system_from_folder() {
run_and_log_cmd "dd if=/dev/zero of=${2} seek=${3} count=0 bs=512 status=none"
case ${1} in
*data/ ) EXTRA_OPTS="${MENDER_DATA_PART_MKFS_OPTS}";;
*rootfs/ ) EXTRA_OPTS="${MENDER_ROOT_PART_MKFS_OPTS}";;
* ) EXTRA_OPTS="";;
*data/) EXTRA_OPTS="${MENDER_DATA_PART_MKFS_OPTS}" ;;
*rootfs/) EXTRA_OPTS="${MENDER_ROOT_PART_MKFS_OPTS}" ;;
*) EXTRA_OPTS="" ;;
esac
case "$4" in
@ -185,7 +184,6 @@ disk_root_part() {
echo "${root_part}"
}
# Check if supplied argument is valid partuuid device path.
# Supports both dos and gpt paths
#
@ -194,7 +192,6 @@ disk_is_valid_partuuid_device() {
disk_is_valid_partuuid_gpt_device "$1" || disk_is_valid_partuuid_dos_device "$1"
}
# Check if supplied argument is valid gpt partuuid device path.
#
# Example: /dev/disk/by-partuuid/26445670-f37c-408b-be2c-3ef419866620
@ -204,7 +201,6 @@ disk_is_valid_partuuid_gpt_device() {
echo "${1}" | grep -qE '^/dev/disk/by-partuuid/([0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12})$'
}
# Check if supplied argument is valid dos partuuid device path.
#
# Example: /dev/disk/by-partuuid/26445670-01
@ -214,7 +210,6 @@ disk_is_valid_partuuid_dos_device() {
echo "${1}" | grep -qE '^/dev/disk/by-partuuid/[0-9a-f]{8}-[0-9a-f]{2}$'
}
# Get partuuid from supplied device path.
# Supports both dos and gpt paths
#
@ -226,7 +221,6 @@ disk_get_partuuid_from_device() {
echo "${1}" | sed "s:/dev/disk/by-partuuid/::"
}
# Get dos disk identifier from supplied device path.
#
# $1 - dos compatible partuuid device path
@ -238,7 +232,6 @@ disk_get_partuuid_dos_diskid_from_device() {
echo "$partuuid" | cut -d- -f1
}
# Get dos partuuid number from supplied device path.
#
# $1 - dos compatible partuuid device path
@ -283,7 +276,6 @@ disk_root_part_b_device() {
disk_get_part_device "${MENDER_ROOTFS_PART_B_NUMBER}" "MENDER_ROOTFS_PART_B"
}
# Get device partition number from device path.
# Unrecognized or unsupported device paths will generate an error
#
@ -291,20 +283,20 @@ disk_root_part_b_device() {
disk_get_device_part_number() {
dev_part="unknown"
case "$1" in
/dev/nvme*n*p* )
/dev/nvme*n*p*)
dev_part=$(echo $1 | cut -dp -f2)
;;
/dev/mmcblk*p* )
/dev/mmcblk*p*)
dev_part=$(echo $1 | cut -dp -f2)
;;
/dev/[sh]d[a-z][1-9]* )
/dev/[sh]d[a-z][1-9]*)
dev_part=${1##*d[a-z]}
;;
ubi*_* )
ubi*_*)
dev_part=$(echo $1 | cut -d_ -f2)
;;
/dev/disk/by-partuuid/* )
if disk_is_valid_partuuid_dos_device "$1";then
/dev/disk/by-partuuid/*)
if disk_is_valid_partuuid_dos_device "$1"; then
dev_part=$(disk_get_partuuid_dos_part_number "$1")
dev_part=$((16#${dev_part}))
else
@ -312,7 +304,7 @@ disk_get_device_part_number() {
fi
;;
esac
part=$(printf "%d" $dev_part 2>/dev/null)
part=$(printf "%d" $dev_part 2> /dev/null)
if [ $? = 1 ]; then
log_fatal "Could not determine partition number from '${1}'"
else
@ -327,19 +319,19 @@ disk_get_device_part_number() {
disk_get_device_base() {
dev_base=""
case "$1" in
/dev/nvme*n*p* )
/dev/nvme*n*p*)
dev_base=$(echo $1 | cut -dp -f1)
;;
/dev/mmcblk*p* )
/dev/mmcblk*p*)
dev_base=$(echo $1 | cut -dp -f1)
;;
/dev/[sh]d[a-z][1-9]* )
/dev/[sh]d[a-z][1-9]*)
dev_base=${1%%[1-9]*}
;;
ubi*_* )
ubi*_*)
dev_base=$(echo $1 | cut -d_ -f1)
;;
/dev/disk/by-partuuid/* )
/dev/disk/by-partuuid/*)
log_fatal "device base does not exist for GPT partuuid: '$1'"
;;
esac
@ -350,18 +342,17 @@ disk_get_device_base() {
fi
}
# Conditionally redefine partition number/device if fine grained variable set.
#
# $1 - variable name
# $2 - variable value
disk_override_partition_variable() {
if [ "${MENDER_ENABLE_PARTUUID}" == "y" ]; then
if disk_is_valid_partuuid_dos_device "${2}";then
if disk_is_valid_partuuid_dos_device "${2}"; then
eval "${1}"=$(disk_get_device_part_number "${2}")
fi
else
if [ -n "${2}" ];then
if [ -n "${2}" ]; then
eval "${1}"=$(disk_get_device_part_number "${2}")
MENDER_STORAGE_DEVICE_BASE=$(disk_get_device_base "${2}")
fi

3
modules/git.sh

@ -14,9 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Print the mender convert version
#
git_mender_convert_version() {
git describe --tags --dirty --exact-match 2>/dev/null || git rev-parse --short HEAD
git describe --tags --dirty --exact-match 2> /dev/null || git rev-parse --short HEAD
}

3
modules/log.sh

@ -18,7 +18,6 @@
# from sub-directories
log_file="${MENDER_CONVERT_LOG_FILE:-${PWD}/work/convert.log}"
# Add some colour to the log messages
YELLOW='\033[1;33m' # Warning
@ -33,7 +32,7 @@ function log {
local -r timestamp=$(date +"%Y-%m-%d %H:%M:%S")
local -r script_name="$(basename "$0")"
echo -e "${timestamp} [${level}] [$script_name] ${message}" >> ${log_file}
>&2 echo -e "${timestamp} [${level}] [$script_name] ${message}"
echo >&2 -e "${timestamp} [${level}] [$script_name] ${message}"
}
function local_log_debug {

14
modules/probe.sh

@ -145,7 +145,7 @@ probe_kernel_image() {
kernel_image_path=$(head -n 1 <<< "$kernels" | cut -f2- -d' ')
n=$(wc -l <<< "$kernels")
if [ "$n" -gt "1" ];then
if [ "$n" -gt "1" ]; then
msg=$(awk '{printf " %s\n", $2}' <<< ${kernels})
log_warn "Found multiple kernel images: \n\n${msg}\n"
log_warn "Selecting newest kernel image: \n\n ${kernel_image_path}\n"
@ -180,7 +180,7 @@ probe_initrd_image() {
initrd_image_path=$(head -n 1 <<< "$initrds" | cut -f2- -d' ')
n=$(wc -l <<< "$initrds")
if [ "$n" -gt "1" ];then
if [ "$n" -gt "1" ]; then
msg=$(awk '{printf " %s\n", $2}' <<< ${initrds})
log_warn "Found multiple initrd images: \n\n${msg}\n"
log_warn "Selecting newest initrd: \n\n ${initrd_image_path}\n"
@ -213,9 +213,9 @@ probe_kernel_in_boot_and_root() {
if [ -n "${kernel_imagetype_path}" ] && [ "${boot}" == "work/boot" ]; then
log_info "Found Linux kernel image in boot part, moving to rootfs/boot"
sudo cp ${kernel_imagetype_path} work/rootfs/boot
break;
break
elif [ -n "${kernel_imagetype_path}" ]; then
break;
break
fi
done
@ -252,9 +252,9 @@ probe_initrd_in_boot_and_root() {
initrd_image_path=$(probe_initrd_image ${boot})
if [ -n "${initrd_image_path}" ] && [ "${boot}" == "work/boot" ]; then
sudo cp ${initrd_image_path} work/rootfs/boot
break;
break
elif [ -n "${initrd_image_path}" ]; then
break;
break
fi
done
@ -307,7 +307,7 @@ is_efi_compatible_kernel() {
kernel_path="$1"
case "$(probe_arch)" in
arm|aarch64)
arm | aarch64)
# On ARM, as of version 2.04, GRUB can only boot kernels which have an EFI
# stub in them. See MEN-2404.
if ! file -k $kernel_path | fgrep -q 'EFI application'; then

6
modules/testscfg.sh

@ -15,7 +15,7 @@
# Init tests configuration file
#
function testscfg_init () {
function testscfg_init() {
rm -f work/testscfg.tmp
touch work/testscfg.tmp
}
@ -25,7 +25,7 @@ function testscfg_init () {
# $1 - key
# $2 - value
#
function testscfg_add () {
function testscfg_add() {
if [[ $# -ne 2 ]]; then
log_fatal "testscfg_add() requires 2 arguments"
fi
@ -38,7 +38,7 @@ function testscfg_add () {
#
# $1 - Filename
#
function testscfg_save () {
function testscfg_save() {
if [[ $# -ne 1 ]]; then
log_fatal "testscfg_save() requires 1 argument"
fi

2
modules/zip.sh

@ -20,7 +20,7 @@
#
# @return - Name of the img contained in the archive
#
function zip_get_imgname () {
function zip_get_imgname() {
if [[ $# -ne 1 ]]; then
log_fatal "zip_get_imgname requires one argument"
fi

4
scripts/bootstrap-rootfs-overlay-demo-server.sh

@ -17,7 +17,7 @@
# Exit if any command exits with a non-zero exit status.
set -o errexit
root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )
root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}")/../" && pwd)
if [ "${root_dir}" != "${PWD}" ]; then
echo "You must execute $(basename $0) from the root directory: ${root_dir}"
exit 1
@ -25,7 +25,7 @@ fi
server_ip=""
output_dir=""
while (( "$#" )); do
while (("$#")); do
case "$1" in
-o | --output-dir)
output_dir="${2}"

4
scripts/bootstrap-rootfs-overlay-hosted-server.sh

@ -17,7 +17,7 @@
# Exit if any command exits with a non-zero exit status.
set -o errexit
root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )
root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}")/../" && pwd)
if [ "${root_dir}" != "${PWD}" ]; then
echo "You must execute $(basename $0) from the root directory: ${root_dir}"
exit 1
@ -25,7 +25,7 @@ fi
tenant_token=""
output_dir=""
while (( "$#" )); do
while (("$#")); do
case "$1" in
-t | --tenant-token)
tenant_token="${2}"

4
scripts/bootstrap-rootfs-overlay-production-server.sh

@ -17,7 +17,7 @@
# Exit if any command exits with a non-zero exit status.
set -o errexit
root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )
root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}")/../" && pwd)
if [ "${root_dir}" != "${PWD}" ]; then
echo "You must execute $(basename $0) from the root directory: ${root_dir}"
exit 1
@ -25,7 +25,7 @@ fi
server_url=""
output_dir=""
while (( "$#" )); do
while (("$#")); do
case "$1" in
-o | --output-dir)
output_dir="${2}"

Loading…
Cancel
Save