Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

realtek-poe: build default config from board.json #25551

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion utils/realtek-poe/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ define Package/realtek-poe/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) $(PKG_BUILD_DIR)/realtek-poe $(1)/usr/bin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/etc/init.d/poe $(1)/etc/init.d/
$(INSTALL_CONF) $(PKG_BUILD_DIR)/files/etc/config/poe $(1)/etc/config/
$(INSTALL_BIN) ./files/etc/uci-defaults/30-poe $(1)/etc/uci-defaults/30-poe
endef
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The poe-common package also added a section to mark the config file as such. I don't quite remember what this means in terms of behaviour on upgrades etc, and I can't really find much documentation either.

define Package/poe-common/conffiles
/etc/config/poe
endef

From the opkg code, I think this results in detecting that the file exists and has been "modified" (created), thus doing The Right Thing (creating backup etc.) on package upgrades. I think the old package would just blindly replace the edited poe config file on upgrades. The uci-defaults script would do the same though, and won't touch the file if it already exists.

Hopefully this also means the config file is put in the config backup automatically on system upgrades, but you may have to check this.


$(eval $(call BuildPackage,realtek-poe))
42 changes: 42 additions & 0 deletions utils/realtek-poe/files/etc/uci-defaults/30-poe
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-License-Identifier: GPL-2.0-or-later

[ -e /etc/config/poe ] && exit 0

. /lib/functions.sh
. /usr/share/libubox/jshn.sh

CFG=/etc/board.json

json_init
json_load_file "${CFG}"

json_is_a poe object || exit 0

umask 055
touch /etc/config/poe

json_select poe
json_get_vars budget

uci add poe global
uci set poe.@global[-1].budget="$budget"

if json_is_a ports array; then
json_get_values ports ports
id='1'

for port in $ports; do
uci -q batch <<-EOF
add poe port
set poe.@port[-1].name='$port'
set poe.@port[-1].id='$id'
set poe.@port[-1].enable='1'
EOF
let id=id+1
done
fi
json_select ..

uci commit

exit 0
Loading