]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use File::stat (); | |
7 | use Getopt::Long; | |
8 | ||
9 | use PVE::Tools; | |
10 | use PVE::Cluster; | |
11 | use PVE::SafeSyslog; | |
12 | use PVE::INotify; | |
13 | use PVE::RPCEnvironment; | |
14 | use PVE::API2::APT; | |
15 | ||
16 | $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin'; | |
17 | ||
18 | initlog('pveupgrade'); | |
19 | ||
20 | die "please run as root\n" if $> != 0; | |
21 | ||
22 | PVE::INotify::inotify_init(); | |
23 | my $nodename = PVE::INotify::nodename(); | |
24 | ||
25 | my $rpcenv = PVE::RPCEnvironment->init('cli'); | |
26 | ||
27 | $rpcenv->init_request(); | |
28 | $rpcenv->set_language($ENV{LANG}); | |
29 | $rpcenv->set_user('root@pam'); | |
30 | ||
31 | my $start_shell; | |
32 | ||
33 | if (!GetOptions ("shell" => \$start_shell)) { | |
34 | print "Usage: $0 [--shell]\n"; | |
35 | exit(-1); | |
36 | } | |
37 | ||
38 | my $st = File::stat::stat("/var/cache/apt/pkgcache.bin"); | |
39 | if (!$st || (time() - $st->mtime) > (3*24*3600)) { | |
40 | ||
41 | print "\nYour package database is out of date. Please update that first.\n\n"; | |
42 | ||
43 | } else { | |
44 | ||
45 | my $cmdstr = 'apt-get dist-upgrade'; | |
46 | ||
47 | print "Starting system upgrade: apt-get dist-upgrade\n"; | |
48 | ||
49 | my $oldlist = PVE::API2::APT->list_updates({ node => $nodename}); | |
50 | ||
51 | system('apt-get', 'dist-upgrade'); | |
52 | ||
53 | my $pkglist = PVE::API2::APT->list_updates({ node => $nodename}); | |
54 | ||
55 | print "\n"; | |
56 | if (my $count = scalar(@$pkglist)) { | |
57 | print "System not fully up to date (found $count new packages)\n\n"; | |
58 | } else { | |
59 | print "Your System is up-to-date\n\n"; | |
60 | } | |
61 | ||
62 | my $newkernel; | |
63 | foreach my $p (@$oldlist) { | |
64 | if (($p->{Package} =~ m/^pve-kernel/) && | |
65 | !grep { $_->{Package} eq $p->{Package} } @$pkglist) { | |
66 | $newkernel = 1; | |
67 | last; | |
68 | } | |
69 | } | |
70 | ||
71 | if ($newkernel) { | |
72 | print "\n"; | |
73 | print "Seems you installed a kernel update - Please consider rebooting\n" . | |
74 | "this node to activate the new kernel.\n\n"; | |
75 | } | |
76 | } | |
77 | ||
78 | ||
79 | if ($start_shell) { | |
80 | print "starting shell\n"; | |
81 | system('/bin/bash -l'); | |
82 | } | |
83 | ||
84 | exit 0; | |
85 | ||
86 | ||
87 | __END__ | |
88 | ||
89 | =head1 NAME | |
90 | ||
91 | pveupgrade - wrapper arournd "apt-get dist-upgrade" | |
92 | ||
93 | =head1 SYNOPSIS | |
94 | ||
95 | pveupgrade [--shell] | |
96 | ||
97 | =head1 DESCRIPTION | |
98 | ||
99 | This is a small wrapper around "apt-get dist-upgrade". We use this to | |
100 | print additional information (kernel restart required?), and | |
101 | optionally run an interactive shell after the update (--shell) |