mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
sysupgrade: move UCI diff into a separate function lib
For reuse by other modules as well.
This commit is contained in:
parent
f52528f806
commit
a01a3be0d1
1 changed files with 6 additions and 58 deletions
|
|
@ -13,6 +13,11 @@ if [ -n "$SAVE_CONFIG" ] && [ $SAVE_CONFIG -eq 0 ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
# Source functions.
|
||||
for f in /lib/upgrade/iopsys*.sh; do
|
||||
[ -r "$f" -a -s "$f" ] || continue
|
||||
source $f
|
||||
done
|
||||
|
||||
[ -d "/lib/config/snapshots/first_boot/uci" ] || exit 0
|
||||
|
||||
|
|
@ -21,64 +26,7 @@ hasWifi=$(chroot "${2}" db -q get hw.board.hasWifi)
|
|||
[ "$hasWifi" = "1" ] || exit 0
|
||||
|
||||
|
||||
# Read the very first verion of the wireless settings.
|
||||
if ! chroot "${2}" uci -c "/lib/config/snapshots/first_boot/uci" \
|
||||
-q show wireless >"/tmp/wireless-first-$$" || \
|
||||
[ ! -s "/tmp/wireless-first-$$" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# Let the current UCI export its wireless settings.
|
||||
if ! chroot "${2}" uci -q show wireless >"/tmp/wireless-current-$$" || \
|
||||
[ ! -s "/tmp/wireless-current-$$" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# If there a diff between the two?
|
||||
if grep -vFf "/tmp/wireless-first-$$" "/tmp/wireless-current-$$" \
|
||||
>"/tmp/wireless-diff-$$" && [ -s "/tmp/wireless-diff-$$" ]; then
|
||||
|
||||
# Create new config if it doesn't yet exist.
|
||||
[ -s "/etc/config/wireless" ] || : >>"/etc/config/wireless"
|
||||
|
||||
# Extract named section "headers" like e.g:
|
||||
# wireless.wl0=wifi-device
|
||||
# from current settings.
|
||||
grep -E "wireless\.[^\.@][^\.]+=" "/tmp/wireless-current-$$" \
|
||||
>"/tmp/wireless-named-secs-$$"
|
||||
|
||||
# Check if a named section exist in the diff. If so,
|
||||
# add corresponding named section "header" to the diff.
|
||||
# Example: Is
|
||||
# wireless.wl0
|
||||
# in the diff? Then add
|
||||
# wireless.wl0=wifi-device
|
||||
# to the diff as well.
|
||||
while read -t 5 -s line; do
|
||||
section="${line%%=*}"
|
||||
if grep -qF "$section" "/tmp/wireless-diff-$$"; then
|
||||
echo "$line" >>"/tmp/wireless-diff-$$"
|
||||
fi
|
||||
done <"/tmp/wireless-named-secs-$$"
|
||||
|
||||
# Migration of anonymous section requires special handling.
|
||||
grep ']=' "/tmp/wireless-current-$$" | tr ".@=" " " | \
|
||||
awk '{
|
||||
if(system("uci -q get "$1".@"$2" >/dev/null") != 0 && # Does it already exit?
|
||||
system("uci add "$1" "$3" >/dev/null") != 0) { # If not, then create it.
|
||||
exit 1;
|
||||
}
|
||||
}'
|
||||
|
||||
# Import the diff into the next UCI database. The eval
|
||||
# is for string parsing of quotation marks. The sort for
|
||||
# section "headers" to come first.
|
||||
sort -Vr "/tmp/wireless-diff-$$" | \
|
||||
while read -t 5 -s line; do
|
||||
uci set "$(eval echo $line)"
|
||||
done
|
||||
fi
|
||||
uci_possibly_migrate_package "wireless" "$2" || exit
|
||||
|
||||
# Report success.
|
||||
logger -s -p daemon.info -t post-hooks -- "UCI wireless migrated."
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue