Antynea / grub-btrfs

Include btrfs snapshots at boot options. (Grub menu)
GNU General Public License v3.0
688 stars 73 forks source link

Fix problem in bash script #312

Open bastien-roucaries opened 5 months ago

bastien-roucaries commented 5 months ago

Hi,

Could you fix the followings problem, found by shellcheck -s bash 41_snapshots-btrfs (the two first one are safe)

In 41_snapshots-btrfs line 44:
[ -f "$grub_btrfs_config" ] && . "$grub_btrfs_config"
                                 ^------------------^ SC1090 (warning): ShellCheck can't follow non-constant source. Use a directive to specify location.

In 41_snapshots-btrfs line 45:
[ -f "${sysconfdir}/default/grub" ] && . "${sysconfdir}/default/grub"
                                         ^--------------------------^ SC1091 (info): Not following: ./default/grub was not specified as input (see shellcheck -x).

In 41_snapshots-btrfs line 80:
[ -f "${GRUB_BTRFS_MKCONFIG_LIB:-/usr/share/grub/grub-mkconfig_lib}" ] && . "${GRUB_BTRFS_MKCONFIG_LIB:-/usr/share/grub/grub-mkconfig_lib}" || print_error "grub-mkconfig_lib couldn't be found"
                                                                       ^-- SC2015 (info): Note that A && B || C is not if-then-else. C may run when A is true.
                                                                            ^-- SC1090 (warning): ShellCheck can't follow non-constant source. Use a directive to specify location.

In 41_snapshots-btrfs line 113:
root_device=$(${grub_probe} --target=device /) # Root device
              ^-----------^ SC2154 (warning): grub_probe is referenced but not assigned.

