Browse Source

Merge pull request #301 from oleorhagen/testfmt

Add a formatter, and format all code files
2.4.x
oleorhagen 4 years ago
committed by GitHub
parent
commit
5fd6880f05
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 47
      .gitlab-ci.yml
  2. 1
      configs/mender_convert_config
  3. 1
      modules/config.sh
  4. 13
      modules/disk.sh
  5. 1
      modules/git.sh
  6. 3
      modules/log.sh
  7. 8
      modules/probe.sh

47
.gitlab-ci.yml

@ -52,6 +52,53 @@ build:
paths: paths:
- image.tar - image.tar
test:format:
stage: test
needs: []
image: alpine:3.13
before_script:
- apk update
- apk upgrade
- apk add --update bash git shfmt
- shfmt -version
script:
- /bin/bash
- SCRIPTS=$(find modules configs scripts -type f
-not -name "*.md"
-not -wholename "scripts/test/*")
# shfmt
## Language=Bash
# -ln bash
## Indent=4 spaces
# -i 4
## List files who differ in formatting
# -l
## Redirect operators should be followed by a space
# -sr
## Indent switch statements
# -ci
## Keep column alignment padding
# -kp
## Binary operators like &&, || may start a new line
# -bn
## Overwrite the source files
# -w
- |
shfmt \
-ln bash \
-i 4 \
-l \
-sr \
-ci \
-kp \
-bn \
-w \
${SCRIPTS}
# Print diff
- git diff HEAD
# Actual test: exits with non zero status if diff
- git diff-index --quiet HEAD
.template_convert_raspbian: &convert_raspbian .template_convert_raspbian: &convert_raspbian
stage: convert stage: convert
needs: needs:

1
configs/mender_convert_config

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

1
modules/config.sh

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

13
modules/disk.sh

@ -48,9 +48,8 @@ disk_get_part_value() {
# #
# $1 - path to disk image # $1 - path to disk image
disk_get_part_nums() { disk_get_part_nums() {
partx --show $1 | tail -n +2 | partx --show $1 | tail -n +2 \
while read line | while read line; do
do
echo $line | awk '{printf "%d\n", $1}' echo $line | awk '{printf "%d\n", $1}'
done done
} }
@ -185,7 +184,6 @@ disk_root_part() {
echo "${root_part}" echo "${root_part}"
} }
# Check if supplied argument is valid partuuid device path. # Check if supplied argument is valid partuuid device path.
# Supports both dos and gpt paths # 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" disk_is_valid_partuuid_gpt_device "$1" || disk_is_valid_partuuid_dos_device "$1"
} }
# Check if supplied argument is valid gpt partuuid device path. # Check if supplied argument is valid gpt partuuid device path.
# #
# Example: /dev/disk/by-partuuid/26445670-f37c-408b-be2c-3ef419866620 # 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})$' 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. # Check if supplied argument is valid dos partuuid device path.
# #
# Example: /dev/disk/by-partuuid/26445670-01 # 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}$' echo "${1}" | grep -qE '^/dev/disk/by-partuuid/[0-9a-f]{8}-[0-9a-f]{2}$'
} }
# Get partuuid from supplied device path. # Get partuuid from supplied device path.
# Supports both dos and gpt paths # Supports both dos and gpt paths
# #
@ -226,7 +221,6 @@ disk_get_partuuid_from_device() {
echo "${1}" | sed "s:/dev/disk/by-partuuid/::" echo "${1}" | sed "s:/dev/disk/by-partuuid/::"
} }
# Get dos disk identifier from supplied device path. # Get dos disk identifier from supplied device path.
# #
# $1 - dos compatible partuuid device path # $1 - dos compatible partuuid device path
@ -238,7 +232,6 @@ disk_get_partuuid_dos_diskid_from_device() {
echo "$partuuid" | cut -d- -f1 echo "$partuuid" | cut -d- -f1
} }
# Get dos partuuid number from supplied device path. # Get dos partuuid number from supplied device path.
# #
# $1 - dos compatible partuuid 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" disk_get_part_device "${MENDER_ROOTFS_PART_B_NUMBER}" "MENDER_ROOTFS_PART_B"
} }
# Get device partition number from device path. # Get device partition number from device path.
# Unrecognized or unsupported device paths will generate an error # Unrecognized or unsupported device paths will generate an error
# #
@ -350,7 +342,6 @@ disk_get_device_base() {
fi fi
} }
# Conditionally redefine partition number/device if fine grained variable set. # Conditionally redefine partition number/device if fine grained variable set.
# #
# $1 - variable name # $1 - variable name

1
modules/git.sh

@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# Print the mender convert version # Print the mender convert version
# #
git_mender_convert_version() { git_mender_convert_version() {

3
modules/log.sh

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

8
modules/probe.sh

@ -213,9 +213,9 @@ probe_kernel_in_boot_and_root() {
if [ -n "${kernel_imagetype_path}" ] && [ "${boot}" == "work/boot" ]; then if [ -n "${kernel_imagetype_path}" ] && [ "${boot}" == "work/boot" ]; then
log_info "Found Linux kernel image in boot part, moving to rootfs/boot" log_info "Found Linux kernel image in boot part, moving to rootfs/boot"
sudo cp ${kernel_imagetype_path} work/rootfs/boot sudo cp ${kernel_imagetype_path} work/rootfs/boot
break; break
elif [ -n "${kernel_imagetype_path}" ]; then elif [ -n "${kernel_imagetype_path}" ]; then
break; break
fi fi
done done
@ -252,9 +252,9 @@ probe_initrd_in_boot_and_root() {
initrd_image_path=$(probe_initrd_image ${boot}) initrd_image_path=$(probe_initrd_image ${boot})
if [ -n "${initrd_image_path}" ] && [ "${boot}" == "work/boot" ]; then if [ -n "${initrd_image_path}" ] && [ "${boot}" == "work/boot" ]; then
sudo cp ${initrd_image_path} work/rootfs/boot sudo cp ${initrd_image_path} work/rootfs/boot
break; break
elif [ -n "${initrd_image_path}" ]; then elif [ -n "${initrd_image_path}" ]; then
break; break
fi fi
done done

Loading…
Cancel
Save