libremesh / lime-packages

LibreMesh packages configuring OpenWrt for wireless mesh networking
https://libremesh.org/
GNU Affero General Public License v3.0
280 stars 96 forks source link

unique_append should check if /etc/crontabs/root file exist before appending #949

Open ilario opened 1 year ago

ilario commented 1 year ago

The onliner function used often in the code for adding a line to the root crontab does not check for its existence before looking into it with grep. For example here:

https://github.com/libremesh/lime-packages/blob/5398a91f50abeb5988c56de41aec7bf20da361f8/packages/shared-state/files/etc/uci-defaults/shared-state-publishers-cron#L3-L10

This causes an error on the very first execution of such function:

Configuring shared-state.
grep: /etc/crontabs/root: No such file or directory

Nevertheless, the content gets added to the crontab anyway, so everything should work even when this error message appears.

ilario commented 4 days ago

Currently three solutions have been proposed:

I proposed to just edit all the files: https://github.com/libremesh/lime-packages/pull/980/commits/ff8fd58d45c0b3fcb7119b2eceaad256446e41d5

@aparcar proposed to create a function to be used until when unique_append gets included in OpenWrt's built-in list of functions (but we did not propose that to OpenWrt yet): https://github.com/libremesh/lime-packages/pull/988

@G10h4ck proposed to create an executable file and put it in the path, like here: https://github.com/libremesh/lime-packages/tree/master/packages/lime-system/files/usr/bin

I like the second option as we should always try to push useful code to OpenWrt. Or we just create the executable file (third option) and some day we will push the function to OpenWrt...