]> git.proxmox.com Git - pve-installer.git/blob - Proxmox/Install/Env.pm
9ec0c3aed4e1218f12bbd4a5a01f324064f97b8a
[pve-installer.git] / Proxmox / Install / Env.pm
1 package Proxmox::Install::Env;
2
3 use strict;
4 use warnings;
5
6 use Carp;
7
8 use base qw(Exporter);
9 our @EXPORT = qw(is_test_mode);
10
11 my $product_cfg = {
12 pve => {
13 fullname => 'Proxmox VE',
14 port => '8006',
15 enable_btrfs => 1,
16 bridged_network => 1,
17 },
18 pmg => {
19 fullname => 'Proxmox Mail Gateway',
20 port => '8006',
21 enable_btrfs => 0,
22 bridged_network => 0,
23 },
24 pbs => {
25 fullname => 'Proxmox Backup Server',
26 port => '8007',
27 enable_btrfs => 0,
28 bridged_network => 0,
29 },
30 };
31
32 my sub get_cd_info {
33 my $info_fn = '/.cd-info'; # default place in the ISO environment
34 if (!-f $info_fn && -f "cd-info.test") {
35 $info_fn = "cd-info.test"; # use from CWD for test mode
36 }
37
38 open(my $fh, '<', $info_fn) or die "Could not open CD info file '$info_fn' $!";
39
40 my $cd_info = {};
41 while (my $line = <$fh>) {
42 chomp $line;
43 if ($line =~ /^(\S+)=['"]?(.+?)['"]?$/) { # we control cd-info content, so good enough.
44 $cd_info->{lc($1)} = $2;
45 }
46 }
47 close ($fh);
48
49 die "CD-info is missing required key 'product'!\n" if !defined $cd_info->{product};
50
51 return $cd_info;
52 }
53
54 my sub get_locations {
55 my $is_test = is_test_mode();
56
57 my $base_lib_dir = '/var/lib/proxmox-installer';
58 my $iso_dir = $is_test ? $ENV{'CD_BUILDER_DIR'} || "../pve-cd-builder/tmp/data-gz/" : "/cdrom";
59
60 return {
61 iso => $iso_dir,
62 lib => $is_test ? Cwd::cwd() . "/testdir/${base_lib_dir}" : $base_lib_dir,
63 pkg => "${iso_dir}/proxmox/packages/",
64 };
65 }
66
67 sub setup {
68 my $cd_info = get_cd_info();
69 my $product = $cd_info->{product};
70
71 my $cfg = $product_cfg->{$product} or die "unknown product '$product'\n";
72 $cfg->{product} = $product;
73
74 my $locations = get_locations();
75
76 my $env = {
77 product => $product,
78 cfg => $cfg,
79 iso => $cd_info,
80 locations => $locations,
81 };
82
83 return $env;
84 }
85
86 my $test_images;
87 # sets a test image to use as disk and enables the testmode
88 sub set_test_image {
89 my ($new_test_image) = @_;
90 croak "cannot disable test mode again after enabled" if defined($test_images) && !defined($new_test_image);
91 $test_images = $new_test_image;
92 }
93 sub is_test_mode {
94 return !!$test_images;
95 }
96 sub get_test_images {
97 return [ split(/,/, $test_images) ];
98 }
99
100 1;