diff --git a/.github/workflows/packaging/deb/postinst b/.github/workflows/packaging/deb/postinst index 10d2073..f110c60 100644 --- a/.github/workflows/packaging/deb/postinst +++ b/.github/workflows/packaging/deb/postinst @@ -39,11 +39,6 @@ if [ -f "/usr/bin/systemctl" ];then cp /opt/linupdate/service/linupdate.systemd.template /lib/systemd/system/linupdate.service fi - # Delete service symlink if exists - if [ ! -L "/etc/systemd/system/linupdate.service" ];then - rm -f /etc/systemd/system/linupdate.service - fi - chmod 550 "$SERVICE" chown root:root "$SERVICE" diff --git a/.github/workflows/packaging/deb/preinst b/.github/workflows/packaging/deb/preinst index b230c5a..d712bd7 100644 --- a/.github/workflows/packaging/deb/preinst +++ b/.github/workflows/packaging/deb/preinst @@ -8,6 +8,9 @@ if [ -f "/etc/linupdate/update.yml" ];then cp /etc/linupdate/update.yml /tmp/update.yml.debsave fi +# Delete service symlink if exists +rm -f /etc/systemd/system/linupdate.service + # Only if systemd is installed (not the case on github runners) if [ -f "/usr/bin/systemctl" ];then # Stop service if started diff --git a/.github/workflows/packaging/rpm/spec b/.github/workflows/packaging/rpm/spec index 96aaeed..5c2749f 100644 --- a/.github/workflows/packaging/rpm/spec +++ b/.github/workflows/packaging/rpm/spec @@ -34,6 +34,9 @@ if [ -f "/etc/linupdate/update.yml" ];then cp /etc/linupdate/update.yml /tmp/update.yml.rpmsave fi +# Delete service symlink if exists +rm -f /etc/systemd/system/linupdate.service + # Only if systemd is installed (not the case on github runners) if [ -f "/usr/bin/systemctl" ];then # Stop service if started @@ -89,11 +92,6 @@ if [ -f "/usr/bin/systemctl" ];then cp /opt/linupdate/service/linupdate.systemd.template /lib/systemd/system/linupdate.service fi - # Delete service symlink if exists - if [ ! -L "/etc/systemd/system/linupdate.service" ];then - rm -f /etc/systemd/system/linupdate.service - fi - chmod 550 "$SERVICE" chown root:root "$SERVICE" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index efd7cb0..5bce344 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -185,7 +185,7 @@ jobs: body: | **Changes:** - - Fixed apt cache cleaning, again + - Another apt cache cleaning draft: false prerelease: false diff --git a/src/controllers/Module/Reposerver/Reposerver.py b/src/controllers/Module/Reposerver/Reposerver.py index 52ead5d..e8c9aca 100644 --- a/src/controllers/Module/Reposerver/Reposerver.py +++ b/src/controllers/Module/Reposerver/Reposerver.py @@ -57,10 +57,6 @@ def post(self, updateSummary): # Generaly "*-release" packages on Redhat/CentOS are resetting .repo files. So it is better to retrieve them again from the reposerver self.configController.get_profile_repos() - # Send last 4 packages history entries to the reposerver - # status = Status() - # status.send_packages_history() - #----------------------------------------------------------------------------------------------- # diff --git a/src/controllers/Package/Apt.py b/src/controllers/Package/Apt.py index 2adfbbf..88df773 100644 --- a/src/controllers/Package/Apt.py +++ b/src/controllers/Package/Apt.py @@ -14,9 +14,6 @@ def __init__(self): # Create an instance of the apt cache self.aptcache = apt.Cache() - # self.aptcache.update() - self.aptcache.open(None) - # Total count of success and failed package updates self.summary = { 'update': { @@ -44,6 +41,11 @@ def __init__(self): def get_installed_packages(self): list = [] + # Clear, update cache and open it + # TODO to fix: cache is updated twice because of a weird bug I cannot fix. It seems that the cache is not updated correctly the first time and leads to an empty list of packages. + self.update_cache() + self.update_cache() + try: # Loop through all installed packages for pkg in self.aptcache: @@ -69,29 +71,31 @@ def get_installed_packages(self): # #----------------------------------------------------------------------------------------------- def get_available_packages(self, dist_upgrade: bool = False): - try: - list = [] - - # Simulate an upgrade - self.aptcache.upgrade(dist_upgrade) - - # Loop through all packages marked for upgrade - for pkg in self.aptcache.get_changes(): - # If the package is upgradable, add it to the list of available packages - if pkg.is_upgradable: - myPackage = { - 'name': pkg.name, - 'current_version': pkg.installed.version, - 'available_version': pkg.candidate.version - } + list = [] - list.append(myPackage) - - # Sort the list by package name - list.sort(key=lambda x: x['name']) + # Clear, update cache and open it + # TODO to fix: cache is updated twice because of a weird bug I cannot fix. It seems that the cache is not updated correctly the first time and leads to an empty list of packages. + # Might be because /etc/apt/sources.list is empty + self.update_cache() + self.update_cache() + + # Simulate an upgrade to get the list of available packages + self.aptcache.upgrade(dist_upgrade) + + # Loop through all packages marked for upgrade + for pkg in self.aptcache.get_changes(): + # If the package is upgradable, add it to the list of available packages + if pkg.is_upgradable: + myPackage = { + 'name': pkg.name, + 'current_version': pkg.installed.version, + 'available_version': pkg.candidate.version + } - except Exception as e: - raise Exception('could not get available packages: ' + str(e)) + list.append(myPackage) + + # Sort the list by package name + list.sort(key=lambda x: x['name']) return list diff --git a/src/controllers/Package/Package.py b/src/controllers/Package/Package.py index a72a74c..864b99f 100644 --- a/src/controllers/Package/Package.py +++ b/src/controllers/Package/Package.py @@ -127,9 +127,6 @@ def get_installed_packages(self): #----------------------------------------------------------------------------------------------- def get_available_packages(self, dist_upgrade: bool = False): try: - # Update package manager cache - self.myPackageManagerController.update_cache() - # Get a list of available packages return self.myPackageManagerController.get_available_packages(dist_upgrade) @@ -259,8 +256,7 @@ def update(self, assume_yes: bool = False, ignore_exclude: bool = False, check_u self.summary['update']['status'] = 'done' except Exception as e: - print(Fore.RED + ' ✕ ' + Style.RESET_ALL + str(e)) - print('\n' + Fore.RED + ' Packages update failed ' + Style.RESET_ALL) + print('\n' + Fore.RED + ' Packages update failed: ' + str(e) + Style.RESET_ALL) self.summary['update']['status'] = 'failed' finally: @@ -309,12 +305,3 @@ def get_history(self, order): #----------------------------------------------------------------------------------------------- def parse_history(self, entries, entries_limit): return self.myPackageManagerController.parse_history(entries, entries_limit) - - - #----------------------------------------------------------------------------------------------- - # - # Clear package manager cache - # - #----------------------------------------------------------------------------------------------- - def clear_cache(self): - self.myPackageManagerController.clear_cache() diff --git a/version b/version index b532f3d..97ceee1 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.1.4 \ No newline at end of file +3.1.5 \ No newline at end of file