]> git.proxmox.com Git - pve-installer.git/blob - Proxmox/Install/Env.pm
rename Proxmox::Install::Setup to Proxmox::Install::Env
[pve-installer.git] / Proxmox / Install / Env.pm
1 package Proxmox::Install::Env;
2
3 use strict;
4 use warnings;
5
6 use base qw(Exporter);
7 our @EXPORT = qw(is_test_mode);
8
9 my $product_cfg = {
10 pve => {
11 fullname => 'Proxmox VE',
12 port => '8006',
13 enable_btrfs => 1,
14 bridged_network => 1,
15 },
16 pmg => {
17 fullname => 'Proxmox Mail Gateway',
18 port => '8006',
19 enable_btrfs => 0,
20 bridged_network => 0,
21 },
22 pbs => {
23 fullname => 'Proxmox Backup Server',
24 port => '8007',
25 enable_btrfs => 0,
26 bridged_network => 0,
27 },
28 };
29
30 sub setup {
31 my $cd_info = get_cd_info();
32 my $product = $cd_info->{product};
33
34 my $setup_info = $product_cfg->{$product};
35 die "unknown product '$product'\n" if !$setup_info;
36
37 $setup_info->{product} = $product;
38
39 return ($setup_info, $cd_info);
40 }
41
42 sub get_cd_info {
43 my $info_fn = '/.cd-info'; # default place in the ISO environment
44 if (!-f $info_fn && -f "cd-info.test") {
45 $info_fn = "cd-info.test"; # use from CWD for test mode
46 }
47
48 open(my $fh, '<', $info_fn) or die "Could not open CD info file '$info_fn' $!";
49
50 my $cd_info = {};
51 while (my $line = <$fh>) {
52 chomp $line;
53 if ($line =~ /^(\S+)=['"]?(.+?)['"]?$/) { # we control cd-info content, so good enough.
54 $cd_info->{lc($1)} = $2;
55 }
56 }
57 close ($fh);
58
59 die "CD-info is missing required key 'product'!\n" if !defined $cd_info->{product};
60
61 return $cd_info;
62 }
63
64 my $test_mode;
65 sub enable_test_mode {
66 $test_mode = 1;
67 }
68 sub is_test_mode {
69 return !!$test_mode;
70 }
71
72 1;