]> git.proxmox.com Git - proxmox-ve.git/blame - debian/apthook/pve-apt-hook
Add a purge proxmox-ve to the warning message
[proxmox-ve.git] / debian / apthook / pve-apt-hook
CommitLineData
5132916e
FG
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use File::Basename;
7
8my $fd = $ENV{APT_HOOK_INFO_FD};
9my $check_file = '/please-remove-proxmox-ve';
10my $check_package = 'proxmox-ve';
11my $hook_name = basename($0);
12
13my $log = sub {
14 my ($line) = @_;
15 print "W: ($hook_name) $line";
16};
17
18if (!defined $fd || $fd == 0) {
19 $log->("APT_HOOK_INFO_FD not correctly defined, skipping apt-pve-hook checks\n");
20 exit 0;
21}
22
23open(my $fh, "<&=${fd}") or die "E: could not open APT_HOOK_INFO_FD (${fd}) - $!\n";
24
25my $cleanup = sub {
26 my ($rc) = @_;
27
28 close($fh);
29 exit $rc;
30};
31
32chomp (my $ver = <$fh>);
33if ($ver ne "VERSION 2") {
34 $log->("apt-pve-hook misconfigured, expecting hook protocol version 2\n");
35 $cleanup->(0);
36}
37
38my $blank;
39while (my $line = <$fh>) {
40 chomp $line;
41
42 if (!defined($blank)) {
43 $blank = 1 if !$line;
44 next;
45 }
46
47 my ($pkg, $old, $dir, $new, $action) = (split / /, $line, 5);
48 if (!defined($action)) {
49 $log->("apt-pve-hook encountered unexpected line: $line\n");
50 next;
51 }
52
53 if ($pkg eq 'proxmox-ve' && $action eq '**REMOVE**') {
54 if (-e $check_file) {
55 $log->("'$check_file' exists, proceeding with removal of package '${check_package}'\n");
56 unlink $check_file;
57 } else {
58 $log->("!! WARNING !!\n");
59 $log->("You are attempting to remove the meta-package '${check_package}'!\n");
60 $log->("\n");
61 $log->("If you really you want to permanently remove '${check_package}' from your system, run the following command\n");
62 $log->("\ttouch '${check_file}'\n");
241fccaf 63 $log->("run apt purge ${check_package} to remove the meta-package\n");
a5216c4e 64 $log->("and repeat your apt invocation.\n");
5132916e
FG
65 $log->("\n");
66 $log->("If you are unsure why '$check_package' would be removed, please verify\n");
67 $log->("\t- your APT repository settings\n");
a5216c4e 68 $log->("\t- that you are using 'apt full-upgrade' to upgrade your system\n");
5132916e
FG
69 $cleanup->(1);
70 }
71 }
72}
73
74$cleanup->(0);