From c3bbca7d80b2fe1d0f18fe2fe420e8d4b70b8edc Mon Sep 17 00:00:00 2001 From: Liangbin Lian Date: Tue, 1 Apr 2025 17:45:46 +0800 Subject: [PATCH] istoreos: improve kmod clean on post upgrade keep metadata so that user can install later --- package/base-files/files/usr/sbin/mount_root | 20 ++++++++++++++++--- .../files/etc/init.d/isos_upgrade | 8 +++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/package/base-files/files/usr/sbin/mount_root b/package/base-files/files/usr/sbin/mount_root index 6660a11e79..3e46e452c6 100755 --- a/package/base-files/files/usr/sbin/mount_root +++ b/package/base-files/files/usr/sbin/mount_root @@ -178,13 +178,27 @@ clean_os_version_files() clean_kmods() { + local DUMMY_VERSION=0.0.0-r1 if [ -d "$1/upper/usr/lib/opkg/info" ]; then local compat=`grep -m1 '^Version: ' /usr/lib/opkg/info/kernel.control | sed 's/^Version: //'` if [ -n "$compat" ]; then cd "$1/upper/usr/lib/opkg/info" - grep -LFm1 "kernel (=$compat)" kmod-*.control | sed 's/.control$//' > /tmp/del_kmods.txt - cat /tmp/del_kmods.txt | sed 's/$/.list/' | xargs cat | sed "s#^/#$1/upper/#" | xargs rm -f - cat /tmp/del_kmods.txt | xargs -rn1 sh -c 'rm -f $0.*' + # ignore processed + grep -Lm1 '^Version: '$DUMMY_VERSION'$' kmod-*.control | sed 's/.control$//' > /tmp/cand_kmods.txt + + grep -LFm1 "kernel (=$compat)" kmod-*.control | sed 's/.control$//' | grep -Fxf /tmp/cand_kmods.txt > /tmp/del_kmods.txt + grep -lFm1 "kernel (=$compat)" kmod-*.control | sed 's/.control$//' | grep -Fxf /tmp/cand_kmods.txt > /tmp/safe_kmods.txt + rm -f /tmp/cand_kmods.txt + + # remove duplicated + ( cd /usr/lib/opkg/info && ls kmod-*.control | sed 's/.control$//' ) | grep -Fxf /tmp/safe_kmods.txt >> /tmp/del_kmods.txt + rm -f /tmp/safe_kmods.txt + + log "Clean kmods in $1: `cat /tmp/del_kmods.txt | xargs echo`" + + cat /tmp/del_kmods.txt | sed 's/$/.list/' | xargs cat | sed "s#^/#$1/upper/#" | xargs -r rm -f + cat /tmp/del_kmods.txt | xargs -rn1 sh -c 'rm -f $0.list $0.prerm $0.postinst' + cat /tmp/del_kmods.txt | sed 's/$/.control/' | xargs -r sed -i 's/^Version: .*$/Version: '$DUMMY_VERSION'/g' rm -f /tmp/del_kmods.txt cd - >/dev/null 2>&1 return 0 diff --git a/package/istoreos-files/files/etc/init.d/isos_upgrade b/package/istoreos-files/files/etc/init.d/isos_upgrade index 2d8fc6762d..07bde13a0c 100755 --- a/package/istoreos-files/files/etc/init.d/isos_upgrade +++ b/package/istoreos-files/files/etc/init.d/isos_upgrade @@ -40,11 +40,17 @@ ls_all_pkgs() { } rebuild_opkg_status() { + local DUMMY_VERSION=0.0.0-r1 local line [ -f /tmp/romopkgstatus/kernel ] && cat /tmp/romopkgstatus/kernel ls_all_pkgs | while read line; do if [ -f /overlay/upper/usr/lib/opkg/info/$line.control -o -f /ext_overlay/upper/usr/lib/opkg/info/$line.control ]; then - echo /tmp/newopkgstatus/$line + if [[ $line = "kmod-*" ]] && \ + grep -qm1 '^Version: '$DUMMY_VERSION'$' /usr/lib/opkg/info/$line.control; then + [ -e /tmp/romopkgstatus/$line ] && echo /tmp/romopkgstatus/$line + else + echo /tmp/newopkgstatus/$line + fi else echo /tmp/romopkgstatus/$line fi