[PATCH] base-files: reduce `mkdir` and `sed` calls

Adrian Schmutzler mail at adrianschmutzler.de
Sat Sep 11 10:47:53 PDT 2021


Hi Paul,

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces at lists.openwrt.org]
> On Behalf Of Paul Spooren
> Sent: Mittwoch, 8. September 2021 23:14
> To: openwrt-devel at lists.openwrt.org
> Cc: Paul Spooren <mail at aparcar.org>
> Subject: [PATCH] base-files: reduce `mkdir` and `sed` calls
> 
> There is no need in calling `mkdir` every single time, instead give it
multiple
> folders at once.
> 
> Also there is no need to create a folder (i.e. /etc/) after a sub folder
of /etc/
> was already created.
> 
> Additionally there is no need to call the `sed` version replacement script
> multiple times with partly the same files.

I'd consider to split this into two patches, one for the sed calls and one
for the mkdir calls.

Apart from that, mostly to share/document my test here:
I wondered what happens when an error occurs during multi-arg mkdir, e.g.
mkdir -p dir1 dir2 dir3
Actually, if dir2 triggers an error, dir3 will still be created. Thus, this
patch is also cosmetic in terms of error handling.

You might want to add that information to the commit message (or just ignore
it, if that's obvious to anybody except me).

Best

Adrian
 

> 
> Signed-off-by: Paul Spooren <mail at aparcar.org>
> ---
>  package/base-files/Makefile | 42 ++++++++++++++++++-------------------
>  1 file changed, 21 insertions(+), 21 deletions(-)
> 
> diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index
> 58ad08c63a..af5c0e6b00 100644
> --- a/package/base-files/Makefile
> +++ b/package/base-files/Makefile
> @@ -150,37 +150,38 @@ define Package/base-files/install
> 
>  	$(VERSION_SED_SCRIPT) \
>  		$(1)/etc/banner \
> +		$(1)/etc/device_info \
> +		$(1)/etc/openwrt_release \
>  		$(1)/etc/openwrt_version \
>  		$(1)/usr/lib/os-release
> 
> -	$(VERSION_SED_SCRIPT) \
> -		$(1)/etc/openwrt_release \
> -		$(1)/etc/device_info \
> -		$(1)/usr/lib/os-release
> 
>  	$(SED) "s#%PATH%#$(TARGET_INIT_PATH)#g" \
>  		$(1)/sbin/hotplug-call \
>  		$(1)/etc/preinit \
>  		$(1)/etc/profile
> 
> -	mkdir -p $(1)/CONTROL
> -	mkdir -p $(1)/dev
> -	mkdir -p $(1)/etc/config
> -	mkdir -p $(1)/etc/crontabs
> -	mkdir -p $(1)/etc/rc.d
> -	mkdir -p $(1)/overlay
> -	mkdir -p $(1)/lib/firmware
> +	mkdir -p \
> +		$(1)/CONTROL \
> +		$(1)/dev \
> +		$(1)/etc/config \
> +		$(1)/etc/crontabs \
> +		$(1)/etc/rc.d \
> +		$(1)/overlay \
> +		$(1)/lib/firmware \
> +		$(1)/mnt \
> +		$(1)/proc \
> +		$(1)/tmp \
> +		$(1)/usr/lib \
> +		$(1)/usr/bin \
> +		$(1)/sys \
> +		$(1)/www \
> +		$(1)/root
> +
> +	$(LN) /proc/mounts $(1)/etc/mtab
>  	$(if $(LIB_SUFFIX),-$(LN) lib $(1)/lib$(LIB_SUFFIX))
> -	mkdir -p $(1)/mnt
> -	mkdir -p $(1)/proc
> -	mkdir -p $(1)/tmp
> -	mkdir -p $(1)/usr/lib
>  	$(if $(LIB_SUFFIX),-$(LN) lib $(1)/usr/lib$(LIB_SUFFIX))
> -	mkdir -p $(1)/usr/bin
> -	mkdir -p $(1)/sys
> -	mkdir -p $(1)/www
> -	mkdir -p $(1)/root
> -	$(LN) /proc/mounts $(1)/etc/mtab
> +
>  ifneq ($(CONFIG_TARGET_ROOTFS_PERSIST_VAR),y)
>  	rm -f $(1)/var
>  	$(LN) tmp $(1)/var
> @@ -188,7 +189,6 @@ else
>  	mkdir -p $(1)/var
>  	$(LN) /tmp/run $(1)/var/run
>  endif
> -	mkdir -p $(1)/etc
>  	$(LN) /tmp/resolv.conf /tmp/TZ /tmp/localtime $(1)/etc/
> 
>  	chmod 0600 $(1)/etc/shadow
> --
> 2.30.2
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel




More information about the openwrt-devel mailing list