]> git.proxmox.com Git - proxmox-ve.git/blob - debian/apthook/pve-apt-hook
d/postinst: drop old release key fixups
[proxmox-ve.git] / debian / apthook / pve-apt-hook
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use File::Basename;
7
8 my $fd = $ENV{APT_HOOK_INFO_FD};
9 my $check_file = '/please-remove-proxmox-ve';
10 my $check_package = 'proxmox-ve';
11 my $hook_name = basename($0);
12
13 my $log = sub {
14 my ($line) = @_;
15 print "W: ($hook_name) $line";
16 };
17
18 if (!defined $fd || $fd == 0) {
19 $log->("APT_HOOK_INFO_FD not correctly defined, skipping apt-pve-hook checks\n");
20 exit 0;
21 }
22
23 open(my $fh, "<&=${fd}") or die "E: could not open APT_HOOK_INFO_FD (${fd}) - $!\n";
24
25 my $cleanup = sub {
26 my ($rc, $confirm) = @_;
27
28 close($fh);
29
30 my $line = <STDIN> if $confirm;
31
32 exit $rc;
33 };
34
35 chomp (my $ver = <$fh>);
36 if ($ver ne "VERSION 2") {
37 $log->("apt-pve-hook misconfigured, expecting hook protocol version 2\n");
38 $cleanup->(0);
39 }
40
41 my $blank;
42 while (my $line = <$fh>) {
43 chomp $line;
44
45 if (!defined($blank)) {
46 $blank = 1 if !$line;
47 next;
48 }
49
50 my ($pkg, $old, $dir, $new, $action) = (split / /, $line, 5);
51 if (!defined($action)) {
52 $log->("apt-pve-hook encountered unexpected line: $line\n");
53 next;
54 }
55
56 if ($pkg eq 'proxmox-ve') {
57 if ($action eq '**REMOVE**') {
58 if (-e $check_file) {
59 $log->("'$check_file' exists, proceeding with removal of package '${check_package}'\n");
60 unlink $check_file;
61 } else {
62 $log->("!! WARNING !!\n");
63 $log->("You are attempting to remove the meta-package '${check_package}'!\n");
64 $log->("\n");
65 $log->("If you really want to permanently remove '${check_package}' from your system, run the following command\n");
66 $log->("\ttouch '${check_file}'\n");
67 $log->("run apt purge ${check_package} to remove the meta-package\n");
68 $log->("and repeat your apt invocation.\n");
69 $log->("\n");
70 $log->("If you are unsure why '$check_package' would be removed, please verify\n");
71 $log->("\t- your APT repository settings\n");
72 $log->("\t- that you are using 'apt full-upgrade' to upgrade your system\n");
73 $cleanup->(1);
74 }
75 } elsif ($action eq '**CONFIGURE**' && $dir eq '<' && $old =~ /^6\./ && $new =~ /^7\./) {
76 $log->("!! ATTENTION !!\n");
77 $log->("You are attempting to upgrade from proxmox-ve '$old' to proxmox-ve '$new'. Please make sure to read the Upgrade notes at\n");
78 $log->("\thttps://pve.proxmox.com/wiki/Upgrade_from_6.x_to_7.0\n");
79 $log->("before proceeding with this operation.\n");
80 $log->("\n");
81 $log->("Press enter to continue, or C^c to abort.\n");
82 $cleanup->(0, 1);
83 }
84 }
85 }
86
87 $cleanup->(0);