]> git.proxmox.com Git - pmg-api.git/blob - src/bin/pmgbanner
pmgbanner: don't die if getting addr fails but running in container
[pmg-api.git] / src / bin / pmgbanner
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use PVE::INotify;
7 use PVE::Tools;
8 use PMG::Cluster;
9
10 sub detect_container {
11
12 my $ct;
13 if (-f '/run/systemd/container') {
14 $ct = PVE::Tools::file_read_firstline('/run/systemd/container');
15 }
16 return $ct;
17 }
18
19 my $nodename = PVE::INotify::nodename();
20 my $localip = eval { PMG::Cluster::remote_node_ip($nodename, 1) };
21 if (my $err = $@) { # FIXME: HACK: cope better with managed CTs and DHCP
22 my $in_ct = detect_container();
23 die $err if !$in_ct;
24 warn "ignore failure to get local IP of $nodename, we're in a container ($in_ct)\n";
25 $localip = '<uknown>';
26 }
27
28 my $xline = '-' x 78;
29
30 my $banner = '';
31
32 if ($localip) {
33 $banner .= <<__EOBANNER;
34
35 $xline
36
37 Welcome to the Proxmox Mail Gateway. Please use your web browser to
38 configure this server - connect to:
39
40 https://${localip}:8006/
41
42 $xline
43
44 __EOBANNER
45
46 }
47
48 open(ISSUE, ">/etc/issue");
49
50 print ISSUE $banner;
51
52 close(ISSUE);
53
54 exit (0);