diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2020-02-14 21:10:45 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2020-02-14 21:10:45 +0100 |
commit | c1671b018f3f2855a9a8387f51b99a72f2a1f053 (patch) | |
tree | 6b9634e1c40aaed5243f92ef1e401e7293499dd3 /scripts | |
parent | dfdcd99b9b8d776b3a94268e938dbd3bf2165f83 (diff) |
upgrade: Remove packages removed on old container
Some packages may have been removed on the old container for example
replaces by full versions. Remove them before installing packages since
you can usually not have both full and normal versions installed
at the same time.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/upgrade.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/scripts/upgrade.py b/scripts/upgrade.py index 98efc70..3de6ee6 100644 --- a/scripts/upgrade.py +++ b/scripts/upgrade.py @@ -107,8 +107,13 @@ class Container: print("Installing %s" % packages) self.execute(['opkg', 'install'] + packages) - def package_set(self): - old_list = self.opkg_list_installed().split('\n') + def opkg_remove(self, packages): + print("Removing %s" % packages) + self.execute(['opkg', 'remove'] + packages) + + def _package_set_from_str(self, s): + print("_package_set_from_str ", type(s)) + old_list = s.split('\n') old_packages = [] i = 1 for l in old_list: @@ -119,6 +124,12 @@ class Container: old_packages.append(name) return frozenset(old_packages) + def package_set(self): + return self._package_set_from_str(self.opkg_list_installed()) + + def orig_package_set(self): + return self._package_set_from_str(self.container.files.get('/etc/openwrt_manifest').decode('ascii')) + def usage(argv): print("Usage:", argv[0], "<old container> <new container> <image>") exit(1) @@ -161,9 +172,18 @@ def main(argv): print("Update package list") new.opkg_update() + orig_set = old.orig_package_set() old_set = old.package_set() new_set = new.package_set() - add_packages = list(old_set.difference(new_set).difference(['iw'])) + del_set = orig_set.difference(old_set) + del_packages = list(del_set) + add_packages = list(old_set.difference(new_set).difference(['iw']).difference(del_set)) + + if len(del_packages) > 0: + print("Remove", del_packages) + new.opkg_remove(del_packages) + else: + print("No packages uninstalled") if len(add_packages) > 0: print("Install", add_packages) |