Sysupgrade - warn if "/usr/bin/find" is not installed

Hello,

I just realized that if the find-package (/usr/bin/find) is not installed,
the sysupgrade will skip a lot of the files defined in the "/etc/sysupgrade.conf"-file (and maybe also other default files) without any warning.

For example the following function will use the file-program to get the list of the static config files. But if "find" is not installed, there seems to be no "error handler" which would catch the "error 127".
The variable "$filter" will just be empty.

root@APU-3B4-OpenWrt ~ # grep "find " /sbin/sysupgrade -n -m1 -A3 -B3
138-list_static_conffiles() {
139-	local filter=$1
140-
141:	find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
142-		/etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
143-		\( -type f -o -type l \) $filter 2>/dev/null
144-}

Would it may be an idea, to just check if the package present, right at the beginning?
Maybe somehow like this:

if ! [ -f /usr/sbin/find ]; then 
	echo "Please install findutils package, otherwise sysupgrade can not get the files which have to be preserved."
	exit 1
fi
1 Like

On my box (22.03.2) /usr/bin/find is a symlink to busybox. So apparently you installed gnu findutils and deinstalled them, which didn't restore the symlink.
Are you sure busybox ash in the script won't use the internal applet? Else you could solve the problem by using 'busybox find' instead of find.

1 Like

I´m not 100% sure, what caused the the initial problem or better said, I don´t remember if the busybox version of find was installed or not. Right now I just installed (or included into my image) the findutils package.

But the problem I see is more general. I think the "sysupgrade"-script should check, if the "find" command exists - no matter which kind of version (busybox or standalone gnu version).

Sure, the situation of a missing "find" command will not happen that often, maybe only if persons like me build their own image and do something wrong.

But why not just check for it inside the sysupgrade script, to get 100% sure that it´s installed?

Unless you have been messing with the .config of busybox, the 'find' applet is included. And building an image without busybox is, well, challenging.

And where to stop? The same scriptlet which you found using find also uses sed, which is a busybox applet either, which symlink could be deleted by installing and removing the 'sed' package.
Your proposed solution assumes the existence of echo, which is a busybox applet which symlink could be deleted by installing and removing the 'coreutils-echo' package.

2 Likes

Thanks a lot for your explanation :slight_smile:

I will take more care in the future, what kind of packages I remove or add when building my own images.

But nevertheless, would there be any alternative to echo which would be definitely include in ash (printf maybe)?

I do not have a huge experience in how the development process in OpenWrt is working. I just ask my self, if it wouldn´t be a good idea to try to catch the this kind of errors somehow. No matter that they should not occur normally.

And if it would only need a check for the presence of some files, why not just check for them? It should not have any influence of the "performance", or am I wrong?
Of course, someone would have to take care, that the check would include all the dependencies.

I think about something like this (sorry, I know OpenWrt uses ash which does not support arrays but I was in a hurry when writing this. It more an Idea then a solution right not...):

!/bin/bash

debug=0

declare -a dependencies
dependencies=(
   "/bin/cat"
   "/bin/find"
   "/bin/sed"
#  "..." any other dependency 
   "/bin/foo-not-installed-bar"
)

if [ $debug == 1 ]; then  printf "Checking for software dependencies.\n"; fi

for i in "${dependencies[@]}"; do
        if ! [ -f "$i" ]; then
                printf "Error: %s is not installed!\nPlease install the corresponding package to get shure that sysupgrade works as expected.\n" "$i"
                exit 1
        fi
        if [ $debug == 1 ]; then printf "%s exists.\n" "$i"; fi
done

Which would give the following output, if there is any dependency missing:

❯ bash test-for-files.sh
Error: /bin/foo-not-installed-bar is not installed!
Please install the corresponding package to get shure that sysupgrade works as expected.

Again, I really do not have any plan how the development process is working in OpenWrt.
I just want to give a you an idea, how I think that a very little part of the project may could be improved.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.