]> git.proxmox.com Git - proxmox-ve.git/blame - debian/apthook/pve-apt-hook
apthook: detect upgrades from PVE 5.x to 6.0
[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 {
4f9e89e6 26 my ($rc, $confirm) = @_;
5132916e
FG
27
28 close($fh);
4f9e89e6
FG
29
30 my $line = <STDIN> if $confirm;
31
5132916e
FG
32 exit $rc;
33};
34
35chomp (my $ver = <$fh>);
36if ($ver ne "VERSION 2") {
37 $log->("apt-pve-hook misconfigured, expecting hook protocol version 2\n");
38 $cleanup->(0);
39}
40
41my $blank;
42while (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
4f9e89e6
FG
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 =~ /^5\./ && $new =~ /^6\./) {
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_5.x_to_6.0\n");
79 $log->("before proceeding with this operation.\n");
5132916e 80 $log->("\n");
4f9e89e6
FG
81 $log->("Press enter to continue, or C^c to abort.\n");
82 $cleanup->(0, 1);
5132916e
FG
83 }
84 }
85}
86
87$cleanup->(0);