In 41_snapshots-btrfs line 146:
    local fstabflags=$(grep -oE '^\s*[^#][[:graph:]]+\s+/\s+btrfs\s+[[:graph:]]+' "${grub_btrfs_mount_point}/${snap_dir_name_trim}/etc/fstab" \
          ^--------^ SC2155 (warning): Declare and assign separately to avoid masking return values.

In 41_snapshots-btrfs line 203:
                if   [ "${kversion}" = "${suffix_i}" ];                 then i="${i}";
                                                                             ^-- SC2269 (info): This variable is assigned to itself, so the assignment does nothing.

In 41_snapshots-btrfs line 204:
                elif [ "${kversion}.img" = "${suffix_i}" ];             then i="${i}";
                                                                             ^-- SC2269 (info): This variable is assigned to itself, so the assignment does nothing.

In 41_snapshots-btrfs line 205:
                elif [ "${kversion}-fallback.img" = "${suffix_i}" ];    then i="${i}";
                                                                             ^-- SC2269 (info): This variable is assigned to itself, so the assignment does nothing.

In 41_snapshots-btrfs line 206:
                elif [ "${kversion}.gz" = "${suffix_i}" ];              then i="${i}";
                                                                             ^-- SC2269 (info): This variable is assigned to itself, so the assignment does nothing.

In 41_snapshots-btrfs line 212:
    menuentry '  "${k}" & "${i}" & "${u}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid' {"
                  ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                  ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                           ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                           ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                    ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                    ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                     ^-------------------^ SC2140 (warning): Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"?

Did you mean: 
    menuentry '  ""${k}"" & ""${i}"" & ""${u}""' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid' {"

In 41_snapshots-btrfs line 215:
    menuentry '  "${k}" & "${i}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid' {"
                  ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                  ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                           ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                           ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                            ^-------------------^ SC2140 (warning): Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"?

Did you mean: 
    menuentry '  ""${k}"" & ""${i}""' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid' {"

In 41_snapshots-btrfs line 217:
                    entry "\
                          ^-- SC1078 (warning): Did you forget to close this double quoted string?

In 41_snapshots-btrfs line 228:
        echo 'Loading Snapshot: "${snap_date_trim}" "${snap_dir_name_trim}"'
                                ^-- SC1079 (info): This is actually an end quote, but due to next char it looks suspect.
                                 ^---------------^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                 ^---------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                     ^-------------------^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                                     ^-------------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                          ^-- SC1078 (warning): Did you forget to close this double quoted string?

Did you mean: 
        echo 'Loading Snapshot: ""${snap_date_trim}"" ""${snap_dir_name_trim}""'

In 41_snapshots-btrfs line 229:
        echo 'Loading Kernel: "${k}" ...'
                              ^-- SC1079 (info): This is actually an end quote, but due to next char it looks suspect.
                               ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                               ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                   ^-- SC1078 (warning): Did you forget to close this double quoted string?

Did you mean: 
        echo 'Loading Kernel: ""${k}"" ...'

In 41_snapshots-btrfs line 230:
        linux \"${boot_dir_root_grub}/"${k}"\" root="${LINUX_ROOT_DEVICE}" ${kernel_parameters} ${rootflags}subvol=\""${snap_dir_name_trim}"\""
                                      ^-- SC1079 (info): This is actually an end quote, but due to next char it looks suspect.
                                       ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                       ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                     ^------------------^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                                     ^------------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                                                                      ^-------------------^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                                                                                                      ^-------------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
        linux \"${boot_dir_root_grub}/""${k}""\" root=""${LINUX_ROOT_DEVICE}"" ${kernel_parameters} ${rootflags}subvol=\"""${snap_dir_name_trim}""\""

In 41_snapshots-btrfs line 233:
        echo 'Loading Microcode & Initramfs: "${u}" "${i}" ...'
                                              ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                              ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                     ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                                     ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                         ^-- SC1078 (warning): Did you forget to close this double quoted string?

Did you mean: 
        echo 'Loading Microcode & Initramfs: ""${u}"" ""${i}"" ...'

In 41_snapshots-btrfs line 234:
        initrd \"${boot_dir_root_grub}/"${u}"\" \"${boot_dir_root_grub}/"${i}"\""
                                       ^-- SC1079 (info): This is actually an end quote, but due to next char it looks suspect.
                                        ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                        ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                         ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                                                         ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
        initrd \"${boot_dir_root_grub}/""${u}""\" \"${boot_dir_root_grub}/""${i}""\""

In 41_snapshots-btrfs line 237:
        echo 'Loading Initramfs: "${i}" ...'
                                  ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                  ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                      ^-- SC1078 (warning): Did you forget to close this double quoted string?

Did you mean: 
        echo 'Loading Initramfs: ""${i}"" ...'

In 41_snapshots-btrfs line 238:
        initrd \"${boot_dir_root_grub}/"${i}"\""
                                       ^-- SC1079 (info): This is actually an end quote, but due to next char it looks suspect.
                                        ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                        ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
        initrd \"${boot_dir_root_grub}/""${i}""\""

In 41_snapshots-btrfs line 247:
    menuentry '  "${k}" & "${u}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid' {"
                  ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                  ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                           ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                           ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                            ^-------------------^ SC2140 (warning): Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"?

Did you mean: 
    menuentry '  ""${k}"" & ""${u}""' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid' {"

In 41_snapshots-btrfs line 250:
    menuentry '  "${k}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid' {"
                  ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                  ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                   ^-------------------^ SC2140 (warning): Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"?

Did you mean: 
    menuentry '  ""${k}""' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid' {"

In 41_snapshots-btrfs line 252:
                    entry "\
                          ^-- SC1078 (warning): Did you forget to close this double quoted string?

In 41_snapshots-btrfs line 263:
        echo 'Loading Snapshot: "${snap_date_trim}" "${snap_dir_name_trim}"'
                                ^-- SC1079 (info): This is actually an end quote, but due to next char it looks suspect.
                                 ^---------------^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                 ^---------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                     ^-------------------^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                                     ^-------------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                          ^-- SC1078 (warning): Did you forget to close this double quoted string?

Did you mean: 
        echo 'Loading Snapshot: ""${snap_date_trim}"" ""${snap_dir_name_trim}""'

In 41_snapshots-btrfs line 264:
        echo 'Loading Kernel: "${k}" ...'
                              ^-- SC1079 (info): This is actually an end quote, but due to next char it looks suspect.
                               ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                               ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                   ^-- SC1078 (warning): Did you forget to close this double quoted string?

Did you mean: 
        echo 'Loading Kernel: ""${k}"" ...'

In 41_snapshots-btrfs line 265:
        linux \"${boot_dir_root_grub}/"${k}"\" root="${LINUX_ROOT_DEVICE}" ${kernel_parameters} ${rootflags}subvol=\""${snap_dir_name_trim}"\""
                                      ^-- SC1079 (info): This is actually an end quote, but due to next char it looks suspect.
                                       ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                       ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                     ^------------------^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                                     ^------------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                                                                      ^-------------------^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                                                                                                      ^-------------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
        linux \"${boot_dir_root_grub}/""${k}""\" root=""${LINUX_ROOT_DEVICE}"" ${kernel_parameters} ${rootflags}subvol=\"""${snap_dir_name_trim}""\""

In 41_snapshots-btrfs line 268:
        echo 'Loading Microcode: "${u}" ...'
                                  ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                  ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                      ^-- SC1078 (warning): Did you forget to close this double quoted string?

Did you mean: 
        echo 'Loading Microcode: ""${u}"" ...'

In 41_snapshots-btrfs line 269:
        initrd \"${boot_dir_root_grub}/"${u}"\""
                                       ^-- SC1079 (info): This is actually an end quote, but due to next char it looks suspect.
                                        ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.
                                        ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
        initrd \"${boot_dir_root_grub}/""${u}""\""

In 41_snapshots-btrfs line 300:
        snap=(${snap})
              ^-----^ SC2206 (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

In 41_snapshots-btrfs line 301:
        local path_snapshot=${snap[@]:13:${#snap[@]}}
                            ^-----------------------^ SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.

In 41_snapshots-btrfs line 334:
                [ "${type_snapshot}" = "${ist}" ] && continue 2;
                   ^--------------^ SC2128 (warning): Expanding an array without an index only gives the first element.

In 41_snapshots-btrfs line 339:
                [ "${description_snapshot}" = "${isd}" ] && continue 2;
                   ^---------------------^ SC2128 (warning): Expanding an array without an index only gives the first element.

In 41_snapshots-btrfs line 343:
        local date_snapshot="${snap[@]:10:2}"
                            ^---------------^ SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.

In 41_snapshots-btrfs line 346:
        type_snapshots+=("$type_snapshot")
                          ^------------^ SC2128 (warning): Expanding an array without an index only gives the first element.

In 41_snapshots-btrfs line 347:
        description_snapshots+=("$description_snapshot")
                                 ^-------------------^ SC2128 (warning): Expanding an array without an index only gives the first element.

In 41_snapshots-btrfs line 394:
    snap_snapshot="$snap_dir_name" # Used by "title_format" function
    ^-----------^ SC2034 (warning): snap_snapshot appears unused. Verify use (or export if used externally).

In 41_snapshots-btrfs line 396:
    snap_type="$(echo "$item" | cut -d'|' -f3)" # column_3
    ^-------^ SC2034 (warning): snap_type appears unused. Verify use (or export if used externally).

In 41_snapshots-btrfs line 398:
    snap_description="$(echo "$item" | cut -d'|' -f4)" # column_4
    ^--------------^ SC2034 (warning): snap_description appears unused. Verify use (or export if used externally).

In 41_snapshots-btrfs line 441:
    if [ -z "${list_initramfs}" ]; then list_initramfs=(x); fi
             ^---------------^ SC2128 (warning): Expanding an array without an index only gives the first element.

In 41_snapshots-btrfs line 467:
    if [ -z "${list_ucode}" ]; then list_ucode=(x); fi
             ^-----------^ SC2128 (warning): Expanding an array without an index only gives the first element.

In 41_snapshots-btrfs line 492:
    [[ -z "${GRUB_BTRFS_TITLE_FORMAT}" ]] && GRUB_BTRFS_TITLE_FORMAT=("date" "snapshot" "type" "description"); # Default parameters
           ^------------------------^ SC2128 (warning): Expanding an array without an index only gives the first element.

In 41_snapshots-btrfs line 499:
            lenght_title_column_left=$((((lenght_title_column_left/2)+${#title_column[${GRUB_BTRFS_TITLE_FORMAT[$key],,}]})));
                                        ^-- SC2323 (style): $(( (x) )) is the same as $(( x )). Prefer not wrapping in additional parentheses.

Did you mean: 
            lenght_title_column_left=$(((lenght_title_column_left/2)+${#title_column[${GRUB_BTRFS_TITLE_FORMAT[$key],,}]}));

In 41_snapshots-btrfs line 517:
        if [ -z "${list_kernel}" ]; then continue; fi
                 ^------------^ SC2128 (warning): Expanding an array without an index only gives the first element.

In 41_snapshots-btrfs line 609:
if "${bindir}/${GRUB_BTRFS_SCRIPT_CHECK:-grub-script-check}" "$grub_btrfs_directory/grub-btrfs.new"; then
    ^-------^ SC2154 (warning): bindir is referenced but not assigned.

For more information:
  https://www.shellcheck.net/wiki/SC1078 -- Did you forget to close this doub...
  https://www.shellcheck.net/wiki/SC1090 -- ShellCheck can't follow non-const...
  https://www.shellcheck.net/wiki/SC2027 -- The surrounding quotes actually u...