-#!/usr/bin/perl -w
+#!/usr/bin/perl
$ENV{DEBIAN_FRONTEND} = 'noninteractive';
$ENV{LC_ALL} = 'C';
use strict;
+use warnings;
+
use Getopt::Long;
use IPC::Open2;
use IPC::Open3;
use File::Basename;
use Time::HiRes;
-my $release = '4.4';
+use ProxmoxInstallerSetup;
+
+my $setup = ProxmoxInstallerSetup::setup();
+
my $kapi = `uname -r`;
chomp $kapi;
-my $enable_btrfs = 0;
-
my $opt_testmode;
if (!$ENV{G_SLICE} || $ENV{G_SLICE} ne "always-malloc") {
my $logfd = IO::File->new (">/tmp/install.log");
-my $proxmox_dir = $opt_testmode ? Cwd::cwd() : "/var/lib/pve-installer";
+my $proxmox_libdir = $opt_testmode ?
+ Cwd::cwd() . "/testdir/var/lib/pve-installer" : "/var/lib/pve-installer";
+my $proxmox_cddir = $opt_testmode ? "../pve-cd-builder/tmp/data-gz/" : "/cdrom";
+my $proxmox_pkgdir = "${proxmox_cddir}/proxmox/packages/";
my $grub_plattform = "pc"; # pc, efi-amd64 or efi-ia32
return $? if $noout; # behave like standard system();
- my $ec = ($? >> 8);
-
- if ($ec) {
- die "command '$cmdstr' failed with exit code $ec";
+ if ($? == -1) {
+ die "command '$cmdstr' failed to execute\n";
+ } elsif (my $sig = ($? & 127)) {
+ die "command '$cmdstr' failed - got signal $sig\n";
+ } elsif (my $exitcode = ($? >> 8)) {
+ die "command '$cmdstr' failed with exit code $exitcode";
}
return $ostream;
}
sub read_cmap {
- my $countryfn = $opt_testmode ? "/usr/share/pve-manager/country.dat" :
- "/cdrom/proxmox/country.dat";
+ my $countryfn = "${proxmox_libdir}/country.dat";
open (TMP, "<$countryfn") || die "unable to open '$countryfn' - $!\n";
my $line;
my $country = {};
syscmd ("zfs create $zfspoolname/ROOT/pve-1") == 0 ||
die "unable to create zfs $zfspoolname/ROOT/pve-1 volume\n";
- # disable atime during insatll
+ # disable atime during install
syscmd ("zfs set atime=off $zfspoolname") == 0 ||
die "unable to set zfs properties\n";
my $datadev = '/dev/pve/data';
my $swapfile = '/dev/pve/swap';
- # we use --metadatasize 250k, which reseults in "pe_start = 512"
+ # we use --metadatasize 250k, which results in "pe_start = 512"
# so pe_start is aligned on a 128k boundary (advantage for SSDs)
syscmd ("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
die "unable to initialize physical volume $lvmdev\n";
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
$ino || die "unable to open file '$basefile' - $!\n";
- my $files;
- if ($opt_testmode) {
- $files = file_read_firstline("/pve/$release/install/pve-base.cnt");
- } else {
- $files = file_read_firstline("/cdrom/proxmox/pve-base.cnt");
- }
+ my $files = file_read_firstline("${proxmox_cddir}/proxmox/$setup->{product}-base.cnt") ||
+ die "unable to read base file count\n";
my $per = 0;
my $count = 0;
my $ntype = $ipversion == 4 ? 'inet' : 'inet6';
- my $bridge_port = $ipconf->{ifaces}->{$ipconf->{selected}}->{name};
+ my $ethdev = $ipconf->{ifaces}->{$ipconf->{selected}}->{name};
- $ifaces .= "iface $bridge_port $ntype manual\n";
+ if ($setup->{bridged_network}) {
+ $ifaces .= "iface $ethdev $ntype manual\n";
- $ifaces .=
- "\nauto vmbr0\niface vmbr0 $ntype static\n" .
- "\taddress $ipaddress\n" .
- "\tnetmask $netmask\n" .
- "\tgateway $gateway\n" .
- "\tbridge_ports $bridge_port\n" .
- "\tbridge_stp off\n" .
- "\tbridge_fd 0\n";
+ $ifaces .=
+ "\nauto vmbr0\niface vmbr0 $ntype static\n" .
+ "\taddress $ipaddress\n" .
+ "\tnetmask $netmask\n" .
+ "\tgateway $gateway\n" .
+ "\tbridge_ports $ethdev\n" .
+ "\tbridge_stp off\n" .
+ "\tbridge_fd 0\n";
+ } else {
+ $ifaces .= "auto $ethdev\n" .
+ "iface $ethdev $ntype static\n" .
+ "\taddress $ipaddress\n" .
+ "\tnetmask $netmask\n" .
+ "\tgateway $gateway\n";
+ }
foreach my $iface (sort keys %{$ipconf->{ifaces}}) {
my $name = $ipconf->{ifaces}->{$iface}->{name};
- next if $name eq $bridge_port;
+ next if $name eq $ethdev;
$ifaces .= "\niface $name $ntype manual\n";
}
write_config ($fstab, "$targetdir/etc/fstab");
write_config ("", "$targetdir/etc/mtab");
- syscmd ("cp ${proxmox_dir}/policy-disable-rc.d " .
+ syscmd ("cp ${proxmox_libdir}/policy-disable-rc.d " .
"$targetdir/usr/sbin/policy-rc.d") == 0 ||
die "unable to copy policy-rc.d\n";
- syscmd ("cp ${proxmox_dir}/fake-start-stop-daemon " .
+ syscmd ("cp ${proxmox_libdir}/fake-start-stop-daemon " .
"$targetdir/sbin/") == 0 ||
die "unable to copy start-stop-daemon\n";
$grub_install_devices_txt .= $di->{by_id} || $di->{devname};
}
- # Note: debian-installer/locale is used by console-setup
+ # Note: keyboard-configuration/xbkb-keymap is used by console-setup
+ my $xkmap = $cmap->{kmap}->{$keymap}->{x11} // 'us';
debconfig_set ($targetdir, <<_EOD);
locales locales/default_environment_locale select en_US.UTF-8
locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
samba-common samba-common/dhcp boolean false
samba-common samba-common/workgroup string WORKGROUP
-postfix postfix/main_mailer_type select Local only
-keyboard-configuration keyboard-configuration/xkb-keymap select $keymap
+postfix postfix/main_mailer_type select No configuration
+keyboard-configuration keyboard-configuration/xkb-keymap select $xkmap
d-i debian-installer/locale select en_US.UTF-8
grub-pc grub-pc/install_devices select $grub_install_devices_txt
_EOD
- my $pkgdir = $opt_testmode ? "packages" : "/cdrom/proxmox/packages";
my $pkg_count = 0;
- while (<$pkgdir/*.deb>) { $pkg_count++ };
+ while (<${proxmox_pkgdir}/*.deb>) { $pkg_count++ };
# btrfs/dpkg is extremely slow without --force-unsafe-io
my $dpkg_opts = $use_btrfs ? "--force-unsafe-io" : "";
$count = 0;
- while (<$pkgdir/*.deb>) {
+ while (<${proxmox_pkgdir}/*.deb>) {
chomp;
my $path = $_;
- my ($deb) = $path =~ m/$pkgdir\/(.*\.deb)/;
+ my ($deb) = $path =~ m/${proxmox_pkgdir}\/(.*\.deb)/;
# if ($deb =~ m/^grub-efi-/ && $deb !~ m/^grub-${grub_plattform}/) {
# $count++;
# next;
display_html ("extract4-virus.htm");
+ # needed for postfix postinst in case no other NIC is active
+ syscmd("chroot $targetdir ifup lo");
+
my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
$count = 0;
run_command ($cmd, sub {
}
});
- debconfig_set ($targetdir, <<_EOD);
-postfix postfix/main_mailer_type select No configuration
-_EOD
-
unlink "$targetdir/etc/mailname";
$postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
write_config ($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
# allow ssh root login
syscmd ("sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/' '$targetdir/etc/ssh/sshd_config'");
- # save installer settings
- my $ucc = uc ($country);
- debconfig_set ($targetdir, <<_EOD);
-pve-manager pve-manager/country string $ucc
-_EOD
+ if ($setup->{product} eq 'pve') {
+ # save installer settings
+ my $ucc = uc ($country);
+ debconfig_set($targetdir, "pve-manager pve-manager/country string $ucc\n");
+ }
update_progress (0.8, 0.95, 1, "make system bootable");
run_command ("chroot $targetdir /usr/sbin/chpasswd", undef,
"root:$octets\n");
- # create pmxcfs DB
+ if ($setup->{product} eq 'pmg') {
+ mkdir "/etc/pmg";
+ # save admin email
+ write_config ("#Unix Superuser\nroot:1:0::root:${mailto}:::\n",
+ "/etc/pmg/user.conf");
- my $tmpdir = "$targetdir/tmp/pve";
- mkdir $tmpdir;
+ } elsif ($setup->{product} eq 'pve') {
- # write vnc keymap to datacenter.cfg
- my $vnckmap = $cmap->{kmap}->{$keymap}->{kvm} || 'en-us';
- write_config ("keyboard: $vnckmap\n",
- "$tmpdir/datacenter.cfg");
+ # create pmxcfs DB
- # save admin email
- write_config ("user:root\@pam:1:0:::${mailto}::\n",
- "$tmpdir/user.cfg");
+ my $tmpdir = "$targetdir/tmp/pve";
+ mkdir $tmpdir;
- # write storage.cfg
- my $strorage_cfg_fn = "$tmpdir/storage.cfg";
- if ($use_zfs) {
- write_config ($storage_cfg_zfs, $strorage_cfg_fn);
- } elsif ($use_btrfs) {
- write_config ($storage_cfg_btrfs, $strorage_cfg_fn);
- } else {
- write_config ($storage_cfg_lvmthin, $strorage_cfg_fn);
- }
+ # write vnc keymap to datacenter.cfg
+ my $vnckmap = $cmap->{kmap}->{$keymap}->{kvm} || 'en-us';
+ write_config ("keyboard: $vnckmap\n",
+ "$tmpdir/datacenter.cfg");
+
+ # save admin email
+ write_config ("user:root\@pam:1:0:::${mailto}::\n",
+ "$tmpdir/user.cfg");
+
+ # write storage.cfg
+ my $strorage_cfg_fn = "$tmpdir/storage.cfg";
+ if ($use_zfs) {
+ write_config ($storage_cfg_zfs, $strorage_cfg_fn);
+ } elsif ($use_btrfs) {
+ write_config ($storage_cfg_btrfs, $strorage_cfg_fn);
+ } else {
+ write_config ($storage_cfg_lvmthin, $strorage_cfg_fn);
+ }
- run_command("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
+ run_command("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
- syscmd ("rm -rf $tmpdir");
+ syscmd ("rm -rf $tmpdir");
+ }
};
my $err = $@;
my $elapsed = Time::HiRes::tv_interval($starttime);
print "Elapsed extract time: $elapsed\n";
- syscmd ("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> pve-final.pkglist");
+ syscmd ("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> final.pkglist");
}
- syscmd ("umount $targetdir/var/lib/vz");
syscmd ("umount $targetdir/tmp");
syscmd ("umount $targetdir/proc");
syscmd ("umount $targetdir/sys");
syscmd ("zpool set bootfs=$zfspoolname/ROOT/pve-1 $zfspoolname") == 0 ||
die "zfs set bootfs failed\n";
+ syscmd ("zpool export $zfspoolname");
}
die $err if $err;
sub display_html {
my ($filename) = @_;
- my $path = "${proxmox_dir}/html/$filename";
+ my $path = "${proxmox_libdir}/html/$filename";
+
my $url = "file://$path";
my $data = file_get_contents($path);
if ($filename eq 'license.htm') {
- my $licensefn = -f "/EULA" ? "/EULA" :
- $opt_testmode ? "./copyright" :
- "/usr/share/doc/pve-installer/copyright";
- my $license = decode('utf8', file_get_contents($licensefn));
- $license =~ m/^\s+(.+\n)/;
- my $title = $licensefn eq '/EULA' ? "END USER LICENSE AGREEMENT (EULA)": $1;
+ my $license = decode('utf8', file_get_contents("${proxmox_cddir}/EULA"));
+ my $title = "END USER LICENSE AGREEMENT (EULA)";
$data =~ s/__LICENSE__/$license/;
$data =~ s/__LICENSE_TITLE__/$title/;
}
$next->grab_focus ();
}
-sub url_requested {
- my ($doc, $url, $stream) = @_;
-
- $stream->set_cancel_func (sub {}); # hack: avoid warning
-
- my $path = "${proxmox_dir}/html/$url";
-
- if (-f $path) {
- open (HTMLTMP, $path) ||
- die "unable to open file '$path' - $!\n";
- my $buf;
- while (my $i = read (HTMLTMP, $buf, 4096)) {
- $stream->write ($buf);
- Gtk3::main_iteration() while Gtk3::events_pending();
- }
- close (HTMLTMP);
- }
-
- #$stream->close(); # hack: dont close - avoid crash
-}
-
sub create_main_window {
$window = Gtk3::Window->new ();
my $vbox = Gtk3::VBox->new (0, 0);
- my $image = Gtk3::Image->new_from_file ("${proxmox_dir}/proxlogo.png");
+ my $image = Gtk3::Image->new_from_file ("${proxmox_libdir}/proxlogo.png");
$vbox->pack_start ($image, 0, 0, 0);
my $hbox = Gtk3::HBox->new (0, 0);
$vbox2->pack_start ($devicebox, 0, 0, 2);
- my $hn = $ipconf->{domain} ? "pve.$ipconf->{domain}" : 'pve.example.invalid';
+ my $hn = $ipconf->{domain} ?
+ "$setup->{product}.$ipconf->{domain}" : "$setup->{product}.example.invalid";
my ($hostbox, $hostentry) =
create_text_input ($hn, 'Hostname (FQDN):');
$vbox->pack_start ($hbox2, 0, 0, 5);
$vbox->pack_start ($hbox3, 0, 0, 5);
- if ($country) {
+ if ($country && $ctr->{$country}) {
$w->set_text ($ctr->{$country}->{name});
}
my $scrolled_window = Gtk3::ScrolledWindow->new();
$scrolled_window->set_hexpand(1);
+ $scrolled_window->set_propagate_natural_height(1) if @$hds > 4;
$scrolled_window->add(&$create_label_widget_grid($disk_labeled_widgets));
$scrolled_window->set_policy('never', 'automatic');
'zfs (RAIDZ-2)', 'zfs (RAIDZ-3)'];
push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
- if $enable_btrfs;
+ if $setup->{enable_btrfs};
my $tcount = 0;
foreach my $tmp (@$fstype) {
}
my (undef, $pref_width) = $dialog->get_preferred_width();
my (undef, $pref_height) = $dialog->get_preferred_height();
+ $pref_height = 750 if $pref_height > 750;
$dialog->resize($pref_width, $pref_height);
};
my $tdir = $opt_testmode ? "target" : "/target";
mkdir $tdir;
- my $base = $opt_testmode ? "/pve/$release/install/pve-base.squashfs" : "/cdrom/pve-base.squashfs";
+ my $base = "${proxmox_cddir}/$setup->{product}-base.squashfs";
eval { extract_data ($base, $tdir); };
my $err = $@;
cleanup_view ();
+ if ($setup->{product} eq 'pve') {
+ eval {
+ my $cpuinfo = file_get_contents('/proc/cpuinfo');
+ if ($cpuinfo && !($cpuinfo =~ /^flags\s*:.*(vmx|svm)/m)) {
+ display_error("No support for KVM virtualisation detected.\n\n" .
+ "Check BIOS settings for Intel VT / AMD-V / SVM.")
+ }
+ };
+ }
+
display_html ("license.htm");
set_next ("I a_gree", \&create_hdsel_view);
$ipconf = get_ip_config ();
-$country = detect_country() if $ipconf->{default} || $opt_testmode;;
+$country = detect_country() if $ipconf->{default} || $opt_testmode;
# read country, kmap and timezone infos
$cmap = read_cmap ();
+if (!defined($cmap->{country}->{$country})) {
+ print $logfd "ignoring detected country '$country', invalid or unknown\n";
+ $country = undef;
+}
+
create_main_window ();
my $initial_error = 0;