From 8e0014906c9e7e327116ef4a55f78483a8eb4b6e Mon Sep 17 00:00:00 2001 From: Russell Bunch Date: Fri, 27 Sep 2024 16:34:42 -0500 Subject: [PATCH] shfmt and `.editorconfig` --- .editorconfig | 24 ++++++ 93metaldmk8s/metal-dmk8s-disks.sh | 46 +++++------ 93metaldmk8s/metal-dmk8s-genrules.sh | 20 ++--- 93metaldmk8s/metal-dmk8s-lib.sh | 109 +++++++++++++-------------- 93metaldmk8s/module-setup.sh | 30 ++++---- 5 files changed, 126 insertions(+), 103 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..04c96d5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,24 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +insert_final_newline = true +trim_trailing_spaces = true +trim_trailing_whitespace = true + +# 4 space indentation +[*.{py,go}] +indent_size = 4 + +# 2 space indentation +[*.{json,yml,yaml}] +indent_size = 2 + +[*.sh] +indent_size = 2 + +[*.{adoc,md}] +trim_trailing_whitespace = false +indent_size = 4 diff --git a/93metaldmk8s/metal-dmk8s-disks.sh b/93metaldmk8s/metal-dmk8s-disks.sh index b7f04b5..519111a 100755 --- a/93metaldmk8s/metal-dmk8s-disks.sh +++ b/93metaldmk8s/metal-dmk8s-disks.sh @@ -41,34 +41,34 @@ scan_ephemeral # Make the ephemeral disk if it didn't exist. if [ ! -f "$EPHEMERAL_DONE_FILE" ]; then - # Offset the search by the number of disks used up by the main metal dracut module. - ephemeral='' - disks="$(metal_scand)" - IFS=" " read -r -a pool <<< "$disks" - for disk in "${pool[@]}"; do - if [ -n "${ephemeral}" ]; then - break - fi - ephemeral=$(metal_resolve_disk "$disk" "$METAL_DISK_LARGE") - done - - # If no disks were found, die. - # When rd.luks is disabled, this hook-script expects to find a disk. Die if one isn't found. - if [ -z "${ephemeral}" ]; then - metal_dmk8s_die "No disks were found for ephemeral use." - exit 1 - else - echo >&2 "Found the following disk for ephemeral storage: $ephemeral" + # Offset the search by the number of disks used up by the main metal dracut module. + ephemeral='' + disks="$(metal_scand)" + IFS=" " read -r -a pool <<< "$disks" + for disk in "${pool[@]}"; do + if [ -n "${ephemeral}" ]; then + break fi + ephemeral=$(metal_resolve_disk "$disk" "$METAL_DISK_LARGE") + done + + # If no disks were found, die. + # When rd.luks is disabled, this hook-script expects to find a disk. Die if one isn't found. + if [ -z "${ephemeral}" ]; then + metal_dmk8s_die "No disks were found for ephemeral use." + exit 1 + else + echo >&2 "Found the following disk for ephemeral storage: $ephemeral" + fi - # Make the ephemeral disk. - make_ephemeral "$ephemeral" + # Make the ephemeral disk. + make_ephemeral "$ephemeral" else - echo 0 > "$EPHEMERAL_DONE_FILE" + echo 0 > "$EPHEMERAL_DONE_FILE" fi # If our disk was created, satisfy the wait_for_dev hook, otherwise keep waiting. if [ -f "$EPHEMERAL_DONE_FILE" ]; then - ln -s null /dev/metal-k8s - exit 0 + ln -s null /dev/metal-k8s + exit 0 fi diff --git a/93metaldmk8s/metal-dmk8s-genrules.sh b/93metaldmk8s/metal-dmk8s-genrules.sh index 6799d4f..6275242 100755 --- a/93metaldmk8s/metal-dmk8s-genrules.sh +++ b/93metaldmk8s/metal-dmk8s-genrules.sh @@ -27,20 +27,20 @@ command -v getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh -case "$(getarg root)" in - kdump) - # do not do anything for kdump - exit 0 - ;; +case "$(getarg root)" in + kdump) + # do not do anything for kdump + exit 0 + ;; esac command -v wait_for_dev > /dev/null 2>&1 || . /lib/dracut-lib.sh # Only run when luks is disabled and a deployment server is present. if ! getargbool 0 rd.luks -d -n rd_NO_LUKS; then - metal_server=$(getarg metal.server=) - if [ -n "${metal_server:-}" ]; then - wait_for_dev -n /dev/metal-k8s - /sbin/initqueue --settled --onetime --unique /sbin/metal-dmk8s-disks - fi + metal_server=$(getarg metal.server=) + if [ -n "${metal_server:-}" ]; then + wait_for_dev -n /dev/metal-k8s + /sbin/initqueue --settled --onetime --unique /sbin/metal-dmk8s-disks + fi fi diff --git a/93metaldmk8s/metal-dmk8s-lib.sh b/93metaldmk8s/metal-dmk8s-lib.sh index df33632..855099e 100644 --- a/93metaldmk8s/metal-dmk8s-lib.sh +++ b/93metaldmk8s/metal-dmk8s-lib.sh @@ -35,28 +35,28 @@ command -v info > /dev/null 2>&1 || . /lib/dracut-lib.sh # Creates a "done" file if the ephemeral disk and its partitions exist. # scan_ephemeral() { - local conrun_scheme=${METAL_CONRUN%=*} - local conrun_authority=${METAL_CONRUN#*=} - local conlib_scheme=${METAL_CONLIB%=*} - local conlib_authority=${METAL_CONLIB#*=} - local k8slet_scheme=${METAL_K8SLET%=*} - local k8slet_authority=${METAL_K8SLET#*=} - local disks=() - disks+=( "/dev/disk/by-${conrun_scheme,,}/${conrun_authority^^}" ) - disks+=( "/dev/disk/by-${conlib_scheme,,}/${conlib_authority^^}" ) - disks+=( "/dev/disk/by-${k8slet_scheme,,}/${k8slet_authority^^}" ) - for disk in "${disks[@]}"; do - if blkid -s UUID -o value "$disk" >/dev/null; then + local conrun_scheme=${METAL_CONRUN%=*} + local conrun_authority=${METAL_CONRUN#*=} + local conlib_scheme=${METAL_CONLIB%=*} + local conlib_authority=${METAL_CONLIB#*=} + local k8slet_scheme=${METAL_K8SLET%=*} + local k8slet_authority=${METAL_K8SLET#*=} + local disks=() + disks+=("/dev/disk/by-${conrun_scheme,,}/${conrun_authority^^}") + disks+=("/dev/disk/by-${conlib_scheme,,}/${conlib_authority^^}") + disks+=("/dev/disk/by-${k8slet_scheme,,}/${k8slet_authority^^}") + for disk in "${disks[@]}"; do + if blkid -s UUID -o value "$disk" > /dev/null; then - # echo 0 to signal that nothing was done; the disks exist - echo 0 > $EPHEMERAL_DONE_FILE - else - # A disk doesn't exist yet. - # Remove the file if it was created and then exit the loop to start making the disks. - rm -f $EPHEMERAL_DONE_FILE - break - fi - done + # echo 0 to signal that nothing was done; the disks exist + echo 0 > $EPHEMERAL_DONE_FILE + else + # A disk doesn't exist yet. + # Remove the file if it was created and then exit the loop to start making the disks. + rm -f $EPHEMERAL_DONE_FILE + break + fi + done } ############################################################################## @@ -74,52 +74,51 @@ scan_ephemeral() { # paths. make_ephemeral() { - local target="${1:-}" && shift - [ -z "$target" ] && info 'No ephemeral disk.' && return 0 - command -v _trip_udev > /dev/null 2>&1 || . /lib/metal-lib.sh + local target="${1:-}" && shift + [ -z "$target" ] && info 'No ephemeral disk.' && return 0 + command -v _trip_udev > /dev/null 2>&1 || . /lib/metal-lib.sh - parted --wipesignatures -m --align=opt --ignore-busy -s "/dev/${target}" -- mktable gpt \ - mkpart extended xfs 2048s "${METAL_SIZE_CONRUN:-75}GB" \ - mkpart extended xfs "${METAL_SIZE_CONRUN:-75}GB" "${METAL_SIZE_CONLIB:-25}%" \ - mkpart extended xfs "${METAL_SIZE_CONLIB:-25}%" "$((${METAL_SIZE_CONLIB:-25} + ${METAL_SIZE_K8SLET:-25}))%" + parted --wipesignatures -m --align=opt --ignore-busy -s "/dev/${target}" -- mktable gpt \ + mkpart extended xfs 2048s "${METAL_SIZE_CONRUN:-75}GB" \ + mkpart extended xfs "${METAL_SIZE_CONRUN:-75}GB" "${METAL_SIZE_CONLIB:-25}%" \ + mkpart extended xfs "${METAL_SIZE_CONLIB:-25}%" "$((${METAL_SIZE_CONLIB:-25} + ${METAL_SIZE_K8SLET:-25}))%" - # NVME partitions have a "p" to delimit the partition number. - if [[ "$target" =~ "nvme" ]]; then - nvme=1 - fi + # NVME partitions have a "p" to delimit the partition number. + if [[ $target =~ "nvme" ]]; then + nvme=1 + fi - partprobe "/dev/${target}" - _trip_udev - mkfs.xfs -f -L "${METAL_CONRUN#*=}" "/dev/${target}${nvme:+p}1" || metal_dmk8s_die "Failed to create ${METAL_CONRUN#*=}" - partprobe "/dev/${target}" - _trip_udev - mkfs.xfs -f -L "${METAL_CONLIB#*=}" "/dev/${target}${nvme:+p}2" || metal_dmk8s_die "Failed to create ${METAL_CONLIB#*=}" - partprobe "/dev/${target}" - _trip_udev - mkfs.xfs -f -L "${METAL_K8SLET#*=}" "/dev/${target}${nvme:+p}3" || metal_dmk8s_die "Failed to create ${METAL_K8SLET#*=}" + partprobe "/dev/${target}" + _trip_udev + mkfs.xfs -f -L "${METAL_CONRUN#*=}" "/dev/${target}${nvme:+p}1" || metal_dmk8s_die "Failed to create ${METAL_CONRUN#*=}" + partprobe "/dev/${target}" + _trip_udev + mkfs.xfs -f -L "${METAL_CONLIB#*=}" "/dev/${target}${nvme:+p}2" || metal_dmk8s_die "Failed to create ${METAL_CONLIB#*=}" + partprobe "/dev/${target}" + _trip_udev + mkfs.xfs -f -L "${METAL_K8SLET#*=}" "/dev/${target}${nvme:+p}3" || metal_dmk8s_die "Failed to create ${METAL_K8SLET#*=}" - mkdir -p /run/containerd /var/lib/kubelet /var/lib/containerd - { - printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_CONRUN}" /run/containerd xfs "$METAL_FSOPTS_XFS" - printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_CONLIB}" /var/lib/containerd xfs "$METAL_FSOPTS_XFS" - printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_K8SLET}" /var/lib/kubelet xfs "$METAL_FSOPTS_XFS" - } >> "$METAL_FSTAB" + mkdir -p /run/containerd /var/lib/kubelet /var/lib/containerd + { + printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_CONRUN}" /run/containerd xfs "$METAL_FSOPTS_XFS" + printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_CONLIB}" /var/lib/containerd xfs "$METAL_FSOPTS_XFS" + printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_K8SLET}" /var/lib/kubelet xfs "$METAL_FSOPTS_XFS" + } >> "$METAL_FSTAB" - # Mount filesystems. Failure to mount here is fatal. - mount -a -v -T "$METAL_FSTAB" + # Mount filesystems. Failure to mount here is fatal. + mount -a -v -T "$METAL_FSTAB" - # echo 1 to signal that this module create a disk. - echo 1 > $EPHEMERAL_DONE_FILE && return + # echo 1 to signal that this module create a disk. + echo 1 > $EPHEMERAL_DONE_FILE && return } - ############################################################################## # function: metal_dmk8s_die # # Calls metal_die, printing this module's URL to its source code first. # metal_dmk8s_die() { - command -v metal_die > /dev/null 2>&1 || . /lib/metal-lib.sh - echo >&2 "GitHub/Docs: https://github.com/Cray-HPE/dracut-metal-dmk8s" - metal_die "$@" + command -v metal_die > /dev/null 2>&1 || . /lib/metal-lib.sh + echo >&2 "GitHub/Docs: https://github.com/Cray-HPE/dracut-metal-dmk8s" + metal_die "$@" } diff --git a/93metaldmk8s/module-setup.sh b/93metaldmk8s/module-setup.sh index 66054af..d05fb6c 100755 --- a/93metaldmk8s/module-setup.sh +++ b/93metaldmk8s/module-setup.sh @@ -26,32 +26,32 @@ # called by dracut check() { - require_binaries blkid lsblk mkfs.xfs mount parted partprobe || return 1 - return + require_binaries blkid lsblk mkfs.xfs mount parted partprobe || return 1 + return } # called by dracut depends() { - # Needed so overlayFS is available, that's where the new fstab is dropped. - echo metalmdsquash - return 0 + # Needed so overlayFS is available, that's where the new fstab is dropped. + echo metalmdsquash + return 0 } installkernel() { - instmods hostonly='' + instmods hostonly='' } # called by dracut install() { - # the rest is needed by metal-squashfs-url-dract. - # rmdir is needed by dmsquash-live/livenet - inst_multiple chmod lsblk mkfs.xfs parted partprobe sort tail + # the rest is needed by metal-squashfs-url-dract. + # rmdir is needed by dmsquash-live/livenet + inst_multiple chmod lsblk mkfs.xfs parted partprobe sort tail - # shellcheck disable=SC2154 - inst_simple "$moddir/metal-dmk8s-lib.sh" "/lib/metal-dmk8s-lib.sh" - inst_script "$moddir/metal-dmk8s-disks.sh" /sbin/metal-dmk8s-disks + # shellcheck disable=SC2154 + inst_simple "$moddir/metal-dmk8s-lib.sh" "/lib/metal-dmk8s-lib.sh" + inst_script "$moddir/metal-dmk8s-disks.sh" /sbin/metal-dmk8s-disks - inst_hook cmdline 10 "$moddir/parse-metal-dmk8s.sh" - inst_hook pre-udev 10 "$moddir/metal-dmk8s-genrules.sh" - dracut_need_initqueue + inst_hook cmdline 10 "$moddir/parse-metal-dmk8s.sh" + inst_hook pre-udev 10 "$moddir/metal-dmk8s-genrules.sh" + dracut_need_initqueue }