[Merge] ~waveform/livecd-rootfs:general-tidy into livecd-rootfs:ubuntu/master

Steve Langasek mp+450874 at code.launchpad.net
Fri Sep 8 01:07:04 UTC 2023


Trying to decide whether I think a 20+-line awk script is an improvement in maintainability over sed line noise.  In the meantime, a minor suggestion inline for making the awk script more succinct.

Diff comments:

> diff --git a/live-build/ubuntu-cpc/hooks.d/chroot/999-cpc-fixes.chroot b/live-build/ubuntu-cpc/hooks.d/chroot/999-cpc-fixes.chroot
> index 1295652..e6df7d2 100755
> --- a/live-build/ubuntu-cpc/hooks.d/chroot/999-cpc-fixes.chroot
> +++ b/live-build/ubuntu-cpc/hooks.d/chroot/999-cpc-fixes.chroot
> @@ -65,15 +65,37 @@ if [ -n "${build_name}" -o -n "${serial}" ]; then
>  fi
>  
>  ## --------------
> -# for maverick and newer, use LABEL= for the '/' entry in fstab
> -if [ -n "${root_fs_label}" ]; then
> -   bl="[:blank:]"
> -   lstr="LABEL=${root_fs_label}"
> -   sed -i "s,^[^#${bl}]*\([${bl}]*/[${bl}].*\),${lstr}\1," "${rootd}/etc/fstab"
> -fi
> -cat > /etc/fstab << EOM
> -LABEL=cloudimg-rootfs	/	 ext4	discard,commit=30,errors=remount-ro	0 1
> -EOM
> +awk \
> +    -v root_fs_label="$root_fs_label" \
> +    -v root_fs_options="discard,commit=30,errors=remount-ro" \
> +    '
> +BEGIN { OFS="\t"; count=0; }
> +
> +# Omit the "UNCONFIGURED" warning if it is still present
> +/^# UNCONFIGURED FSTAB/ { next; }
> +
> +# Only modify the first non-comment line where the second field is the root and
> +# omit multiple root definitions
> +/^[^#]/ && $2 == "/" {
> +    if (!count) {
> +        $1="LABEL=" root_fs_label;
> +        $4=root_fs_options;
> +        $6="1";
> +    }
> +    count++;
> +    if (count > 1) next;
> +}

Do I really want to bikeshed an awk program?

Apparently.

/^[^#]/ && $2 == "/" {
    if (!count++) {
        $1="LABEL=" root_fs_label;
        $4=root_fs_options;
        $6="1";
    } else {
        next;
    }
}

> +
> +{ print; }
> +
> +# If we reach the end without seeing a root mount line, add one
> +END {
> +    if (!count) {
> +        print "LABEL=" root_fs_label, "/", "ext4", root_fs_options, "0", "1";
> +    }
> +}
> +' "$rootd"/etc/fstab > "$rootd"/etc/fstab.new
> +mv "$rootd"/etc/fstab.new "$rootd"/etc/fstab
>  
>  # for quantal and newer, add /etc/overlayroot.local.conf
>  # but do not overwrite anything that somehow got there


-- 
https://code.launchpad.net/~waveform/livecd-rootfs/+git/livecd-rootfs/+merge/450874
Your team Ubuntu Core Development Team is subscribed to branch livecd-rootfs:ubuntu/master.




More information about the Ubuntu-reviews mailing list