]>
git.proxmox.com Git - pve-installer.git/blob - proxinstall
3 $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
16 use String
::ShellQuote
;
21 my $kapi = `uname -r`;
26 if (!$ENV{G_SLICE
} || $ENV{G_SLICE
} ne "always-malloc") {
27 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
30 if (!GetOptions
('testmode=s' => \
$opt_testmode)) {
35 my $logfd = IO
::File-
>new (">/tmp/install.log");
37 my $proxmox_dir = $opt_testmode ? Cwd
::cwd
() : "/var/lib/pve-installer";
39 my $grub_plattform = "pc"; # pc, efi-amd64 or efi-ia32
41 $grub_plattform = "efi-amd64" if -d
"/sys/firmware/efi";
43 my ($window, $cmdbox, $inbox, $htmlview);
44 my ($next, $next_fctn, $target_hd, $master_hd);
45 my ($progress, $progress_status);
46 my ($ipaddress, $ip_1, $ip_2, $ip_3, $ip_4);
47 my ($netmask, $mask_1, $mask_2, $mask_3, $mask_4);
48 my ($gateway, $gw_1, $gw_2, $gw_3, $gw_4);
49 my ($dnsserver, $dns_1, $dns_2, $dns_3, $dns_4);
50 my $hostname = 'proxmox';
51 my $domain = 'domain.tld';
52 my $cmdline = `cat /proc/cmdline` || '';
55 my $timezone = 'Europe/Vienna';
61 my $filesys = ($cmdline =~ m/\sext4(\s.*)$/) ?
'ext4' : 'ext3';
63 my $postfix_main_cf = <<_EOD;
64 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
68 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
71 # appending .domain is the MUA's job.
72 append_dot_mydomain = no
74 # Uncomment the next line to generate "delayed mail" warnings
75 #delay_warning_time = 4h
77 alias_maps = hash:/etc/aliases
78 alias_database = hash:/etc/aliases
79 mydestination = \$myhostname, localhost.\$mydomain, localhost
81 mynetworks = 127.0.0.0/8
82 inet_interfaces = loopback-only
83 recipient_delimiter = +
90 return String
::ShellQuote
::shell_quote
($str);
96 die "no arguments" if !$cmd;
98 return $cmd if !ref($cmd);
101 foreach my $arg (@$cmd) { push @qa, shellquote
($arg); }
103 return join (' ', @qa);
109 return run_command
($cmd, undef, undef, 1);
113 my ($cmd, $func, $input, $noout) = @_;
119 # see 'man bash' for option pipefail
120 $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
125 $cmdstr = cmd2string
($cmd);
129 if ($input && ($cmdstr !~ m/chpasswd/)) {
130 $cmdtxt = "# $cmdstr <<EOD\n$input";
132 $cmdtxt .= "\nEOD\n";
134 $cmdtxt = "# $cmdstr\n";
138 print $logfd $cmdtxt;
140 my $reader = IO
::File-
>new();
141 my $writer = IO
::File-
>new();
142 my $error = IO
::File-
>new();
148 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
154 if ($orig_pid != $$) {
161 print $writer $input if defined $input;
164 my $select = new IO
::Select
;
165 $select->add ($reader);
166 $select->add ($error);
168 my ($ostream, $logout) = ('', '', '');
170 while ($select->count) {
171 my @handles = $select->can_read (0.2);
173 Gtk3-
>main_iteration while Gtk3-
>events_pending;
175 next if !scalar (@handles); # timeout
177 foreach my $h (@handles) {
179 my $count = sysread ($h, $buf, 4096);
180 if (!defined ($count)) {
184 die "command '$cmd' failed: $err";
186 $select->remove ($h) if !$count;
188 $ostream .= $buf if !($noout || $func);
190 while ($logout =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
192 &$func($line) if $func;
195 } elsif ($h eq $error) {
196 $ostream .= $buf if !($noout || $func);
204 &$func($logout) if $func;
206 my $rv = waitpid ($pid, 0);
208 return $? if $noout; # behave like standard system();
213 die "command '$cmd' failed with exit code $ec";
221 print "trying to detect country...\n";
222 open (TMP
, "traceroute -N 1 -q 1 -n 8.8.8.8|");
226 my $previous_alarm = alarm (10);
228 local $SIG{ALRM
} = sub { die "timed out!\n" };
230 while (defined ($line = <TMP
>)) {
231 print $logfd "DC TRACEROUTE: $line";
232 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
233 my $geoip = `geoiplookup $1`;
234 print $logfd "DC GEOIP: $geoip";
235 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
245 alarm ($previous_alarm);
250 print "unable to detect country - $err\n";
252 print "detected country: " . uc($country) . "\n";
254 print "unable to detect country\n";
262 open (MEMINFO, "/proc/meminfo");
264 my $res = 512; # default to 512 if something goes wrong
265 while (my $line = <MEMINFO>) {
266 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
267 $res = int ($1 / 1024);
276 my $total_memory = get_memtotal();
279 my ($src, $dest) = @_;
281 my ($dev1,$ino1) = stat ($src);
282 my ($dev2,$ino2) = stat ($dest);
284 return 0 if !($dev1 && $dev2 && $ino1 && $ino2);
286 return $ino1 == $ino2 && $dev1 == $dev2;
289 sub find_stable_path {
290 my ($stabledir, $bdev) = @_;
292 my $dh = IO::Dir->new ($stabledir);
294 while (defined(my $tmp = $dh->read)) {
295 my $path = "$stabledir/$tmp";
296 if (link_points_to ($path, $bdev)) {
297 return wantarray ? ($path, $tmp) : $path;
304 return wantarray ? () : undef;
307 sub find_dev_by_uuid {
310 my ($full_path, $name) = find_stable_path ("/dev/disk/by-uuid", $bdev);
320 push @$res, [-1, $opt_testmode, int((-s $opt_testmode)/512), "TESTDISK"];
325 foreach my $bd (</sys/block/*>) {
326 next if $bd =~ m|^/sys/block/ram\d+$|;
327 next if $bd =~ m|^/sys/block/loop\d+$|;
328 next if $bd =~ m|^/sys/block/md\d+$|;
329 next if $bd =~ m|^/sys/block/dm-.*$|;
330 next if $bd =~ m|^/sys/block/fd\d+$|;
331 next if $bd =~ m|^/sys/block/sr\d+$|;
333 my $dev = `cat
'$bd/dev'`;
338 my $info = `udevadm info
--path
$bd --query all
`;
341 next if $info !~ m/^E: DEVTYPE=disk$/m;
343 next if $info =~ m/^E: ID_CDROM/m;
345 my ($name) = $info =~ m/^N: (\S+)$/m;
348 my $real_name = "/dev/$name";
350 my $size = `cat
'$bd/size'`;
352 $size = undef if !($size && $size =~ m/^\d+$/);
354 my $model = `cat
'$bd/device/model'`;
357 if (length ($model) > 30) {
358 $model = substr ($model, 0, 30);
360 push @$res, [$count++, $real_name, $size, $model] if $size;
362 print STDERR "ERROR: unable to map device $dev ($bd)\n";
370 my $countryfn = $opt_testmode ? "/usr/share/pve-manager/country.dat" :
371 "/proxmox/country.dat";
372 open (TMP, "<$countryfn") || die "unable to open '$countryfn' - $!\n";
375 my $countryhash = {};
378 while (defined ($line = <TMP>)) {
379 if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
387 $kmaphash->{$2} = $1;
388 } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
394 $countryhash->{lc($2)} = $1;
396 warn "unable to parse 'country.dat' line: $line";
403 my $zonefn = "/usr/share/zoneinfo/zone.tab";
404 open (TMP, "<$zonefn") || die "unable to open '$zonefn' - $!\n";
405 while (defined ($line = <TMP>)) {
406 next if $line =~ m/^\#/;
407 next if $line =~ m/^\s*$/;
408 if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
410 $cczones->{$cc}->{$2} = 1;
411 $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
422 countryhash => $countryhash,
424 kmaphash => $kmaphash,
428 # search for Harddisks
429 my $hds = hd_list ();
434 foreach my $hd (@$hds) {
435 my ($disk, $devname, $size, $model) = @$hd;
436 return int($size/2) if $devname eq $dev;
439 die "no such device '$dev'";
442 # find the master boot disk - return the first found scsi/ide disk
444 my ($target_hd) = @_;
446 foreach my $hd (sort { ${$a}[1] cmp ${$b}[1] } @$hds) {
447 my ($disk, $devname) = @$hd;
450 if ($target_hd =~ m|^/dev/sd|) {
451 return $devname if $devname =~ m|^/dev/sd|;
452 } elsif ($target_hd =~ m|^/dev/hd|) {
453 return $devname if $devname =~ m|^/dev/hd|;
454 } elsif ($target_hd =~ m|^/dev/i2o/|) {
455 return $devname if $devname =~ m|^/dev/i2o/|;
456 } elsif ($target_hd =~ m|^/dev/ataraid/|) {
457 return $devname if $devname =~ m|^/dev/ataraid/|;
458 } elsif ($target_hd =~ m|^/dev/ida/|) {
459 return $devname if $devname =~ m|^/dev/ida/|;
460 } elsif ($target_hd =~ m|^/dev/cciss/|) {
461 return $devname if $devname =~ m|^/dev/cciss/|;
462 } elsif ($target_hd =~ m|^/dev/rd/|) {
463 return $devname if $devname =~ m|^/dev/rd/|;
470 sub get_partition_dev {
471 my ($target_hd, $partnum) = @_;
473 if ($target_hd =~ m|^/dev/[hxsev]d[a-z]$|) {
474 return "${target_hd}$partnum";
475 } elsif ($target_hd =~ m|^/dev/[^/]+/c\d+d\d+$|) {
476 return "${target_hd}p$partnum";
477 } elsif ($target_hd =~ m|^/dev/[^/]+/d\d+$|) {
478 return "${target_hd}p$partnum";
479 } elsif ($target_hd =~ m|^/dev/[^/]+/hd[a-z]$|) {
480 return "${target_hd}$partnum";
482 die "unable to get device for partition $partnum on device $target_hd\n";
487 sub file_get_contents {
488 my ($filename, $max) = @_;
490 my $fh = IO::File->new($filename, "r") ||
491 die "can't open '$filename' - $!\n";
493 local $/; # slurp mode
503 my ($text, $filename) = @_;
505 my $fd = IO::File->new (">$filename") ||
506 die "unable to open file '$filename' - $!";
511 sub update_progress {
512 my ($frac, $start, $end, $text) = @_;
514 my $part = $end - $start;
515 my $res = $start + $frac*$part;
517 $progress->set_fraction ($res);
518 $progress->set_text (sprintf ("%d%%", int ($res*100)));
519 $progress_status->set_text ($text) if defined ($text);
521 Gtk3->main_iteration while Gtk3->events_pending;
524 sub create_filesystem {
525 my ($dev, $name, $type, $start, $end, $fs, $fe, $opts) = @_;
527 $opts = '' if !$opts;
529 my $range = $end - $start;
530 my $rs = $start + $range*$fs;
531 my $re = $start + $range*$fe;
534 update_progress (0, $rs, $re, "creating $name filesystem");
536 run_command ("mkfs.$type $opts -F $dev", sub {
539 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
541 } elsif ($max && $line =~ m/(\d+)\/$max/) {
542 update_progress (($1/$max)*0.9, $rs, $re);
543 } elsif ($line =~ m/Creating journal.*done/) {
544 update_progress (0.95, $rs, $re);
545 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
546 update_progress (1, $rs, $re);
552 my ($targetdir, $dcdata) = @_;
554 my $cfgfile = "/tmp/debconf.txt";
555 write_config ($dcdata, "$targetdir/$cfgfile");
556 syscmd ("chroot $targetdir debconf-set-selections $cfgfile");
557 unlink "$targetdir/$cfgfile";
561 my ($targetdir, $cmd, $new_cmd) = @_;
563 syscmd ("chroot $targetdir dpkg-divert --package proxmox " .
564 "--add --rename $cmd") == 0 ||
565 die "unable to exec dpkg-divert\n";
567 syscmd ("ln -sf ${new_cmd} $targetdir/$cmd") == 0 ||
568 die "unable to link diversion to ${new_cmd}\n";
571 sub diversion_remove {
572 my ($targetdir, $cmd) = @_;
574 syscmd ("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0 ||
575 die "unable to remove $cmd diversion\n";
577 syscmd ("chroot $targetdir dpkg-divert --remove $cmd") == 0 ||
578 die "unable to remove $cmd diversion\n";
582 my ($tgzfile, $targetdir) = @_;
584 die "target '$targetdir' does not exist\n" if ! -d $targetdir;
596 update_progress (0, 0, $maxper, "create partitions");
598 if ( -b $target_hd) {
599 syscmd ("dd if=/dev/zero of=${target_hd} bs=512 count=256");
600 my $hdsize = hd_size ($target_hd); # size in blocks (1024 bytes)
602 if ($cmdline =~ m/hdsize=(\d+)[\s\n]/i) {
603 # max hdsize passed on cmdline (GB)
604 my $maxhdsize=$1*1024*1024;
606 # use $maxhdsize if specified size is lower than hdsize
607 if ($maxhdsize < $hdsize) {
608 $hdsize = $maxhdsize;
612 if ($grub_plattform =~ m/^efi/) {
613 $efibootdev = get_partition_dev($target_hd, 1);
615 $bootdev = get_partition_dev ($target_hd, 2);
616 my $lvmdev = get_partition_dev ($target_hd, 3);
618 my $efibootsize_mb = 512;
619 my $bootsize_mb = 512;
621 my $hdsize_mb = $hdsize/1024;
623 my $pcmd = ['parted', '--script', '--align', 'optimal', $target_hd];
624 push @$pcmd, 'unit', 'MiB';
625 push @$pcmd, 'mklabel', 'gpt';
630 push @$pcmd, 'mkpart', 'primary', 'fat32', 1, $efibootsize_mb;
631 push @$pcmd, 'set', $pnum, 'boot', 'on';
632 push @$pcmd, 'name', $pnum, 'EFI-System-Partition';
634 push @$pcmd, 'mkpart', 'primary', 1, 2;
635 push @$pcmd, 'set', $pnum, 'bios_grub', 'on';
636 push @$pcmd, 'name', $pnum, 'Grub-Boot-Partition';
641 push @$pcmd, 'mkpart', 'primary', 'ext2', $efibootsize_mb, $efibootsize_mb + $bootsize_mb;
643 push @$pcmd, 'mkpart', 'primary', 'ext2', 2, $bootsize_mb;
644 push @$pcmd, 'set', $pnum, 'boot', 'on';
646 push @$pcmd, 'name', $pnum, 'PVE-Boot-Partition';
650 push @$pcmd, 'mkpart', 'primary', 'ext2', $efibootsize_mb + $bootsize_mb, $hdsize_mb;
652 push @$pcmd, 'mkpart', 'primary', 'ext2', $bootsize_mb, $hdsize_mb;
655 push @$pcmd, 'set', $pnum, 'lvm', 'on';
656 push @$pcmd, 'name', $pnum, 'PVE-LVM2-Partition';
658 syscmd($pcmd) == 0 ||
659 die "unable to partition harddisk '${target_hd}'\n";
661 sleep(1); # give kernel time to reread part table
663 $rootdev = '/dev/pve/root';
664 $datadev = '/dev/pve/data';
665 $swapfile = '/dev/pve/swap';
667 # we use --metadatasize 250k, which reseults in "pe_start = 512"
668 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
669 syscmd ("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
670 die "unable to initialize physical volume $lvmdev";
671 syscmd ("/sbin/vgcreate pve $lvmdev") == 0 ||
672 die "unable to create volume group";
674 my $hdgb = int($hdsize/(1024*1024));
675 die "hardisk too small (${hdgb}GB)" if $hdgb < 4;
678 if ($cmdline =~ m/swapsize=(\d+)[\s\n]/i) {
679 $swapsize=$1*1024*1024;
681 my $ss = int ($total_memory / 1024);
683 $ss = ($hdgb/8) if $ss > ($hdgb/8);
684 $swapsize = $ss*1024*1024;
687 my $space = (($hdgb > 128) ? 16 : ($hdgb/8))*1024*1024;
690 if ($cmdline =~ m/maxroot=(\d+)[\s\n]/i) {
696 my $rootsize = (($hdgb > ($maxroot*4)) ? $maxroot : $hdgb/4)*1024*1024;
698 my $bootsize = $bootsize_mb * 1024;
699 $bootsize += $efibootsize_mb * 1024 if $efibootdev;
701 my $rest = int($hdsize) - $bootsize - $swapsize - $rootsize; # in KB
704 if ($cmdline =~ m/minfree=(\d+)[\s\n]/i) {
705 $minfree = (($1*1024*1024) >= $rest ) ? $space : $1*1024*1024 ;
710 $rest = $rest - $minfree;
712 if ($cmdline =~ m/maxvz=(\d+)[\s\n]/i) {
713 $rest = (($1*1024*1024) <= $rest) ? $1*1024*1024 : $rest;
716 syscmd ("/sbin/lvcreate -L${swapsize}K -nswap pve") == 0 ||
717 die "unable to create swap volume";
719 syscmd ("/sbin/lvcreate -L${rootsize}K -nroot pve") == 0 ||
720 die "unable to create root volume";
722 syscmd ("/sbin/lvcreate -L${rest}K -ndata pve") == 0 ||
723 die "unable to create data volume";
725 syscmd ("/sbin/vgchange -a y pve") == 0 ||
726 die "unable to activate volume group";
729 $rootdev = $target_hd;
730 syscmd ("umount $rootdev");
733 update_progress (0.03, 0, $maxper, "create swap space");
735 syscmd ("mkswap $swapfile") == 0 ||
736 die "unable to create swap space\n";
739 update_progress (0.05, 0, $maxper, "creating filesystems");
741 if ( -b $target_hd) {
743 syscmd ("mkfs.vfat -F32 $efibootdev");
745 create_filesystem ($bootdev, 'boot', $filesys, 0.05, $maxper, 0, 0.1, '-m 0');
746 create_filesystem ($rootdev, 'root', $filesys, 0.05, $maxper, 0.1, 0.5);
747 create_filesystem ($datadev, 'data', $filesys, 0.05, $maxper, 0.5, 1, '-m 0');
749 create_filesystem ($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1, '-m 0');
752 update_progress (1, 0.05, $maxper, "mounting target $rootdev");
754 if ( -b $target_hd) {
756 # trigger udev to create /dev/disk/by-uuid
757 syscmd ("udevadm trigger --subsystem-match block");
758 syscmd ("udevadm settle --timeout 10");
760 syscmd ("mount -n $rootdev -o noatime,barrier=0 $targetdir") == 0 ||
761 die "unable to mount $rootdev\n";
763 mkdir "$targetdir/boot";
764 syscmd ("mount -n $bootdev -o noatime,barrier=0 $targetdir/boot") == 0 ||
765 die "unable to mount $bootdev\n";
768 mkdir "$targetdir/boot/efi";
769 syscmd ("mount -n $efibootdev $targetdir/boot/efi") == 0 ||
770 die "unable to mount $efibootdev\n";
773 mkdir "$targetdir/var";
774 mkdir "$targetdir/var/lib";
775 mkdir "$targetdir/var/lib/vz";
776 syscmd ("mount -n $datadev $targetdir/var/lib/vz") == 0 ||
777 die "unable to mount $datadev\n";
780 syscmd ("mount $rootdev $targetdir -o loop,noatime,barrier=0") == 0 ||
781 die "unable to mount $rootdev\n";
784 display_html ("extract2-rulesystem.htm");
785 update_progress (1, 0.05, $maxper, "extracting base system");
787 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($tgzfile);
788 $ino || die "unable to open file '$tgzfile' - $!\n";
792 $files = `cat
/pve/$release/install/pve-base
.cnt
`;
794 $files = `cat
/proxmox/pve
-base
.cnt
`;
800 run_command ("tar xvf $tgzfile -C $targetdir", sub {
803 my $nper = int (($count *100)/$files);
806 my $frac = $per > 100 ? 100 : $per/100;
807 update_progress ($frac, $maxper, 0.5);
811 syscmd ("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 ||
812 die "unable to mount tmpfs on $targetdir/tmp\n";
813 syscmd ("mount -n -t proc proc $targetdir/proc") == 0 ||
814 die "unable to mount proc on $targetdir/proc\n";
815 syscmd ("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
816 die "unable to mount sysfs on $targetdir/sys\n";
818 display_html ("extract3-spam.htm");
819 update_progress (1, $maxper, 0.5, "configuring base system");
824 "127.0.0.1 localhost.localdomain localhost\n" .
825 "$ipaddress $hostname.$domain $hostname pvelocalhost\n\n" .
826 "# The following lines are desirable for IPv6 capable hosts\n\n" .
827 "::1 ip6-localhost ip6-loopback\n" .
828 "fe00::0 ip6-localnet\n" .
829 "ff00::0 ip6-mcastprefix\n" .
830 "ff02::1 ip6-allnodes\n" .
831 "ff02::2 ip6-allrouters\n" .
832 "ff02::3 ip6-allhosts\n";
834 write_config ($hosts, "$targetdir/etc/hosts");
836 write_config ("$hostname\n", "$targetdir/etc/hostname");
838 syscmd ("/bin/hostname $hostname") if !$opt_testmode;
840 # configure interfaces
843 "auto lo\niface lo inet loopback\n\n" .
844 "auto vmbr0\niface vmbr0 inet static\n" .
845 "\taddress $ipaddress\n" .
846 "\tnetmask $netmask\n" .
847 "\tgateway $gateway\n" .
848 "\tbridge_ports eth0\n" .
849 "\tbridge_stp off\n" .
852 write_config ($ifaces, "$targetdir/etc/network/interfaces");
856 my $resolfconf = "search $domain\nnameserver $dnsserver\n";
857 write_config ($resolfconf, "$targetdir/etc/resolv.conf");
859 # try to use UUID=XXX for boot device
860 my $boot_uuid = $bootdev;
861 if (my $uuid = find_dev_by_uuid ($bootdev)) {
862 $boot_uuid = "UUID=$uuid";
868 "# <file system> <mount point> <type> <options> <dump> <pass>\n" .
869 "$rootdev / $filesys errors=remount-ro 0 1\n";
871 $fstab .= "$datadev /var/lib/vz $filesys defaults 0 1\n" if $datadev;
873 $fstab .= "${boot_uuid} /boot $filesys defaults 0 1\n" if $boot_uuid;
876 my $efi_boot_uuid = $efibootdev;
877 if (my $uuid = find_dev_by_uuid ($efibootdev)) {
878 $efi_boot_uuid = "UUID=$uuid";
881 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
884 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
886 $fstab .= "proc /proc proc defaults 0 0\n";
888 write_config ($fstab, "$targetdir/etc/fstab");
889 write_config ("", "$targetdir/etc/mtab");
891 syscmd ("cp ${proxmox_dir}/policy-disable-rc.d " .
892 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
893 die "unable to copy policy-rc.d\n";
894 syscmd ("cp ${proxmox_dir}/fake-start-stop-daemon " .
895 "$targetdir/sbin/") == 0 ||
896 die "unable to copy start-stop-daemon\n";
898 diversion_add ($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
899 diversion_add ($targetdir, "/usr/sbin/update-grub", "/bin/true");
900 diversion_add ($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
902 syscmd ("touch $targetdir/proxmox_install_mode");
904 debconfig_set ($targetdir, <<_EOD);
905 locales locales/default_environment_locale select en_US.UTF-8
906 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
907 samba-common samba-common/dhcp boolean false
908 samba-common samba-common/workgroup string WORKGROUP
909 postfix postfix/main_mailer_type select Local only
910 console-data console-data/keymap/policy select Don\'t touch keymap
913 my $pkgdir = $opt_testmode ?
"packages" : "/proxmox/packages";
915 while (<$pkgdir/*.deb
>) { $pkg_count++ };
918 while (<$pkgdir/*.deb
>) {
921 my ($deb) = $path =~ m/$pkgdir\/(.*\
.deb
)/;
922 if ($deb =~ m/^grub-efi-/ && $deb !~ m/^grub-${grub_plattform}/) {
926 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
927 print "extracting: $deb\n";
928 syscmd
("cp $path $targetdir/tmp/$deb") == 0 ||
929 die "installation of package $deb failed\n";
930 syscmd
("chroot $targetdir dpkg --force-depends --no-triggers --unpack /tmp/$deb") == 0 ||
931 die "installation of package $deb failed\n";
932 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
935 display_html
("extract4-virus.htm");
937 my $cmd = "chroot $targetdir dpkg --force-confold --configure -a";
939 run_command
($cmd, sub {
941 if ($line =~ m/Setting up\s+(\S+)/) {
942 update_progress
((++$count)/$pkg_count, 0.75, 0.95,
947 debconfig_set
($targetdir, <<_EOD);
948 postfix postfix/main_mailer_type select No configuration
951 unlink "$targetdir/etc/mailname";
952 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
953 write_config
($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
955 # make sure we have all postfix directories
956 syscmd
("chroot $targetdir /usr/sbin/postfix check");
958 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
960 unlink "$targetdir/proxmox_install_mode";
963 syscmd
("touch '$targetdir/etc/bacula/do_not_run'");
966 unlink ("$targetdir/etc/localtime");
967 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
968 write_config
("$timezone\n", "$targetdir/etc/timezone");
971 if (my $kmapfile = $cmap->{kmap
}->{$keymap}->{console
}) {
972 syscmd
("chroot $targetdir /usr/sbin/install-keymap '/usr/share/keymaps/i386/$kmapfile'");
976 if (my $mirror = $cmap->{country
}->{$country}->{mirror
}) {
977 my $fn = "$targetdir/etc/apt/sources.list";
978 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
981 # create extended_states for apt (avoid cron job warning if that
982 # file does not exist)
983 write_config
('', "$targetdir/var/lib/apt/extended_states");
985 # save installer settings
986 my $ucc = uc ($country);
987 debconfig_set
($targetdir, <<_EOD);
988 pve-manager pve-manager/country string $ucc
991 update_progress
(0.8, 0.95, 1, "make system bootable");
993 # update default grub settings
994 syscmd
("sed -i -e 's/^GRUB_DISTRIBUTOR.*/GRUB_DISTRIBUTOR=\"Proxmox Virtual Environment\"/' -e 's/#GRUB_DISABLE_RECOVERY=.*/GRUB_DISABLE_RECOVERY=\"true\"/' $targetdir/etc/default/grub");
996 diversion_remove
($targetdir, "/usr/sbin/update-grub");
997 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
999 if (!$opt_testmode && -b
$target_hd) {
1001 unlink ("$targetdir/etc/mtab");
1002 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1003 syscmd
("mount -n --bind /dev $targetdir/dev");
1005 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1006 die "unable to install initramfs\n";
1008 syscmd
("chroot $targetdir /usr/sbin/grub-install --no-floppy --bootloader-id='proxmox' ${target_hd}") == 0 ||
1009 die "unable to install the boot loader\n";
1011 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1012 die "unable to install the boot loader\n";
1014 syscmd
("umount $targetdir/dev");
1020 # hack: remove dead.letter from sshd installation
1021 syscmd
("rm -rf $targetdir/dead.letter");
1023 unlink "$targetdir/usr/sbin/policy-rc.d";
1025 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1028 my $octets = encode
("utf-8", $password);
1029 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1034 my $tmpdir = "$targetdir/tmp/pve";
1037 # write vnc keymap to datacenter.cfg
1038 my $vnckmap = $cmap->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1039 write_config
("keyboard: $vnckmap\n",
1040 "$tmpdir/datacenter.cfg");
1043 write_config
("user:root\@pam:1:0:::${mailto}::\n",
1044 "$tmpdir/user.cfg");
1046 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1048 syscmd
("rm -rf $tmpdir");
1053 update_progress
(1, 0, 1, "");
1057 if ($opt_testmode) {
1058 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> pve-final.pkglist");
1061 syscmd
("umount $targetdir/boot/efi") if $efibootdev;
1062 syscmd
("umount $targetdir/boot");
1063 syscmd
("umount $targetdir/var/lib/vz");
1064 syscmd
("umount $targetdir/tmp");
1065 syscmd
("umount $targetdir/proc");
1066 syscmd
("umount $targetdir/sys");
1067 syscmd
("umount -d $targetdir");
1073 my ($filename) = @_;
1075 my $path = "${proxmox_dir}/html/$filename";
1076 my $url = "file://$path";
1078 my $data = file_get_contents
($path);
1080 if ($filename eq 'license.htm') {
1081 my $licensefn = -f
"/EULA" ?
"/EULA" :
1082 $opt_testmode ?
"./copyright" :
1083 "/usr/share/doc/pve-installer/copyright";
1084 my $license = decode
('utf8', file_get_contents
($licensefn));
1085 $license =~ m/^\s+(.+\n)/;
1086 my $title = $licensefn eq '/EULA' ?
"END USER LICENSE AGREEMENT (EULA)": $1;
1087 $data =~ s/__LICENSE__/$license/;
1088 $data =~ s/__LICENSE_TITLE__/$title/;
1091 $htmlview->load_html_string($data, $url);
1094 sub display_html_old
{
1095 my ($filename) = @_;
1097 $htmlview->set_document(undef);
1102 $htmlview->set_document($document);
1104 $document->open_stream ("text/html");
1106 my $fn = "${proxmox_dir}/html/$filename";
1108 die "unable to open file '$fn' - $!\n";
1109 while (<HTML
>) { $document->write_stream ($_); }
1112 $document->close_stream;
1116 my ($text, $fctn) = @_;
1119 $text = "_Next" if !$text;
1120 $next->set_label ($text);
1122 $next->grab_focus ();
1126 my ($doc, $url, $stream) = @_;
1128 $stream->set_cancel_func (sub {}); # hack: avoid warning
1130 my $path = "${proxmox_dir}/html/$url";
1133 open (HTMLTMP
, $path) ||
1134 die "unable to open file '$path' - $! ";
1136 while (my $i = read (HTMLTMP
, $buf, 4096)) {
1137 $stream->write ($buf);
1138 Gtk3-
>main_iteration while Gtk3-
>events_pending;
1143 #$stream->close(); # hack: dont close - avoid crash
1146 sub create_main_window
{
1148 $window = Gtk3
::Window-
>new ();
1149 $window->set_default_size (1024, 768);
1150 $window->set_has_resize_grip(0);
1151 $window->set_decorated (0) if !$opt_testmode;
1153 my $vbox = Gtk3
::VBox-
>new (0, 0);
1155 my $image = Gtk3
::Image-
>new_from_file ("${proxmox_dir}/proxlogo.xpm");
1156 $vbox->pack_start ($image, 0, 0, 0);
1158 my $hbox = Gtk3
::HBox-
>new (0, 0);
1159 $vbox->pack_start ($hbox, 1, 1, 0);
1161 # my $f1 = Gtk3::Frame->new ('test');
1162 # $f1->set_shadow_type ('none');
1163 # $hbox->pack_start ($f1, 1, 1, 0);
1165 my $sep1 = Gtk3
::HSeparator-
>new;
1166 $vbox->pack_start ($sep1, 0, 0, 0);
1168 $cmdbox = Gtk3
::HBox-
>new ();
1169 $vbox->pack_start ($cmdbox, 0, 0, 10);
1171 $next = Gtk3
::Button-
>new ('_Next');
1172 $next->signal_connect (clicked
=> sub { &$next_fctn (); });
1173 $cmdbox->pack_end ($next, 0, 0, 10);
1174 my $abort = Gtk3
::Button-
>new ('_Abort');
1175 $abort->set_can_focus (0);
1176 $cmdbox->pack_start ($abort, 0, 0, 10);
1177 $abort->signal_connect (clicked
=> sub { exit (-1); });
1179 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1180 $hbox->add ($vbox2);
1182 $htmlview = Gtk3
::WebKit
::WebView-
>new();
1183 my $scrolls = Gtk3
::ScrolledWindow-
>new();
1184 $scrolls->add($htmlview);
1186 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1187 $hbox2->pack_start ($scrolls, 1, 1, 0);
1189 $vbox2->pack_start ($hbox2, 1, 1, 0);
1191 my $vbox3 = Gtk3
::VBox-
>new (0, 0);
1192 $vbox2->pack_start ($vbox3, 0, 0, 0);
1194 my $sep2 = Gtk3
::HSeparator-
>new;
1195 $vbox3->pack_start ($sep2, 0, 0, 0);
1197 $inbox = Gtk3
::HBox-
>new (0, 0);
1198 $vbox3->pack_start ($inbox, 0, 0, 0);
1200 $window->add ($vbox);
1203 $window->realize ();
1207 my $list = $inbox->get_children;
1208 foreach my $c (@$list) {
1209 next if !defined ($c);
1210 $inbox->remove ($c);
1215 my ($entry, $event) = @_;
1218 my $val = $event->get_keyval;
1220 if ($val == ord '.') {
1221 $entry->get_parent->child_focus ('right');
1225 if ($val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
1226 $val == Gtk3
::Gdk
::KEY_Shift_L
||
1227 $val == Gtk3
::Gdk
::KEY_Tab
||
1228 $val == Gtk3
::Gdk
::KEY_BackSpace
||
1229 $val == Gtk3
::Gdk
::KEY_Delete
||
1230 ($val >= ord '0' && $val <= ord '9') ||
1231 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
1232 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
1240 my ($entry, $event) = @_;
1242 my $text = $entry->get_text;
1243 if (!defined($text) || ($text !~ m/^(\d+)$/) || ($1 > 255)) {
1244 $entry->set_text ($entry->{default});
1251 sub creat_text_input
{
1252 my ($default, $text) = @_;
1254 my $hbox = Gtk3
::HBox-
>new (0, 0);
1256 my $label = Gtk3
::Label-
>new ($text);
1257 $label->set_size_request (150, -1);
1258 $label->set_alignment (1, 0.5);
1259 $hbox->pack_start ($label, 0, 0, 10);
1260 my $e1 = Gtk3
::Entry-
>new ();
1261 $e1->set_width_chars (30);
1262 $hbox->pack_start ($e1, 0, 0, 0);
1263 $e1->set_text ($default);
1265 return ($hbox, $e1);
1268 sub creat_ip_input
{
1269 my ($init, $default, $text) = @_;
1271 my (@ips) = split /\./, $init;
1272 my (@defs) = split /\./, $default;
1274 my $hbox = Gtk3
::HBox-
>new (0, 0);
1276 my $label = Gtk3
::Label-
>new ($text);
1277 $label->set_size_request (150, -1);
1278 $label->set_alignment (1, 0.5);
1279 $hbox->pack_start ($label, 0, 0, 10);
1281 my $e1 = Gtk3
::Entry-
>new();
1282 $e1->set_max_length(3);
1283 $e1->{default} = $defs[0];
1284 $hbox->pack_start ($e1, 0, 0, 0);
1285 $e1->set_width_chars (3);
1286 $e1->set_text ($ips[0]);
1287 $e1->signal_connect (key_press_event
=> \
&check_num
);
1288 $e1->signal_connect (focus_out_event
=> \
&check_range
);
1290 my $l1 = Gtk3
::Label-
>new (".");
1291 $hbox->pack_start ($l1, 0, 0, 2);
1293 my $e2 = Gtk3
::Entry-
>new();
1294 $e2->set_max_length(3);
1295 $e2->{default} = $defs[1];
1296 $hbox->pack_start ($e2, 0, 0, 0);
1297 $e2->set_width_chars (3);
1298 $e2->set_text ($ips[1]);
1299 $e2->signal_connect (key_press_event
=> \
&check_num
);
1300 $e2->signal_connect (focus_out_event
=> \
&check_range
);
1302 my $l2 = Gtk3
::Label-
>new (".");
1303 $hbox->pack_start ($l2, 0, 0, 2);
1305 my $e3 = Gtk3
::Entry-
>new();
1306 $e3->set_max_length(3);
1307 $e3->{default} = $defs[2];
1308 $hbox->pack_start ($e3, 0, 0, 0);
1309 $e3->set_width_chars (3);
1310 $e3->set_text ($ips[2]);
1311 $e3->signal_connect (key_press_event
=> \
&check_num
);
1312 $e3->signal_connect (focus_out_event
=> \
&check_range
);
1314 my $l3 = Gtk3
::Label-
>new (".");
1315 $hbox->pack_start ($l3, 0, 0, 2);
1317 my $e4 = Gtk3
::Entry-
>new();
1318 $e4->set_max_length(3);
1319 $e4->{default} = $defs[3];
1320 $hbox->pack_start ($e4, 0, 0, 0);
1321 $e4->set_width_chars (3);
1322 $e4->set_text ($ips[3]);
1323 $e4->signal_connect (key_press_event
=> \
&check_num
);
1324 $e4->signal_connect (focus_out_event
=> \
&check_range
);
1326 return ($hbox, $e1, $e2, $e3, $e4);
1331 my $ifconfig = `ifconfig eth0`;
1333 my ($addr) = $ifconfig =~ m/inet addr:(\S*)/m;
1334 my ($mask) = $ifconfig =~ m/Mask:(\S*)/m;
1336 my $route = `route -n`;
1337 my ($gateway) = $route =~ m/^0\.0\.0\.0\s+(\d+\.\d+\.\d+\.\d+)\s+/m;
1339 my $resolvconf = `cat /etc/resolv.conf`;
1340 my ($dnsserver) = $resolvconf =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/m;
1345 gateway
=> $gateway,
1346 dnsserver
=> $dnsserver,
1350 sub display_message
{
1353 my $dialog = Gtk3
::MessageDialog-
>new ($window, 'modal',
1354 'info', 'ok', $msg);
1362 my $dialog = Gtk3
::MessageDialog-
>new ($window, 'modal',
1363 'error', 'ok', $msg);
1368 sub create_ipconf_view
{
1371 display_html
("ipconf.htm");
1373 my $vbox = Gtk3
::VBox-
>new (0, 0);
1374 $inbox->pack_start ($vbox, 1, 0, 0);
1375 my $hbox = Gtk3
::HBox-
>new (0, 0);
1376 $vbox->pack_start ($hbox, 0, 0, 10);
1377 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1378 $hbox->add ($vbox2);
1380 my $addr = $ipconf->{addr
} || '192.168.100.2';
1381 my $mask = $ipconf->{mask
} || '255.255.255.0';
1383 my ($hostbox, $hostentry) =
1384 creat_text_input
('proxmox.domain.tld', 'Hostname (FQDN):');
1385 $vbox2->pack_start ($hostbox, 0, 0, 2);
1388 ($ipbox, $ip_1, $ip_2, $ip_3, $ip_4) =
1389 creat_ip_input
($addr, '0.0.0.0', 'IP Address:');
1390 $vbox2->pack_start ($ipbox, 0, 0, 2);
1393 ($maskbox, $mask_1, $mask_2, $mask_3, $mask_4) =
1394 creat_ip_input
($mask, '255.255.255.0', 'Netmask:');
1395 $vbox2->pack_start ($maskbox, 0, 0, 2);
1397 $gateway = $ipconf->{gateway
} || '192.168.100.1';
1400 ($gwbox, $gw_1, $gw_2, $gw_3, $gw_4) =
1401 creat_ip_input
($gateway, '0.0.0.0', 'Gateway:');
1403 $vbox2->pack_start ($gwbox, 0, 0, 2);
1405 $dnsserver = $ipconf->{dnsserver
} || $gateway;
1408 ($dnsbox, $dns_1, $dns_2, $dns_3, $dns_4) =
1409 creat_ip_input
($dnsserver, '0.0.0.0', 'DNS Server:');
1411 $vbox2->pack_start ($dnsbox, 0, 0, 0);
1414 set_next
(undef, sub {
1415 my $text = $hostentry->get_text();
1420 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
1422 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.domain.tld$/ &&
1423 $text =~ m/^([^\.]+)\.(\S+)$/) {
1426 create_extract_view
();
1429 display_message
("Hostname does not look like a fully qualified domain name.");
1430 $hostentry->grab_focus();
1433 $hostentry->grab_focus();
1436 sub get_device_desc
{
1437 my ($devname, $size, $model) = @_;
1439 if ($size && ($size > 0) && $model) {
1440 $size = int($size/2048); # size in MB
1442 if ($size >= 1024) {
1443 $size = int($size/1024); # size in GB
1444 return "$devname (${size}GB, $model)";
1446 return "$devname (${size}MB, $model)";
1455 my ($cb, $kmap) = @_;
1460 my $kmaphash = $cmap->{kmaphash
};
1461 foreach my $layout (sort keys %$kmaphash) {
1462 $def = $i if $kmaphash->{$layout} eq 'en-us';
1463 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
1467 $cb->set_active ($ind || $def || 0);
1471 sub update_zonelist
{
1472 my ($box, $cc) = @_;
1474 my $cczones = $cmap->{cczones
};
1475 my $zones = $cmap->{zones
};
1479 $sel = $lastzonecb->get_active_text();
1480 $box->remove ($lastzonecb);
1482 $sel = $timezone; # used once to select default
1485 my $cb = $lastzonecb = Gtk3
::ComboBoxText-
>new_with_entry();
1486 $cb->set_size_request (200, -1);
1488 $cb->signal_connect ('changed' => sub {
1489 $timezone = $cb->get_active_text();
1493 if ($cc && defined ($cczones->{$cc})) {
1494 @za = keys %{$cczones->{$cc}};
1500 foreach my $zone (sort @za) {
1501 $ind = $i if $sel && $zone eq $sel;
1502 $cb->append_text ($zone);
1506 $cb->set_active ($ind || 0);
1509 $box->pack_start ($cb, 0, 0, 0);
1512 sub create_password_view
{
1516 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1517 $inbox->pack_start ($vbox2, 1, 0, 0);
1518 my $vbox = Gtk3
::VBox-
>new (0, 0);
1519 $vbox2->pack_start ($vbox, 0, 0, 10);
1521 my $hbox1 = Gtk3
::HBox-
>new (0, 0);
1522 my $label = Gtk3
::Label-
>new ("Password");
1523 $label->set_size_request (150, -1);
1524 $label->set_alignment (1, 0.5);
1525 $hbox1->pack_start ($label, 0, 0, 10);
1526 my $pwe1 = Gtk3
::Entry-
>new ();
1527 $pwe1->set_visibility (0);
1528 $pwe1->set_size_request (200, -1);
1529 $hbox1->pack_start ($pwe1, 0, 0, 0);
1531 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1532 $label = Gtk3
::Label-
>new ("Confirm");
1533 $label->set_size_request (150, -1);
1534 $label->set_alignment (1, 0.5);
1535 $hbox2->pack_start ($label, 0, 0, 10);
1536 my $pwe2 = Gtk3
::Entry-
>new ();
1537 $pwe2->set_visibility (0);
1538 $pwe2->set_size_request (200, -1);
1539 $hbox2->pack_start ($pwe2, 0, 0, 0);
1541 my $hbox3 = Gtk3
::HBox-
>new (0, 0);
1542 $label = Gtk3
::Label-
>new ("E-Mail");
1543 $label->set_size_request (150, -1);
1544 $label->set_alignment (1, 0.5);
1545 $hbox3->pack_start ($label, 0, 0, 10);
1546 my $eme = Gtk3
::Entry-
>new ();
1547 $eme->set_size_request (200, -1);
1548 $hbox3->pack_start ($eme, 0, 0, 0);
1551 $vbox->pack_start ($hbox1, 0, 0, 5);
1552 $vbox->pack_start ($hbox2, 0, 0, 5);
1553 $vbox->pack_start ($hbox3, 0, 0, 15);
1557 display_html
("passwd.htm");
1559 set_next
(undef, sub {
1561 my $t1 = $pwe1->get_text;
1562 my $t2 = $pwe2->get_text;
1564 if (length ($t1) < 5) {
1565 display_message
("Password is too short.");
1566 $pwe1->grab_focus();
1571 display_message
("Password does not match.");
1572 $pwe1->grab_focus();
1576 my $t3 = $eme->get_text;
1577 if ($t3 !~ m/^\S+\@\S+\.\S+$/) {
1578 display_message
("E-Mail does not look like a vaild address" .
1579 " (user\@domain.tld)");
1588 create_ipconf_view
();
1591 $pwe1->grab_focus();
1595 sub create_country_view
{
1599 my $countryhash = $cmap->{countryhash
};
1600 my $ctr = $cmap->{country
};
1602 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1603 $inbox->pack_start ($vbox2, 1, 0, 0);
1604 my $vbox = Gtk3
::VBox-
>new (0, 0);
1605 $vbox2->pack_start ($vbox, 0, 0, 10);
1607 my $w = Gtk3
::Entry-
>new ();
1608 $w->set_size_request (200, -1);
1610 my $c = Gtk3
::EntryCompletion-
>new ();
1611 $c->set_text_column (0);
1612 $c->set_minimum_key_length(0);
1613 $c->set_popup_set_width (1);
1614 $c->set_inline_completion (1);
1616 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1617 my $label = Gtk3
::Label-
>new ("Time zone");
1618 $label->set_size_request (150, -1);
1619 $label->set_alignment (1, 0.5);
1620 $hbox2->pack_start ($label, 0, 0, 10);
1621 update_zonelist
($hbox2);
1623 my $hbox3 = Gtk3
::HBox-
>new (0, 0);
1624 $label = Gtk3
::Label-
>new ("Keyboard Layout");
1625 $label->set_size_request (150, -1);
1626 $label->set_alignment (1, 0.5);
1627 $hbox3->pack_start ($label, 0, 0, 10);
1629 my $kmapcb = Gtk3
::ComboBoxText-
>new_with_entry ();
1630 $kmapcb->set_size_request (200, -1);
1631 foreach my $layout (sort keys %{$cmap->{kmaphash
}}) {
1632 $kmapcb->append_text ($layout);
1635 update_layout
($kmapcb);
1636 $hbox3->pack_start ($kmapcb, 0, 0, 0);
1638 $kmapcb->signal_connect ('changed' => sub {
1639 my $sel = $kmapcb->get_active_text();
1640 if (my $kmap = $cmap->{kmaphash
}->{$sel}) {
1641 my $xkmap = $cmap->{kmap
}->{$kmap}->{x11
};
1642 my $xvar = $cmap->{kmap
}->{$kmap}->{x11var
};
1643 syscmd
("setxkbmap $xkmap $xvar") if !$opt_testmode;
1648 $w->signal_connect ('changed' => sub {
1649 my ($entry, $event) = @_;
1650 my $text = $entry->get_text;
1652 if (my $cc = $countryhash->{lc($text)}) {
1653 update_zonelist
($hbox2, $cc);
1654 my $kmap = $ctr->{$cc}->{kmap
} || 'en-us';
1655 update_layout
($kmapcb, $kmap);
1659 $w->signal_connect (key_press_event
=> sub {
1660 my ($entry, $event) = @_;
1661 my $text = $entry->get_text;
1663 my $val = $event->get_keyval;
1665 if ($val == Gtk3
::Gdk
::KEY_Tab
) {
1666 my $cc = $countryhash->{lc($text)};
1673 $compl = $ctr->{$cc}->{name
};
1675 foreach my $cc (keys %$ctr) {
1676 my $ct = $ctr->{$cc}->{name
};
1677 if ($ct =~ m/^\Q$text\E.*$/i) {
1686 $entry->set_text($compl);
1691 print chr(7); # beep ?
1696 my $buf = $w->get_buffer();
1697 $buf->insert_text(-1, '', -1); # popup selection
1705 my $ls = Gtk3
::ListStore-
>new('Glib::String');
1706 foreach my $cc (sort {$ctr->{$a}->{name
} cmp $ctr->{$b}->{name
} } keys %$ctr) {
1707 my $iter = $ls->append();
1708 $ls->set ($iter, 0, $ctr->{$cc}->{name
});
1710 $c->set_model ($ls);
1712 $w->set_completion ($c);
1714 my $hbox = Gtk3
::HBox-
>new (0, 0);
1716 $label = Gtk3
::Label-
>new ("Country");
1717 $label->set_alignment (1, 0.5);
1718 $label->set_size_request (150, -1);
1719 $hbox->pack_start ($label, 0, 0, 10);
1720 $hbox->pack_start ($w, 0, 0, 0);
1722 $vbox->pack_start ($hbox, 0, 0, 5);
1723 $vbox->pack_start ($hbox2, 0, 0, 5);
1724 $vbox->pack_start ($hbox3, 0, 0, 5);
1727 $w->set_text ($ctr->{$country}->{name
});
1732 display_html
("country.htm");
1733 set_next
(undef, sub {
1735 my $text = $w->get_text;
1737 if (my $cc = $countryhash->{lc($text)}) {
1739 create_password_view
();
1742 display_message
("Please select a country first.");
1750 sub create_hdsel_view
{
1754 my $vbox = Gtk3
::VBox-
>new (0, 0);
1755 $inbox->pack_start ($vbox, 1, 0, 0);
1756 my $hbox = Gtk3
::HBox-
>new (0, 0);
1757 $vbox->pack_start ($hbox, 0, 0, 10);
1759 my ($disk, $devname, $size, $model) = @{@$hds[0]};
1760 $target_hd = $devname;
1761 $master_hd = find_master
($target_hd);
1764 $label = Gtk3
::Label-
>new ("Target Harddisks: ");
1765 $hbox->pack_start ($label, 0, 0, 0);
1767 my $combo = Gtk3
::ComboBoxText-
>new_with_entry();
1768 my $e = $combo->get_child();
1769 $e->set_width_chars(40);
1771 foreach my $hd (@$hds) {
1772 ($disk, $devname, $size, $model) = @$hd;
1773 $combo->append_text (get_device_desc
($devname, $size, $model));
1776 $combo->set_active (0);
1777 $combo->signal_connect (changed
=> sub {
1778 $a = shift-
>get_active;
1779 my ($disk, $devname) = @{@$hds[$a]};
1780 $target_hd = $devname;
1781 $master_hd = find_master
($target_hd);
1784 $hbox->pack_start ($combo, 0, 0, 0);
1788 display_html
("page1.htm");
1789 set_next
(undef, \
&create_country_view
);
1792 sub create_extract_view
{
1794 $ipaddress = $ip_1->get_text . "." . $ip_2->get_text . "." .
1795 $ip_3->get_text . "." . $ip_4->get_text;
1797 $netmask = $mask_1->get_text . "." . $mask_2->get_text . "." .
1798 $mask_3->get_text . "." . $mask_4->get_text;
1800 $gateway = $gw_1->get_text . "." . $gw_2->get_text . "." .
1801 $gw_3->get_text . "." . $gw_4->get_text;
1803 $dnsserver = $dns_1->get_text . "." . $dns_2->get_text . "." .
1804 $dns_3->get_text . "." . $dns_4->get_text;
1806 # print "TEST $ipaddress $netmask $gateway $dnsserver\n";
1809 display_html
("extract1-license.htm");
1810 $next->set_sensitive (0);
1812 my $vbox = Gtk3
::VBox-
>new (0, 0);
1813 $inbox->pack_start ($vbox, 1, 0, 0);
1814 my $hbox = Gtk3
::HBox-
>new (0, 0);
1815 $vbox->pack_start ($hbox, 0, 0, 10);
1817 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1818 $hbox->pack_start ($vbox2, 0, 0, 0);
1820 $progress_status = Gtk3
::Label-
>new ('');
1821 $vbox2->pack_start ($progress_status, 1, 1, 0);
1823 $progress = Gtk3
::ProgressBar-
>new;
1824 $progress->set_show_text(1);
1825 $progress->set_size_request (600, -1);
1827 $vbox2->pack_start ($progress, 0, 0, 0);
1831 my $tdir = $opt_testmode ?
"target" : "/target";
1833 my $base = $opt_testmode ?
"/pve/$release/install/pve-base.tar" : "/proxmox/pve-base.tar";
1835 eval { extract_data
($base, $tdir); };
1838 $next->set_sensitive (1);
1840 set_next
("_Reboot", sub { exit (0); } );
1843 display_html
("fail.htm");
1844 display_error
($err);
1847 display_html
("success.htm");
1851 sub create_intro_view
{
1855 display_html
("license.htm");
1857 set_next
("I a_gree", \
&create_hdsel_view
);
1860 $ipconf = get_ip_config
();
1862 $country = detect_country
() if $ipconf->{addr
};
1864 # read country, kmap and timezone infos
1865 $cmap = read_cmap
();
1867 create_main_window
();
1869 if (!defined ($hds) || (scalar (@$hds) <= 0)) {
1870 print "no hardisks found\n";
1871 display_html
("nohds.htm");
1872 set_next
("Reboot", sub { exit (0); } );
1875 foreach my $hd (@$hds) {
1876 my ($disk, $devname) = @$hd;
1877 next if $devname =~ m
|^/dev/md\d
+$|;
1878 print "found Disk$disk N:$devname\n";
1881 create_intro_view
();