[pve-devel] [PATCH] add APT hook to prevent proxmox-ve removal

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Mar 29 06:32:18 CEST 2018


On 3/23/18 12:21 PM, Fabian Gr├╝nbichler wrote:
> since this happens quite regularly when users accidentally install
> conflicting packages.
> 

works good!
But touching $check_file once makes it stay permanent, rendering the
hook useless for the next time.
E:g., when I have a messed up system and need/want to allow removing
proxmox-ve and installing it again to get out of the mess.

So maybe either remove the file actively if it's there and proxmox-ve gets removed,
or place the file in /run, so that a reboot cleans it indirectly.
I like the former more, but no heavy opinions here... :)

> sample output:
> $ apt remove pve-qemu-kvm
> Reading package lists... Done
> Building dependency tree
> Reading state information... Done
> The following packages were automatically installed and are no longer required:
>   libxml-libxml-perl proxmox-widget-toolkit pve-edk2-firmware pve-i18n pve-xtermjs
> Use 'apt autoremove' to remove them.
> The following packages will be REMOVED:
>   proxmox-ve pve-container pve-ha-manager pve-ha-manager-dbgsym pve-manager pve-qemu-kvm qemu-server spiceterm
> 0 upgraded, 0 newly installed, 8 to remove and 0 not upgraded.
> After this operation, 37.6 MB disk space will be freed.
> Do you want to continue? [Y/n] y
> W: (pve-apt-hook) !! WARNING !!
> W: (pve-apt-hook) You are attempting to remove the meta-package 'proxmox-ve'!
> W: (pve-apt-hook)
> W: (pve-apt-hook) If you really you want to permanently remove 'proxmox-ve' from your system, run the following command
> W: (pve-apt-hook)       touch '/please-remove-proxmox-ve'
> W: (pve-apt-hook) and repeat your apt-get/apt invocation.
> W: (pve-apt-hook)
> W: (pve-apt-hook) If you are unsure why 'proxmox-ve' would be removed, please verify
> W: (pve-apt-hook)       - your APT repository settings
> W: (pve-apt-hook)       - that you are using 'apt-get dist-upgrade' or 'apt full-upgrade' to upgrade your system
> E: Sub-process /usr/share/proxmox-ve/pve-apt-hook returned an error code (1)
> E: Failure running script /usr/share/proxmox-ve/pve-apt-hook
> 
> Signed-off-by: Fabian Gr├╝nbichler <f.gruenbichler at proxmox.com>
> ---
>  debian/apthook/10pveapthook |  4 +++
>  debian/apthook/pve-apt-hook | 72 +++++++++++++++++++++++++++++++++++++++++++++
>  debian/proxmox-ve.install   |  2 ++
>  3 files changed, 78 insertions(+)
>  create mode 100644 debian/apthook/10pveapthook
>  create mode 100755 debian/apthook/pve-apt-hook
> 
> diff --git a/debian/apthook/10pveapthook b/debian/apthook/10pveapthook
> new file mode 100644
> index 0000000..b7ae649
> --- /dev/null
> +++ b/debian/apthook/10pveapthook
> @@ -0,0 +1,4 @@
> +DPkg::Pre-Install-Pkgs { "/usr/share/proxmox-ve/pve-apt-hook"; };
> +DPkg::Tools::Options::/usr/share/proxmox-ve/pve-apt-hook "";
> +DPkg::Tools::Options::/usr/share/proxmox-ve/pve-apt-hook::Version "2";
> +DPkg::Tools::Options::/usr/share/proxmox-ve/pve-apt-hook::InfoFD "20";
> diff --git a/debian/apthook/pve-apt-hook b/debian/apthook/pve-apt-hook
> new file mode 100755
> index 0000000..c09ab73
> --- /dev/null
> +++ b/debian/apthook/pve-apt-hook
> @@ -0,0 +1,72 @@
> +#!/usr/bin/perl
> +
> +use strict;
> +use warnings;
> +
> +use File::Basename;
> +
> +my $fd = $ENV{APT_HOOK_INFO_FD};
> +my $check_file = '/please-remove-proxmox-ve';
> +my $check_package = 'proxmox-ve';
> +my $hook_name = basename($0);
> +
> +my $log = sub {
> +  my ($line) = @_;
> +  print "W: ($hook_name) $line";
> +};
> +
> +if (!defined $fd || $fd == 0) {
> +  $log->("APT_HOOK_INFO_FD not correctly defined, skipping apt-pve-hook checks\n");
> +  exit 0;
> +}
> +
> +open(my $fh, "<&=${fd}") or die "E: could not open APT_HOOK_INFO_FD (${fd}) - $!\n";
> +
> +my $cleanup = sub {
> +  my ($rc) = @_;
> +
> +  close($fh);
> +  exit $rc;
> +};
> +
> +chomp (my $ver = <$fh>);
> +if ($ver ne "VERSION 2") {
> +  $log->("apt-pve-hook misconfigured, expecting hook protocol version 2\n");
> +  $cleanup->(0);
> +}
> +
> +my $blank;
> +while (my $line = <$fh>) {
> +  chomp $line;
> +
> +  if (!defined($blank)) {
> +    $blank = 1 if !$line;
> +    next;
> +  }
> +
> +  my ($pkg, $old, $dir, $new, $action) = (split / /, $line, 5);
> +  if (!defined($action)) {
> +    $log->("apt-pve-hook encountered unexpected line: $line\n");
> +    next;
> +  }
> +
> +  if ($pkg eq 'proxmox-ve' && $action eq '**REMOVE**') {
> +    if (-e $check_file) {
> +      $log->("'$check_file' exists, proceeding with removal of package '${check_package}'\n");
> +    } else {
> +      $log->("!! WARNING !!\n");
> +      $log->("You are attempting to remove the meta-package '${check_package}'!\n");
> +      $log->("\n");
> +      $log->("If you really you want to permanently remove '${check_package}' from your system, run the following command\n");
> +      $log->("\ttouch '${check_file}'\n");
> +      $log->("and repeat your apt-get/apt invocation.\n");
> +      $log->("\n");
> +      $log->("If you are unsure why '$check_package' would be removed, please verify\n");
> +      $log->("\t- your APT repository settings\n");
> +      $log->("\t- that you are using 'apt-get dist-upgrade' or 'apt full-upgrade' to upgrade your system\n");
> +      $cleanup->(1);
> +    }
> +  }
> +}
> +
> +$cleanup->(0);
> diff --git a/debian/proxmox-ve.install b/debian/proxmox-ve.install
> index 6ac09f5..13d16c4 100644
> --- a/debian/proxmox-ve.install
> +++ b/debian/proxmox-ve.install
> @@ -1 +1,3 @@
>  debian/proxmox-ve-release-5.x.gpg etc/apt/trusted.gpg.d/
> +debian/apthook/10pveapthook etc/apt/apt.conf.d/
> +debian/apthook/pve-apt-hook usr/share/proxmox-ve/
> 





More information about the pve-devel mailing list