diff options
author | Tony Ambardar <itugrok@yahoo.com> | 2018-03-02 19:32:24 -0800 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-12-18 11:28:14 +0100 |
commit | 85c77301d4ad126cf93695422fdaa9a50ca957e6 (patch) | |
tree | e2c7e9b718e58bfa17626596439868edaa2ea895 /package/base-files | |
parent | 6bcafab581cd60196e94b2b0edebc236888f7f4d (diff) | |
download | upstream-85c77301d4ad126cf93695422fdaa9a50ca957e6.tar.gz upstream-85c77301d4ad126cf93695422fdaa9a50ca957e6.tar.bz2 upstream-85c77301d4ad126cf93695422fdaa9a50ca957e6.zip |
base-files: fix postinstall uci-defaults removal
Commit 7f694582 introduced a bug where default_postinst() often fails to
remove a uci-defaults script after application, leaving it to run again
after a reboot.
(Note: commit 7f694582 also introduced FS#1021, now fixed by 73c745f6)
The subtle problem arises from the shell logical chain:
[ -f "$i" ] && . "$i" && rm -f "$i"
Most uci-defaults scripts contain a terminal 'exit 0' statement which,
when sourced, results in the logic chain exiting before executing 'rm -f'.
This was observed while testing upgrades of 'luci-app-sqm'.
The solution is to wrap the shell sourcing in a subshell relative to the
command 'rm -f':
( [ -f "$i" ] && . "$i" ) && rm -f "$i"
Revert to using 'grep' to prefilter the list of entries from the control
file, which yields the full path of uci-defaults scripts. This allows
keeping the existence check, directory change and script sourcing inside
the subshell, with the script removal correctly outside.
This approach avoids adding a second subshell only around the "." (source)
command. The change also preserves the fix FS#1021, since the full path is
used to source the script, which is POSIX-portable irrespective of PATH
variable or reference to the CWD.
Run Tested on: LEDE 17.01.4 running ar71xx, while tracing installation of
package luci-app-sqm with its associated /etc/uci-defaults/luci-sqm file.
Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
(backported from 4097ab6a975902b170dd7f7ac6c8025e5f32ef8d)
Diffstat (limited to 'package/base-files')
-rwxr-xr-x | package/base-files/files/lib/functions.sh | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh index f16ffd1746..50a7b40869 100755 --- a/package/base-files/files/lib/functions.sh +++ b/package/base-files/files/lib/functions.sh @@ -234,10 +234,9 @@ default_postinst() { if [ -z "$root" ] && grep -q -s "^/etc/uci-defaults/" "/usr/lib/opkg/info/${pkgname}.list"; then . /lib/functions/system.sh [ -d /tmp/.uci ] || mkdir -p /tmp/.uci - for i in $(sed -ne 's!^/etc/uci-defaults/!!p' "/usr/lib/opkg/info/${pkgname}.list"); do ( - cd /etc/uci-defaults - [ -f "$i" ] && . ./"$i" && rm -f "$i" - ) done + for i in $(grep -s "^/etc/uci-defaults/" "/usr/lib/opkg/info/${pkgname}.list"); do + ( [ -f "$i" ] && cd "$(dirname $i)" && . "$i" ) && rm -f "$i" + done uci commit fi |