]> git.proxmox.com Git - proxmox-ve.git/blob - debian/apthook/pve-apt-hook
d/copyright: update years
[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 || $fd !~ /^\d+$/) {
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 if ($confirm) {
31 my $line = <STDIN>;
32 }
33
34 exit $rc;
35 };
36
37 my $file_read_firstline = sub {
38 my ($filename) = @_;
39
40 my $fh = IO::File->new($filename, "r");
41 return undef if !$fh;
42 my $res = <$fh>;
43 chomp $res if $res;
44 $fh->close;
45 return $res;
46 };
47
48 chomp (my $ver = <$fh>);
49 if ($ver ne "VERSION 2") {
50 $log->("apt-pve-hook misconfigured, expecting hook protocol version 2\n");
51 $cleanup->(0);
52 }
53
54 my $blank;
55 while (my $line = <$fh>) {
56 chomp $line;
57
58 if (!defined($blank)) {
59 $blank = 1 if !$line;
60 next;
61 }
62
63 my ($pkg, $old, $dir, $new, $action) = (split / /, $line, 5);
64 if (!defined($action)) {
65 $log->("apt-pve-hook encountered unexpected line: $line\n");
66 next;
67 }
68
69 if ($pkg eq 'proxmox-ve') {
70 if ($action eq '**REMOVE**') {
71 if (-e $check_file) {
72 $log->("'$check_file' exists, proceeding with removal of package '${check_package}'\n");
73 unlink $check_file;
74 } else {
75 $log->("!! WARNING !!\n");
76 $log->("You are attempting to remove the meta-package '${check_package}'!\n");
77 $log->("\n");
78 $log->("If you really want to permanently remove '${check_package}' from your system, run the following command\n");
79 $log->("\ttouch '${check_file}'\n");
80 $log->("run apt purge ${check_package} to remove the meta-package\n");
81 $log->("and repeat your apt invocation.\n");
82 $log->("\n");
83 $log->("If you are unsure why '$check_package' would be removed, please verify\n");
84 $log->("\t- your APT repository settings\n");
85 $log->("\t- that you are using 'apt full-upgrade' to upgrade your system\n");
86 $cleanup->(1);
87 }
88 } elsif ($action eq '**CONFIGURE**' && $dir eq '<' && $old =~ /^6\./ && $new =~ /^7\./) {
89 $log->("!! ATTENTION !!\n");
90 $log->("You are attempting to upgrade from proxmox-ve '$old' to proxmox-ve '$new'. Please make sure to read the Upgrade notes at\n");
91 $log->("\thttps://pve.proxmox.com/wiki/Upgrade_from_6.x_to_7.0\n");
92 $log->("before proceeding with this operation.\n");
93 $log->("\n");
94 $log->("Press enter to continue, or C^c to abort.\n");
95 $cleanup->(0, 1);
96 }
97 }
98 if ($pkg =~ /^pve-kernel-/) {
99 if ($action eq '**REMOVE**') {
100 my $next_boot_ver = $file_read_firstline->("/etc/kernel/next-boot-pin");
101 my $pinned_ver = $file_read_firstline->("/etc/kernel/proxmox-boot-pin");
102 my $remove_pinned_ver = ($next_boot_ver && $pkg =~ /$next_boot_ver$/);
103 $remove_pinned_ver ||= ($pinned_ver && $pkg =~ /$pinned_ver$/);
104 if ($remove_pinned_ver) {
105 $log->("!! WARNING !!\n");
106 $log->("You are attempting to remove the currently pinned kernel '${pkg}'!\n");
107 $log->("\n");
108 $log->("If you really do not need the version anymore unpin it by running\n");
109 $log->("\tproxmox-boot-tool kernel unpin'\n");
110 $log->("and repeat your apt invocation.\n");
111 $cleanup->(1);
112 }
113 }
114 }
115 }
116
117 $cleanup->(0);