From 416ab8a37f1b07dc9f6c0fb3ff1a8ff2036510b5 Mon Sep 17 00:00:00 2001 From: Sebastian Schmelzer Date: Thu, 2 Sep 2010 17:50:49 +0200 Subject: change dir structure --- .../plugins/vmware/OpenSLX/Distro/Base.pm | 47 ++ .../plugins/vmware/OpenSLX/Distro/Debian.pm | 227 ++++++ .../plugins/vmware/OpenSLX/Distro/Fedora.pm | 29 + .../plugins/vmware/OpenSLX/Distro/Gentoo.pm | 28 + .../plugins/vmware/OpenSLX/Distro/Suse.pm | 28 + .../plugins/vmware/OpenSLX/Distro/Ubuntu.pm | 23 + .../plugins/vmware/OpenSLX/OSPlugin/vmware.pm | 836 +++++++++++++++++++++ src/os-plugins/plugins/vmware/XX_vmware.sh | 201 +++++ src/os-plugins/plugins/vmware/files/README | 12 + .../plugins/vmware/files/install-vmpl.sh | 284 +++++++ src/os-plugins/plugins/vmware/files/nvram | Bin 0 -> 8664 bytes .../plugins/vmware/files/run-virt.include | 448 +++++++++++ .../init-hooks/20-nw-bridge-config/bridge.sh | 30 + .../init-hooks/60-have-servconfig/vm-dhcpd.sh | 60 ++ .../init-hooks/80-after-plugins/adapt-tmpfs.sh | 24 + 15 files changed, 2277 insertions(+) create mode 100644 src/os-plugins/plugins/vmware/OpenSLX/Distro/Base.pm create mode 100644 src/os-plugins/plugins/vmware/OpenSLX/Distro/Debian.pm create mode 100644 src/os-plugins/plugins/vmware/OpenSLX/Distro/Fedora.pm create mode 100644 src/os-plugins/plugins/vmware/OpenSLX/Distro/Gentoo.pm create mode 100644 src/os-plugins/plugins/vmware/OpenSLX/Distro/Suse.pm create mode 100644 src/os-plugins/plugins/vmware/OpenSLX/Distro/Ubuntu.pm create mode 100644 src/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm create mode 100644 src/os-plugins/plugins/vmware/XX_vmware.sh create mode 100644 src/os-plugins/plugins/vmware/files/README create mode 100644 src/os-plugins/plugins/vmware/files/install-vmpl.sh create mode 100644 src/os-plugins/plugins/vmware/files/nvram create mode 100644 src/os-plugins/plugins/vmware/files/run-virt.include create mode 100755 src/os-plugins/plugins/vmware/init-hooks/20-nw-bridge-config/bridge.sh create mode 100755 src/os-plugins/plugins/vmware/init-hooks/60-have-servconfig/vm-dhcpd.sh create mode 100644 src/os-plugins/plugins/vmware/init-hooks/80-after-plugins/adapt-tmpfs.sh (limited to 'src/os-plugins/plugins/vmware') diff --git a/src/os-plugins/plugins/vmware/OpenSLX/Distro/Base.pm b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Base.pm new file mode 100644 index 00000000..d59227ad --- /dev/null +++ b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Base.pm @@ -0,0 +1,47 @@ +# Copyright (c) 2008 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# vmware/OpenSLX/Distro/Base.pm +# - provides base implementation of the Distro API for the vmware plugin. +# ----------------------------------------------------------------------------- +package vmware::OpenSLX::Distro::Base; + +use strict; +use warnings; + +our $VERSION = 1.01; # API-version . implementation-version + +use Scalar::Util qw( weaken ); + +use OpenSLX::Basics; +use OpenSLX::Utils; + +################################################################################ +### interface methods +################################################################################ +sub new +{ + my $class = shift; + my $self = {}; + return bless $self, $class; + +} + +sub initialize +{ + my $self = shift; + my $engine = shift; + weaken($self->{engine}); + # avoid circular reference between plugin and its engine + + return 1; +} + +1; diff --git a/src/os-plugins/plugins/vmware/OpenSLX/Distro/Debian.pm b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Debian.pm new file mode 100644 index 00000000..fb7b4998 --- /dev/null +++ b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Debian.pm @@ -0,0 +1,227 @@ +# Copyright (c) 2008 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# vmware/OpenSLX/Distro/debian.pm +# - provides Debian-specific overrides of the Distro API for the vmware +# plugin. +# ----------------------------------------------------------------------------- +package vmware::OpenSLX::Distro::Debian; + +use strict; +use warnings; + +use base qw(vmware::OpenSLX::Distro::Base); + +use OpenSLX::Basics; +use OpenSLX::Utils; + +################################################################################ +### interface methods +################################################################################ + +sub fillRunlevelScript +{ + my $self = shift; + my $location = shift; + my $kind = shift; + + my $script = unshiftHereDoc(<<" End-of-Here"); + #!/bin/sh + # Ubuntu/Debian specific start/stop script, generated via stage1 'vmware' + # plugin install + # inspiration taken from vmware start script: + # Copyright 1998-2007 VMware, Inc. All rights reserved. + # + # This script manages the services needed to run VMware software + + # Basic support for the Linux Standard Base Specification 1.3 + ### BEGIN INIT INFO + # Provides: VMware + # Required-Start: \$syslog + # Required-Stop: + # Default-Start: 2 3 5 + # Default-Stop: 0 6 + # Short-Description: Manages the services needed to run VMware software + # Description: Manages the services needed to run VMware software + ### END INIT INFO + + load_modules() { + End-of-Here + + # Load modules + if ($kind eq 'local' || $kind eq 'local25' || $kind eq 'local30') { + if ($kind eq 'local30') { + $script .= unshiftHereDoc(<<" End-of-Here"); + # vmplayer 3.0 specific stuff + insmod /lib/modules/\$(uname -r)/misc/vsock.ko || return 1 + insmod /lib/modules/\$(uname -r)/misc/vmci.ko || return 1 + End-of-Here + } + $script .= unshiftHereDoc(<<" End-of-Here"); + # to be filled in via the stage1 configuration script + insmod /lib/modules/\$(uname -r)/misc/vmmon.ko || return 1 + insmod /lib/modules/\$(uname -r)/misc/vmnet.ko || return 1 + insmod /lib/modules/\$(uname -r)/misc/vmblock.o 2>/dev/null || return 0 + End-of-Here + } elsif ($kind eq 'vmpl1.0') { + $script .= unshiftHereDoc(<<" End-of-Here"); + vmware_kind_path=/opt/openslx/plugin-repo/vmware/${kind}/ + module_src_path=\${vmware_kind_path}/vmroot/modules + insmod \${module_src_path}/vmmon.ko + insmod \${module_src_path}/vmnet.ko + End-of-Here + } elsif ($kind eq "vmpl2.0") { + $script .= unshiftHereDoc(<<" End-of-Here"); + vmware_kind_path=/opt/openslx/plugin-repo/vmware/${kind}/ + module_src_path=\${vmware_kind_path}/vmroot/modules + insmod \${module_src_path}/vmmon.ko + insmod \${module_src_path}/vmnet.ko + insmod \${module_src_path}/vmblock.ko + End-of-Here + } elsif ($kind eq 'vmpl2.5') { + $script .= unshiftHereDoc(<<" End-of-Here"); + vmware_kind_path=/opt/openslx/plugin-repo/vmware/${kind}/ + module_src_path=\${vmware_kind_path}/vmroot/modules + insmod \${module_src_path}/vmmon.ko + insmod \${module_src_path}/vmnet.ko + insmod \${module_src_path}/vmblock.ko + End-of-Here + } elsif ($kind eq 'vmpl3.0') { + $script .= unshiftHereDoc(<<" End-of-Here"); + vmware_kind_path=/opt/openslx/plugin-repo/vmware/${kind}/ + module_src_path=\${vmware_kind_path}/vmroot/modules + insmod \${module_src_path}/vmmon.ko + insmod \${module_src_path}/vmnet.ko + insmod \${module_src_path}/vmblock.ko + insmod \${module_src_path}/vsock.ko + insmod \${module_src_path}/vmci.ko + End-of-Here + } + + # unload modules + $script .= unshiftHereDoc(<<" End-of-Here"); + } + + unload_modules() { + # to be filled with the proper list within via the stage1 + # configuration script + rmmod vmmon vmblock vmnet vmmon vmci vsock 2>/dev/null + } + End-of-Here + + # setup vmnet0 and vmnet8 + # depends on specific stage3 setting. I let this if in the code + # because else this whole if-reducing process will become more + # complicated and the code will get less understandable + $script .= unshiftHereDoc(<<" End-of-Here"); + # the bridged interface + setup_vmnet0() { + if [ -n "\$vmnet0" ] ; then + # the path might be directly point to the plugin dir + End-of-Here + if ($kind eq 'vmpl2.5' || $kind eq 'vmpl3.0' || $kind eq 'local25' || $kind eq 'local30') { + $script .= " $location/vmnet-bridge -d /var/run/vmnet-bridge-0.pid -n 0\n"; + } else { + $script .= " $location/vmnet-bridge -d /var/run/vmnet-bridge-0.pid /dev/vmnet0 eth0\n"; + } + $script .= unshiftHereDoc(<<" End-of-Here"); + fi + } + # we definately prefer the hostonly interface for NATed operation too + # distinction is made via enabled forwarding + setup_vmnet1() { + if [ -n "\$vmnet1" ] ; then + # the path might be directly point to the plugin dir + $location/vmnet-netifup -d /var/run/vmnet-netifup-vmnet1.pid \\ + /dev/vmnet1 vmnet1 + dhcpif="\$dhcpif vmnet1" + ip addr add \$vmnet1 dev vmnet1 + ip link set vmnet1 up + if [ -n "\$vmnet1nat" ] ; then + # needs refinement interface name for eth0 is known in stage3 already + echo "1" > /proc/sys/net/ipv4/conf/vmnet1/forwarding 2>/dev/null + echo "1" > /proc/sys/net/ipv4/conf/eth0/forwarding 2>/dev/null + #iptables -A -s vmnet1 -d eth0 + fi + $location/vmnet-dhcpd -cf /etc/vmware/dhcpd-vmnet1.conf -lf \\ + /var/run/vmware/dhcpd-vmnet1.leases \\ + -pf /var/run/vmnet-dhcpd-vmnet1.pid vmnet1 2>/dev/null # or logfile + fi + } + # incomplete ... + setup_vmnet8() { + if [ -n "\$vmnet8" ] ; then + # we don't need the following test. It's handled by + # XX_vmware.sh + #test -c /dev/vmnet8 || mknod c 119 8 /dev/vmnet8 + $location/vmnet-netifup -d /var/run/vmnet-netifup-vmnet8.pid \\ + /dev/vmnet8 vmnet8 + ip addr add \$vmnet8 dev vmnet8 + ip link set vmnet8 up + # /etc/vmware/vmnet-natd-8.mac simply contains a mac like 00:50:56:F1:30:50 + $location/vmnet-natd -d /var/run/vmnet-natd-8.pid \\ + -m /etc/vmware/vmnet-natd-8.mac -c /etc/vmware/nat.conf 2>/dev/null # or logfile + $location/vmnet-dhcpd -cf /etc/vmware/dhcpd-vmnet8.conf \\ + -lf /var/run/vmware/dhcpd-vmnet8.leases \\ + -pf /var/run/vmnet-dhcpd-vmnet8.pid vmnet8 2>/dev/null # or logfile + fi + } + # initialize the lsb status messages + . /lib/lsb/init-functions + + case \$1 in + start) + log_daemon_msg "Starting vmware background services ..." "vmware" + # include default directories + . /etc/opt/openslx/openslx.conf + # load the configuration file + . \${OPENSLX_DEFAULT_CONFDIR}/plugins/vmware/vmware.conf + mkdir -p /var/run/vmware + touch /var/run/vmware/dhcpd-vmnet1.leases + touch /var/run/vmware/dhcpd-vmnet8.leases + load_modules || log_warning_msg "The loading of vmware modules failed" + setup_vmnet0 || log_warning_msg "Problems setting up vmnet0 interface" + setup_vmnet1 || log_warning_msg "Problems setting up vmnet1 interface" + setup_vmnet8 || log_warning_msg "Problems setting up vmnet8 interface" + log_end_msg $? + ;; + stop) + # message output should match the given vendor-os + log_daemon_msg "Stopping vmware background services ..." "vmware" + killall vmnet-netifup vmnet-natd vmnet-bridge vmware vmplayer \\ + vmware-tray vmnet-dhcpd 2>/dev/null + # wait for shutting down of interfaces. vmnet needs kinda + # long + sleep 1 + unload_modules + log_end_msg $? + ;; + # we don't need a status yet... at least as long as it is + # unclear in which path the corresponding binary (see original + # /etc/init.d/vmware) is in our case + #status) + # log_daemon_msg "Say something useful here ..." + #;; + restart) + \$0 stop + \$0 start + exit $? + ;; + *) + log_success_msg "Usage: \$0 {start|stop|restart}" + exit 2 + ;; + esac + exit 0 + End-of-Here + return $script; +} + +1; diff --git a/src/os-plugins/plugins/vmware/OpenSLX/Distro/Fedora.pm b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Fedora.pm new file mode 100644 index 00000000..912bdfa0 --- /dev/null +++ b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Fedora.pm @@ -0,0 +1,29 @@ +# Copyright (c) 2007..2010 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# vmware/OpenSLX/Distro/Fedora.pm +# - provides Fedora-specific overrides of the Distro API for the vmware +# plugin. +# ----------------------------------------------------------------------------- +package vmware::OpenSLX::Distro::Fedora; + +use strict; +use warnings; + +use base qw(vmware::OpenSLX::Distro::Base); + +use OpenSLX::Basics; + +################################################################################ +### interface methods +################################################################################ + + +1; diff --git a/src/os-plugins/plugins/vmware/OpenSLX/Distro/Gentoo.pm b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Gentoo.pm new file mode 100644 index 00000000..2e1197d8 --- /dev/null +++ b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Gentoo.pm @@ -0,0 +1,28 @@ +# Copyright (c) 2008 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# vmware/OpenSLX/Distro/Gentoo.pm +# - provides Gentoo-specific overrides of the Distro API for the vmware +# plugin. +# ----------------------------------------------------------------------------- +package vmware::OpenSLX::Distro::Gentoo; + +use strict; +use warnings; + +use base qw(vmware::OpenSLX::Distro::Base); + +use OpenSLX::Basics; + +################################################################################ +### interface methods +################################################################################ + +1; diff --git a/src/os-plugins/plugins/vmware/OpenSLX/Distro/Suse.pm b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Suse.pm new file mode 100644 index 00000000..c1b2ecf4 --- /dev/null +++ b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Suse.pm @@ -0,0 +1,28 @@ +# Copyright (c) 2008..2010 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# vmware/OpenSLX/Distro/Suse.pm +# - provides SUSE-specific overrides of the Distro API for the vmware plugin. +# ----------------------------------------------------------------------------- +package vmware::OpenSLX::Distro::Suse; + +use strict; +use warnings; + +use base qw(vmware::OpenSLX::Distro::Base); + +use OpenSLX::Basics; +use OpenSLX::Utils; + +################################################################################ +### interface methods +################################################################################ + +1; diff --git a/src/os-plugins/plugins/vmware/OpenSLX/Distro/Ubuntu.pm b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Ubuntu.pm new file mode 100644 index 00000000..922fb34f --- /dev/null +++ b/src/os-plugins/plugins/vmware/OpenSLX/Distro/Ubuntu.pm @@ -0,0 +1,23 @@ +# Copyright (c) 2007..2010 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# vmware/OpenSLX/Distro/Ubuntu.pm +# - provides Ubuntu-specific overrides of the Distro API for the vmware +# plugin. +# ----------------------------------------------------------------------------- +package vmware::OpenSLX::Distro::Ubuntu; + +use strict; +use warnings; + +# inherit everything from Debian (as Ubuntu is based on it anyway) +use base qw(vmware::OpenSLX::Distro::Debian); + +1; diff --git a/src/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm b/src/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm new file mode 100644 index 00000000..7e55019c --- /dev/null +++ b/src/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm @@ -0,0 +1,836 @@ +# Copyright (c) 2008..2010 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# vmware.pm +# - declares necessary information for the vmware plugin +# ----------------------------------------------------------------------------- +package OpenSLX::OSPlugin::vmware; + +use strict; +use warnings; + +use base qw(OpenSLX::OSPlugin::Base); + +use File::Basename; +use File::Path; + +use OpenSLX::Basics; +use OpenSLX::Utils; +use OpenSLX::DistroUtils; + +sub new +{ + my $class = shift; + + my $self = { + name => 'vmware', + }; + + return bless $self, $class; +} + +sub getInfo +{ + my $self = shift; + + return { + description => unshiftHereDoc(<<' End-of-Here'), + Module for enabling services of VMware Inc. on an OpenSLX stateless + client. This plugin might use pre-existing installations of VMware + tools or install addional variants and versions. + End-of-Here + precedence => 70, + required => [ qw( desktop ) ], + }; +} + +sub getAttrInfo +{ + # returns a hash-ref with information about all attributes supported + # by this specific plugin + my $self = shift; + + # This default configuration will be added as attributes to the default + # system, such that it can be overruled for any specific system by means + # of slxconfig. + return { + # attribute 'active' is mandatory for all plugins + 'vmware::active' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + should the 'vmware'-plugin be executed during boot? + End-of-Here + content_regex => qr{^(0|1)$}, + content_descr => '1 means active - 0 means inactive', + default => '1', + }, + # attribute 'imagesrc' defines where we can find vmware images + 'vmware::imagesrc' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + Where do we store our vmware images? NFS? Filesystem? + End-of-Here + #TODO: check if the input is valid + #content_regex => qr{^(0|1)$}, + content_descr => 'Allowed values: path or URI', + default => '', + }, + # attribute 'bridge' defines if bridged network mode should be + # switched on + 'vmware::bridge' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + Should the bridging (direct access of the vmware clients + to the ethernet the host is connected to) be enabled + End-of-Here + content_regex => qr{^(0|1)$}, + content_descr => 'Allowed values: 0 or 1', + default => '1', + }, + # attribute 'vmnet1' defines if the host connection network mode + # should be switched on and NAT should be enabled + 'vmware::vmnet1' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + Format ServerIP/Netprefix without NAT + Format ServerIP/Netprefix,NAT enables NAT/Masquerading + End-of-Here + #TODO: check if the input is valid + #content_regex => qr{^(0|1)$}, + content_descr => 'Allowed value: IP/Prefix[,NAT]', + default => '192.168.101.1/24,NAT', + }, + # attribute 'vmnet8' defines if vmware specific NATed network mode + # should be switched on + 'vmware::vmnet8' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + Format ServerIP/Netprefix. Last octet will be omitted + End-of-Here + #TODO: check if the input is valid + #content_regex => qr{^(0|1)$}, + content_descr => 'Allowed value: IP/Prefix. Last octet will be omitted', + default => '192.168.102.x/24', + }, + # attribute 'kind' defines which set of VMware binaries should be + # activated ('local' provided with the main installation set). + 'vmware::kind' => { + applies_to_vendor_os => 0, + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + Which set of VMware binaries to use: installed (local) or provided by the + plugin itself (vmpl1.0, vmpl2.0, vmpl2.5, vmpl3.X)? + End-of-Here + # only allow the supported once... + # TODO: modify if we know which of them work + #content_regex => qr{^(local|vmws(5\.5|6.0)|vmpl(1\.0|2\.0))$}, + content_regex => qr{^(local|vmpl3\.0||vmpl2\.0|vmpl1\.0|vmpl2\.5)$}, + content_descr => 'Allowed values: local, vmpl2.0', + #TODO: what if we don't have a local installation. default + # is still local. Someone has a clue how to test + # it and change the default value? + default => 'local', + }, + ## + ## only stage1 setup options: different kinds to setup + 'vmware::local' => { + applies_to_vendor_os => 1, + applies_to_system => 0, + applies_to_clients => 0, + description => unshiftHereDoc(<<' End-of-Here'), + Set's up stage1 configuration for a local installed + vmplayer or vmware workstation + End-of-Here + content_regex => qr{^(1|0)$}, + content_descr => '1 means active - 0 means inactive', + default => '1', + }, + 'vmware::vmpl2.0' => { + applies_to_vendor_os => 1, + applies_to_system => 0, + applies_to_clients => 0, + description => unshiftHereDoc(<<' End-of-Here'), + Install and configure vmplayer v2 + End-of-Here + content_regex => qr{^(1|0)$}, + content_descr => '1 means active - 0 means inactive', + default => '0', + }, + 'vmware::vmpl2.5' => { + applies_to_vendor_os => 1, + applies_to_system => 0, + applies_to_clients => 0, + description => unshiftHereDoc(<<' End-of-Here'), + Install and configure vmplayer v2 + End-of-Here + content_regex => qr{^(1|0)$}, + content_descr => '1 means active - 0 means inactive', + default => '0', + }, + 'vmware::vmpl1.0' => { + applies_to_vendor_os => 1, + applies_to_system => 0, + applies_to_clients => 0, + description => unshiftHereDoc(<<' End-of-Here'), + Install and configure vmplayer v1 + End-of-Here + content_regex => qr{^(1|0)$}, + content_descr => '1 means active - 0 means inactive', + default => '0', + }, + 'vmware::pkgpath' => { + applies_to_vendor_os => 1, + applies_to_system => 0, + applies_to_clients => 0, + description => unshiftHereDoc(<<' End-of-Here'), + Path to VMware packages + End-of-Here + #TODO + #content_regex => qr{^(1|0)$}, + content_descr => '1 means active - 0 means inactive', + default => '/root/vmware-pkgs', + }, + # ** set of attributes for the installation of VM Workstation/Player + # versions. More than one package could be installed in parallel. + # To be matched to/triggerd by 'vmware::kind' + }; +} + + +sub preInstallationPhase() +{ + my $self = shift; + my $info = shift; + + $self->{pluginRepositoryPath} = $info->{'plugin-repo-path'}; + $self->{pluginTempPath} = $info->{'plugin-temp-path'}; + $self->{openslxBasePath} = $info->{'openslx-base-path'}; + $self->{openslxConfigPath} = $info->{'openslx-config-path'}; + $self->{attrs} = $info->{'plugin-attrs'}; + $self->{vendorOsPath} = $info->{'vendor-os-path'}; + + my $pkgpath = $self->{attrs}->{'vmware::pkgpath'}; + my $vmpl10 = $self->{attrs}->{'vmware::vmpl1.0'}; + my $vmpl20 = $self->{attrs}->{'vmware::vmpl2.0'}; + my $vmpl25 = $self->{attrs}->{'vmware::vmpl2.5'}; + my $local = $self->{attrs}->{'vmware::local'}; + + if ($local == 0 && $vmpl10 == 0 && $vmpl20 == 0 && $vmpl25 == 0) { + print "\n\n * At least one kind needs to get installed/activated:\n"; + print " vmware::local=1 or\n"; + print " vmware::vmpl1.0=1 or\n"; + print " vmware::vmpl2.0=1\n"; + print " vmware::vmpl2.5=1\n"; + print " * vmware plugin was not installed!\n\n"; + exit 1; + } + + if (! -d $pkgpath && ($vmpl10 == 1 || $vmpl20 == 1 || $vmpl25 == 1)) { + print "\n\n * vmware::pkgpath: no such directory $pkgpath!\n"; + print " See wiki about vmware Plugin\n"; + print " * vmware plugin was not installed!\n\n"; + exit 1; + } + + # test just for the case we only set up local vmware + if (-d $pkgpath && ($vmpl10 == 1 || $vmpl20 == 1 || $vmpl25 == 1)) { + # todo: ask oliver about a similiar function + # like copyFile() just for directorys + # or fix the manual after checked the source of + # copyFile() function. check if copyFile etc. perldoc + # is somewhere in the wiki documented else do it! + system("cp -r $pkgpath $self->{pluginRepositoryPath}/packages"); + } +} + +sub installationPhase +{ + my $self = shift; + my $info = shift; + + $self->{pluginRepositoryPath} = $info->{'plugin-repo-path'}; + $self->{pluginTempPath} = $info->{'plugin-temp-path'}; + $self->{openslxBasePath} = $info->{'openslx-base-path'}; + $self->{openslxConfigPath} = $info->{'openslx-config-path'}; + $self->{attrs} = $info->{'plugin-attrs'}; + + # copy common part of run-virt.include to the appropriate place for + # inclusion in stage4 + copyFile("$self->{openslxBasePath}/lib/plugins/vmware/files/run-virt.include", + "$self->{pluginRepositoryPath}/"); + + # kinds we will configure and install + # TODO: write a list of installed/setted up and check it in stage3 + # this will avoid conflict of configured vmware version in + # stage3 which are not setted up or installed in stage1 + if ($self->{attrs}->{'vmware::local'} == 1) { + $self->_localInstallation(); + } + if ($self->{attrs}->{'vmware::vmpl2.0'} == 1) { + $self->_vmpl2Installation(); + } + if ($self->{attrs}->{'vmware::vmpl1.0'} == 1) { + $self->_vmpl1Installation(); + } + if ($self->{attrs}->{'vmware::vmpl2.5'} == 1) { + $self->_vmpl25Installation(); + } + + ## prepration for our faster wrapper script + # rename the default vmplayer script and create a link. + # uninstall routine takes care about plugin remove. + # stage3 copys our own wrapper script + if (-e "/usr/bin/vmplayer" && ! -e "/usr/bin/vmplayer.slx-back") { + rename("/usr/bin/vmplayer", "/usr/bin/vmplayer.slx-bak"); + } + # the same with vmware, if ws is installed + if (-e "/usr/bin/vmware" && ! -e "/usr/bin/vmware.slx-bak") { + rename("/usr/bin/vmware", "/usr/bin/vmware.slx-bak"); + } + +} + +sub removalPhase +{ + my $self = shift; + my $info = shift; + + # restore old start scripts - to be discussed + my @files = qw( vmware vmplayer ); + foreach my $file (@files) { + if (-e "/usr/bin/$file.slx-bak") { + unlink("/usr/bin/$file"); + rename("/usr/bin/$file.slx-bak", "/usr/bin/$file"); + } + } + return; +} + +sub checkStage3AttrValues +{ + my $self = shift; + my $stage3Attrs = shift; + my $vendorOSAttrs = shift; + my @problems; + + my $vm_kind = $stage3Attrs->{'vmware::kind'} || ''; + my $vmimg = $stage3Attrs->{'vmware::imagesrc'} || ''; + + if ($vm_kind eq 'local' && ! -x "/usr/lib/vmware/bin/vmplayer") { + push @problems, _tr( + "No local executeable installation of vmware found! Using it as virtual machine wouldn't work!" + ); + } + + if ($vm_kind eq 'local' && + ! -d "/opt/openslx/plugin-repo/vmware/local") { + push @problems, _tr( + "local vmware installation not configured by slxos-plugin!" + ); + } + + if ($vm_kind eq 'vmpl1.0' && + ! -d "/opt/openslx/plugin-repo/vmware/vmpl1.0/vmroot") { + push @problems, _tr( + "No OpenSLX installation of VMware Player 1 found or installation failed. Using it as virtual machine wouldn't work!" + ); + } + + if ($vm_kind eq 'vmpl2.0' && + ! -d "/opt/openslx/plugin-repo/vmware/vmpl2.0/vmroot") { + push @problems, _tr( + "No OpenSLX installation of VMware Player 2.0 found or installation failed. Using it as virtual machine wouldn't work!" + ); + } + + if ($vm_kind eq 'vmpl2.5' && + ! -d "/opt/openslx/plugin-repo/vmware/vmpl2.5/vmroot") { + push @problems, _tr( + "No OpenSLX installation of VMware Player 2.5 found or installation failed. Using it as virtual machine wouldn't work!" + ); + } + + if ($vm_kind eq 'vmpl3.X' && + ! -d "/opt/openslx/plugin-repo/vmware/vmpl3.X/vmroot") { + push @problems, _tr( + "No OpenSLX installation of VMware Player 3.X found or installation failed. Using it as virtual machine wouldn't work!" + ); + } + + return if !@problems; + + return \@problems; +} + + +####################################### +## local, non-general OpenSLX functions +####################################### + +# Write the runlevelscript +# usage: _writeRunlevelScript("$vmpath", "$kind") +sub _writeRunlevelScript +{ + my $self = shift; + my $vmpath = shift; + my $kind = shift; + my $initfile = newInitFile(); + + my $script = ""; + my $modpath = ""; + my $modlist = ""; + # vmpath is to be redefined here ... + if ($kind =~ /local*/) { + $vmpath = ""; + $modpath = "/lib/modules/\$(uname -r)/misc"; + } elsif ($kind =~ /vmpl*/) { + $vmpath = "/opt/openslx/plugin-repo/vmware/${kind}"; + $modpath = "${vmpath}/vmroot/modules"; + } + + $initfile->setName("vmware-slx"); + $initfile->setDesc("Setup environment for VMware Workstation or Player ($kind)."); + + # functions ... + $modlist = "vmnet vmmon"; + $script = unshiftHereDoc(<<" End-of-Here"); + # VMplayer common stuff + insmod ${modpath}/vmmon.ko || return 1 + insmod ${modpath}/vmnet.ko || return 1 + End-of-Here + if ($kind eq 'local3X' || $kind eq 'vmpl3.X') { + $script .= unshiftHereDoc(<<" End-of-Here"); + # VMplayer 3.X specific stuff + insmod ${modpath}/vmci.ko + insmod ${modpath}/vmblock.ko + insmod ${modpath}/vsock.ko + End-of-Here + $modlist .= "vsock vmci vmblock"; + } elsif ($kind eq 'local20' || $kind eq 'local25' || $kind eq 'vmpl2.0' || $kind eq 'vmpl2.5') { + $script .= unshiftHereDoc(<<" End-of-Here"); + # VMplayer 2.X specific stuff + insmod ${modpath}/vmblock.ko + End-of-Here + $modlist .= "vmblock"; + } + $initfile->addFunction( + "load_modules", + "$script" + ); + $initfile->addFunction( + "unload_modules", + "rmmod $modlist 2>/dev/null" + ); + # vmnet0,1,8 (bridge, nat, host-only) interface definition + $script = unshiftHereDoc(<<" End-of-Here"); + # let point the path directly to the directory where the binary lives + location="$vmpath/usr/bin" + if [ -n "\$vmnet0" ] ; then + # the path might be directly point to the plugin dir + End-of-Here + if ($kind eq 'vmpl1.0' || $kind eq 'vmpl2.0' || $kind eq 'local10' || $kind eq 'local20') { + $script .= " \$location/vmnet-bridge -d /var/run/vmnet-bridge-0.pid /dev/vmnet0 eth0\n"; + } else { + $script .= " \$location/vmnet-bridge -d /var/run/vmnet-bridge-0.pid -n 0\n"; + } + $script .= unshiftHereDoc(<<" End-of-Here"); + fi + if [ -n "\$vmnet1" ] ; then + \$location/vmnet-netifup -d /var/run/vmnet-netifup-vmnet1.pid \\ + /dev/vmnet1 vmnet1 + ip addr add \$vmnet1 dev vmnet1 + ip link set vmnet1 up + if [ -n "\$vmnet1nat" ] ; then + echo "1" >/proc/sys/net/ipv4/conf/vmnet1/forwarding 2>/dev/null + echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding 2>/dev/null + #iptables -A -s vmnet1 -d br0 + fi + /opt/openslx/uclib-rootfs/usr/sbin/udhcpd \\ + -S /etc/vmware/udhcpd/udhcpd-vmnet1.conf + fi + if [ -n "\$vmnet8" ] ; then + \$location/vmnet-netifup -d /var/run/vmnet-netifup-vmnet8.pid \\ + /dev/vmnet8 vmnet8 + ip addr add \$vmnet8 dev vmnet8 + ip link set vmnet8 up + echo "1" >/proc/sys/net/ipv4/conf/vmnet8/forwarding 2>/dev/null + echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding 2>/dev/null + iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE + /opt/openslx/uclib-rootfs/usr/sbin/udhcpd \\ + -S /etc/vmware/udhcpd/udhcpd-vmnet8.conf + fi + End-of-Here + $initfile->addFunction( + "vmnetif", + "$script" + ); + # vmblock for handling e.g. removable USB devices + $script = unshiftHereDoc(<<" End-of-Here"); + # let point the path directly to the directory where the binary lives + $vmpath/usr/bin/vmware-usbarbitrator + End-of-Here + $initfile->addFunction( + "vmblock", + "$script" + ); + $script = unshiftHereDoc(<<" End-of-Here"); + # include default directories + . /etc/opt/openslx/openslx.conf + # load the configuration file + . \${OPENSLX_DEFAULT_CONFDIR}/plugins/vmware/vmware.conf + # hack to access the first serial/parallel port + chmod a+rw /dev/ttyS0 + chmod a+rw /dev/parport0 + load_modules + vmnetif + End-of-Here + # start the USB arbitrator on higher VMware/player versions (3.0+) + if ($kind eq 'vmpl3.X' || $kind eq 'local3X') { + $script .= unshiftHereDoc(<<" End-of-Here"); + vmblock + End-of-Here + } + $initfile->addToCase( + "start", + "$script" + ); + $script = unshiftHereDoc(<<" End-of-Here"); + killall vmnet-netifup vmnet-natd vmnet-bridge vmware vmplayer \\ + vmware-tray vmnet-dhcpd 2>/dev/null + # might take a while until all services are shut down + sleep 1 + unload_modules + End-of-Here + $initfile->addToCase( + "stop", + "$script" + ); + $initfile->addToCase( + "status", + "vmstatus" + ); + $initfile->addToCase( + "restart", + "\$0 stop && \$0 start" + ); + + my $distro = (split('-',$self->{'os-plugin-engine'}->distroName()))[0]; + my $runlevelscript = getInitFileForDistro($initfile, $distro); + # todo: because we dont have distribution or version dependend + # init scripts we could put it directly into /etc/init.d... + spitFile("$self->{'pluginRepositoryPath'}/vmware-slx", $runlevelscript); +} + + +# writes the wrapper script for vmware workstation and player, depending +# on the flag. If player: just player wrapper, if ws: ws+player wrapper +# usage: _writeWrapperScript("$vmpath", "$kind", "player") +# _writeWrapperScript("$vmpath", "$kind", "ws") +sub _writeWrapperScript +{ + my $self = shift; + my $vmpath = shift; + my $kind = shift; + my $type = shift; + my @files; + + if ("$type" eq "ws") { + @files = qw(vmware vmplayer); + } else { + @files = qw(vmplayer); + } + + foreach my $file (@files) { + # create our own simplified version of the vmware and player wrapper + # Depending on the configured kind it will be copied in stage3 + # because of tempfs of /var but not /usr we link the file + # to /var/..., where we can write in stage3 + my $script = unshiftHereDoc(<<" End-of-Here"); + #!/bin/sh + # written by OpenSLX-plugin 'vmware' in Stage1 + # radically simplified version of the original script $file by VMware Inc. + End-of-Here + + # kinda ugly and we only need it for local. Preserves errors + if ($kind ne "local") { + $script .= unshiftHereDoc(<<" End-of-Here"); + export LD_LIBRARY_PATH=$vmpath/lib + export GDK_PIXBUF_MODULE_FILE=$vmpath/libconf/etc/gtk-2.0/gdk-pixbuf.loaders + export GTK_IM_MODULE_FILE=$vmpath/libconf/etc/gtk-2.0/gtk.immodules + export FONTCONFIG_PATH=$vmpath/libconf/etc/fonts + export PANGO_RC_FILE=$vmpath/libconf/etc/pango/pangorc + # possible needed... but what are they good for? + #export GTK_DATA_PREFIX= + #export GTK_EXE_PREFIX= + #export GTK_PATH= + End-of-Here + } + + $script .= unshiftHereDoc(<<" End-of-Here"); + PREFIX=$vmpath # depends on the vmware location + exec "\$PREFIX"'/lib/wrapper-gtk24.sh' \\ + "\$PREFIX"'/lib' \\ + "\$PREFIX"'/bin/$file' \\ + "\$PREFIX"'/libconf' "\$@" + End-of-Here + + # TODO: check if these will be overwritten if we have more as + # local defined (add the version/type like vmpl1.0, vmws5.5, ...) + # then we have a lot of files easily distinguishable by there suffix + spitFile("$self->{'pluginRepositoryPath'}/$kind/$file", $script); + chmod 0755, "$self->{'pluginRepositoryPath'}/$kind/$file"; + } +} + +sub _writeVmwareConfigs { + my $self = shift; + my $kind = shift; + my $vmpath = shift; + my %versionhash = (vmversion => "", vmbuildversion => ""); + my $vmversion = ""; + my $vmbuildversion = ""; + my $config = ""; + + %versionhash = _getVersion($vmpath); + + $config .= "version=\"".$versionhash{vmversion}."\"\n"; + $config .= "buildversion=\"".$versionhash{vmbuildversion}."\"\n"; + spitFile("$self->{'pluginRepositoryPath'}/$kind/vmware.conf", $config); + chmod 0755, "$self->{'pluginRepositoryPath'}/$kind/vmware.conf"; + + $config = "libdir = \"$vmpath\"\n"; + spitFile("$self->{'pluginRepositoryPath'}/$kind/config", $config); + chmod 0755, "$self->{'pluginRepositoryPath'}/$kind/config"; +} + +sub _getVersion { + + my $vmpath = shift; + my $vmversion = ""; + my $vmbuildversion = ""; + my %versioninfo = (vmversion => "", vmbuildversion => ""); + + # get version information about installed vmplayer + if (open(FH, "$vmpath/bin/vmplayer")) { + $/ = undef; + my $data = ; + close FH; + # depending on the installation it could differ and has multiple build + # strings + if ($data =~ m{[^\d\.](\d\.\d) build-(\d+)}) { + $vmversion = $1; + $vmbuildversion = $2; + } + if ($data =~ m{\0(2\.[05])\.[0-9]}) { + $vmversion = $1; + } + # else { TODO: errorhandling if file or string doesn't exist } + chomp($vmversion); + chomp($vmbuildversion); + + + $versioninfo{vmversion} = $vmversion; + $versioninfo{vmbuildversion} = $vmbuildversion; + } + return %versioninfo; +} + +######################################################################## +## Functions, which setup the different environments (local, ws-v(5.5|6), +## player-v(1|2) +## Seperation makes this file more readable. Has a bigger benefit as +## one big copy function. Makes integration of new versions easier. +######################################################################## + +# local installation +sub _localInstallation +{ + my $self = shift; + + my $kind = "local"; + my $vmpath = "/usr/lib/vmware"; + my $vmbin = "/usr/bin"; + my %versionhash = (vmversion => "", vmbuildversion => ""); + my $vmversion = ""; + my $vmbuildversion = ""; + + # if vmware ws is installed, vmplayer is installed, too. + # we will only use vmplayer + if (-e "/usr/lib/vmware/bin/vmplayer") { + + ## Get and write version information + %versionhash = _getVersion($vmpath); + $vmversion = $versionhash{vmversion}; + $vmbuildversion = $versionhash{vmbuildversion}; + + # set version information + # VMplayer 2.0 + if ($vmversion eq "2.0" || $vmversion eq "6.0") { + $kind="local20"; + # VMplayer 2.5 + } elsif ($vmversion eq "2.5" || $vmversion eq "6.5") { + $kind="local25"; + # VMplayer 3.0, 3.1, Workstation 7.0, 7.1 + } elsif ($vmversion eq "3.0" || $vmversion eq "7.0" || + $vmversion eq "3.1" || $vmversion eq "7.1") { $kind="local3X"; + } + # Create runlevel script depending on detected version + $self->_writeRunlevelScript("$vmpath", "$kind"); + + # Create wrapper scripts, kind of localNN is set to local + if ( $kind =~ /local*/ ) { $kind = "local"; } + if (-e "/usr/lib/vmware/bin/vmware") { + $self->_writeWrapperScript("$vmpath", "$kind", "ws"); + } + if (-e "/usr/lib/vmware/bin/vmplayer") { + $self->_writeWrapperScript("$vmpath", "$kind", "player"); + } + + # copy nvram file + my $pluginFilesPath + = "$self->{'openslxBasePath'}/lib/plugins/$self->{'name'}/files"; + my @files = qw(nvram); + foreach my $file (@files) { + copyFile("$pluginFilesPath/$file", "$self->{'pluginRepositoryPath'}/$kind"); + } + + } # else { TODO: errorhandling if file or string doesn't exist } + + ## creating needed config /etc/vmware/config + $self->_writeVmwareConfigs("$kind", "$vmpath"); +} + +sub _vmpl2Installation { + my $self = shift; + + my $kind = "vmpl2.0"; + my $vmpath = "/opt/openslx/plugin-repo/vmware/$kind/vmroot/lib/vmware"; + my $vmbin = "/opt/openslx/plugin-repo/vmware/$kind/vmroot/bin"; + + my $pluginFilesPath + = "$self->{'openslxBasePath'}/lib/plugins/$self->{'name'}/files"; + my $installationPath = "$self->{'pluginRepositoryPath'}/$kind"; + + mkpath($installationPath); + + ## + ## Copy needed files + + # copy 'normal' needed files + my @files = qw( nvram install-vmpl.sh ); + foreach my $file (@files) { + copyFile("$pluginFilesPath/$file", "$installationPath"); + } + + # Install the binarys from given pkgpath + system("/bin/sh /opt/openslx/plugin-repo/$self->{'name'}/$kind/install-vmpl.sh $kind"); + + # Create runlevel script + $self->_writeRunlevelScript($vmpath, $kind); + + # Create wrapperscripts + $self->_writeWrapperScript("$vmpath", "$kind", "player"); + + # Creating needed config /etc/vmware/config + $self->_writeVmwareConfigs("$kind", "$vmpath"); + +} + +sub _vmpl25Installation { + my $self = shift; + + my $kind = "vmpl2.5"; + my $vmpath = "/opt/openslx/plugin-repo/vmware/$kind/vmroot/lib/vmware"; + my $vmbin = "/opt/openslx/plugin-repo/vmware/$kind/vmroot/bin"; + my $vmversion = "6.5"; + my $vmbuildversion = "TODO_we_need_it_for_enhanced_runvmware_config_in_stage1"; + + my $pluginFilesPath + = "$self->{'openslxBasePath'}/lib/plugins/$self->{'name'}/files"; + my $installationPath = "$self->{'pluginRepositoryPath'}/$kind"; + + mkpath($installationPath); + + # copy 'normal' needed files + my @files = qw( nvram install-vmpl.sh ); + foreach my $file (@files) { + copyFile("$pluginFilesPath/$file", "$installationPath"); + } + + # Install the binarys from given pkgpath + system("/bin/sh /opt/openslx/plugin-repo/$self->{'name'}/$kind/install-vmpl.sh $kind"); + + # Create runlevel script + $self->_writeRunlevelScript($vmpath, $kind); + + # Create wrapperscripts + $self->_writeWrapperScript("$vmpath", "$kind", "player"); + + # Creating needed config /etc/vmware/config + $self->_writeVmwareConfigs("$kind", "$vmpath"); + +} + +sub _vmpl1Installation { + my $self = shift; + + my $kind = "vmpl1.0"; + my $vmpath = "/opt/openslx/plugin-repo/vmware/$kind/vmroot/lib/vmware"; + my $vmbin = "/opt/openslx/plugin-repo/vmware/$kind/vmroot/bin"; + my $vmversion = "5.5"; + my $vmbuildversion = "TODO_we_need_it_for_enhanced_runvmware_config_in_stage1"; + + my $pluginFilesPath + = "$self->{'openslxBasePath'}/lib/plugins/$self->{'name'}/files"; + my $installationPath = "$self->{'pluginRepositoryPath'}/$kind"; + + mkpath($installationPath); + + # copy 'normal' needed files + my @files = qw( nvram install-vmpl.sh ); + foreach my $file (@files) { + copyFile("$pluginFilesPath/$file", "$installationPath"); + } + + # Download and install the binarys + system("/bin/sh /opt/openslx/plugin-repo/$self->{'name'}/$kind/install-vmpl.sh $kind"); + + # Create runlevel script + $self->_writeRunlevelScript($vmpath, $kind); + + # create wrapper scripts + $self->_writeWrapperScript("$vmpath", "$kind", "player"); + + # creating needed config /etc/vmware/config + $self->_writeVmwareConfigs("$kind", "$vmpath"); + +} + +# The bridge configuration needs the bridge module to be present in early +# stage3 +sub suggestAdditionalKernelModules +{ + my $self = shift; + my $makeInitRamFSEngine = shift; + + my @suggestedModules; + + push @suggestedModules, qw( bridge ); + + return @suggestedModules; +} + +1; diff --git a/src/os-plugins/plugins/vmware/XX_vmware.sh b/src/os-plugins/plugins/vmware/XX_vmware.sh new file mode 100644 index 00000000..26b49cc5 --- /dev/null +++ b/src/os-plugins/plugins/vmware/XX_vmware.sh @@ -0,0 +1,201 @@ +# Copyright (c) 2007..2009 - RZ Uni Freiburg +# Copyright (c) 2008..2010 - OpenSLX GmbH +# +# This program/file is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your feedback to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org +# +# script is included from init via the "." load function - thus it has all +# variables and functions available + +# TODO: +# configs nach /etc/opt/openslx/plugins/vmware +# cp nach run-virt.include + +# TODO: nvram,functions +# write /etc/vmware/config (if a non-standard location of vmware basedir is +# to be configured), /etc/init.d/vmware + +# include default directories +. /etc/openslx.conf + +ETCDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR} +PLUGINCONFDIR=${ETCDIR}/plugins/vmware +BINDIR=/mnt/${OPENSLX_DEFAULT_BINDIR} +PLUGINDIR=/mnt/${OPENSLX_DEFAULT_DIR}/plugin-repo/vmware +VIRTDIR=/mnt/${OPENSLX_DEFAULT_VIRTDIR} + +# check if the configuration file is available +if [ -e /initramfs/plugin-conf/vmware.conf ]; then + + # load needed variables + . /initramfs/plugin-conf/vmware.conf + + # Test if this plugin is activated... more or less useless with the + # new plugin system + if [ $vmware_active -ne 0 ]; then + + [ $DEBUGLEVEL -gt 0 ] && echo "executing the 'vmware' os-plugin ..."; + # Load general configuration + . /initramfs/machine-setup + + testmkd /mnt/tmp/vmware 1777 + testmkd /dev/shm/vmware 1777 + testmkd /mnt/var/run/vmware 1777 + testmkd ${PLUGINCONFDIR} + testmkd /mnt/etc/vmware/udhcpd + + # write the ${PLUGINCONFDIR}/vmware.conf file + # check for the several variables and write the several files: + # dhcpd.conf for vmnet* interfaces + # nat.conf for the NAT configuration of vmnet8 + # TODO: vmnet-natd-8.mac not clear if really needed and which mac it + # should contain (seems to be an average one) + echo -e "# configuration file for vmware background services written in \ +stage3 setup" > ${PLUGINCONFDIR}/vmware.conf + if [ "$vmware_bridge" = 1 ] ; then + echo "vmnet0=true" >> ${PLUGINCONFDIR}/vmware.conf + fi + + # variable might contain ",NAT" which is to be taken off + if [ -n "$vmware_vmnet1" ] ; then + local vmnet1=${vmware_vmnet1%,*} # x.x.x.x/yy,NAT => 'x.x.x.x/yy' + local vmnat=${vmware_vmnet1#$vmnet1*} # x.x.x.x/yy,NAT => ',NAT' + local vmip=${vmnet1%/*} # x.x.x.x/yy => 'x.x.x.x'"> + local vmpx=${vmnet1#*/} # x.x.x.x/yy => 'yy' + local vmsub=$(echo $vmip |sed 's,\(.*\)\..*,\1,') # x.x.x.x => x.x.x + echo -e "vmnet1=$vmnet1" >> ${PLUGINCONFDIR}/vmware.conf + [ -n "$vmnat" ] && echo "vmnet1nat=true" >> ${PLUGINCONFDIR}/vmware.conf + # setting up the udhcpd configuration + sed -e "s,NWIF,vmnet1,;s,/misc/,/vmware/," \ + -e "s,CNETWORK,$vmsub,;s,PIDFILE,/var/run/vmware/udhcpd-vmnet1.pid," \ + -e "s,LEASEFILE,/var/run/vmware/udhcpd-vmnet1.leases," \ + /mnt/etc/opt/openslx/udhcpd.conf >/mnt/etc/vmware/udhcpd/udhcpd-vmnet1.conf + fi + + # vmware nat interface configuration + if [ -n "$vmware_vmnet8" ] ; then + local vmnet8ip=${vmware_vmnet8%/*} + local vmpx=${vmware_vmnet8#*/} + local vmsub=$(echo $vmnet8ip |sed 's,\(.*\)\..*,\1,') # x.x.x.x => x.x.x"> + # vmip is user for vmnet8 device + # vmnet is user for config files nat.conf/dhcp + local vmip="${vmsub}.1" + local vmnet="${vmsub}.2" + echo -e "vmnet8=$vmip/$vmpx" >>${PLUGINCONFDIR}/vmware.conf + # setting up the udhcpd configuration + sed -e "s,NWIF,vmnet8,;s,/misc/,/vmware/," \ + -e "s,CNETWORK,$vmsub,;s,PIDFILE,/var/run/vmware/udhcpd-vmnet8.pid," \ + -e "s,LEASEFILE,/var/run/vmware/udhcpd-vmnet8.leases," \ + /mnt/etc/opt/openslx/udhcpd.conf >/mnt/etc/vmware/udhcpd/udhcpd-vmnet8.conf + # might be not needed any more ... + echo -e "# Linux NAT configuration file" \ + > /mnt/etc/vmware/nat.conf + echo -e "[host]" \ + >> /mnt/etc/vmware/nat.conf + echo -e "ip = $vmnet/$vmpx" \ + >> /mnt/etc/vmware/nat.conf + echo -e "device = /dev/vmnet8" \ + >> /mnt/etc/vmware/nat.conf + echo -e "activeFTP = 1" \ + >> /mnt/etc/vmware/nat.conf + echo -e "[udp]" \ + >> /mnt/etc/vmware/nat.conf + echo -e "timeout = 60" \ + >> /mnt/etc/vmware/nat.conf + echo -e "[incomingtcp]" \ + >> /mnt/etc/vmware/nat.conf + echo -e "[incomingudp]" \ + >> /mnt/etc/vmware/nat.conf + echo "00:50:56:F1:30:50" > /mnt/etc/vmware/vmnet-natd-8.mac + fi + # copy the runlevel script to the proper place and activate it + sed "s/eth0/$nwif/g" ${PLUGINDIR}/vmware-slx > /mnt/etc/init.d/vmware-env \ + || echo " * Error copying runlevel script. Shouldn't happen." + chmod a+x /mnt/etc/init.d/vmware-env + rllinker "vmware-env" 20 2 + + ############################################################################ + # vmware stuff first part: two scenarios + # * VM images in /usr/share/vmware - then simply link + # * VM images via additional mount (mount source NFS, NBD, ...) + + # get source of vmware image server (get type, server and path) + if strinstr "/" "${vmware_imagesrc}" ; then + vmimgprot=$(uri_token ${vmware_imagesrc} prot) + vmimgserv=$(uri_token ${vmware_imagesrc} server) + vmimgpath="$(uri_token ${vmware_imagesrc} path)" + fi + if [ -n "${vmimgserv}" -a -n ${vmimgpath} -a -n ${vmimgprot} ] ; then + mnttarget=${VIRTDIR}/vmware + # mount the vmware image source readonly (ro) + fsmount ${vmimgprot} ${vmimgserv} ${vmimgpath} ${mnttarget} ro + else + [ $DEBUGLEVEL -gt 1 ] && error " * Incomplete information in variable \ +${vmware_imagesrc}." nonfatal + fi + + ############################################################################ + # vmware stuff second part: setting up the environment + # make udhcpd more silent + touch /mnt/var/run/vmware/udhcpd-vmnet1.leases \ + /mnt/var/run/vmware/udhcpd-vmnet8.leases + + # create the needed devices which effects all vmware options + # they are not created automatically via module load + for i in "/dev/vmnet0 c 119 0" "/dev/vmnet1 c 119 1" \ + "/dev/vmnet8 c 119 8" "/dev/vmmon c 10 165"; do + mknod $i + done + chmod 0700 /dev/vmnet* + + echo -e "usbfs\t\t/proc/bus/usb\tusbfs\t\tauto\t\t 0 0" >> /mnt/etc/fstab + # needed for VMware 5.5.4 and versions below + echo -e "\tmount -t usbfs usbfs /proc/bus/usb 2>/dev/null" \ + >>/mnt/etc/init.d/boot.slx + + # allow VMware swapping if RamZSWAP is enabled + if grep -E "^ramzswap.*1 -.*" /proc/modules ; then + echo -e '.encoding = "UTF-8"\nprefvmx.minVmMemPct = "50" +prefvmx.useRecommendedLockedMemSize = "TRUE"' | sed -e "s/^ *//" \ + >/mnt/etc/vmware/config + else + # disable VMware swapping else + echo -e '.encoding = "UTF-8"\nprefvmx.minVmMemPct = "100" +prefvmx.useRecommendedLockedMemSize = "TRUE"' | sed -e "s/^ *//" \ + >/mnt/etc/vmware/config + fi + + # copy virtualization include files to config dir + cp ${PLUGINDIR}/run-virt.include ${PLUGINCONFDIR} + # copy version depending files + cp ${PLUGINDIR}/${vmware_kind}/vmplayer ${BINDIR}/vmplayer + if [ -e ${PLUGINDIR}/${vmware_kind}/vmware ]; then + cp ${PLUGINDIR}/${vmware_kind}/vmware ${BINDIR}/vmware + fi + + # affects only kernel and config depending configuration of not + # local installed versions + cat ${PLUGINDIR}/${vmware_kind}/config >>/mnt/etc/vmware/config + chmod 644 /mnt/etc/vmware/config + echo "# stage1 variables produced during plugin install" \ + >>${PLUGINCONFDIR}/vmware.conf + cat ${PLUGINDIR}/${vmware_kind}/vmware.conf >>${PLUGINCONFDIR}/vmware.conf + + # if /tmp resides on nfs: create an empty container file for vmware *.vmem + # it does not like to live on NFS exports (still needed??) + #if [ cat /proc/mounts|grep -qe "^/tmp "|grep -qe "nfs" ] ; then + # dd if=/dev/zero of=/mnt/tmp/vm-container count=1 seek=2048000 + # diskfm /mnt/tmp/vm-container /mnt/tmp/vmware + # chmod a+rwxt /mnt/tmp/vmware + #fi + [ $DEBUGLEVEL -gt 0 ] && echo "done with 'vmware' os-plugin ..." + + fi +else + [ $DEBUGLEVEL -gt 0 ] && echo " * Configuration of vmware plugin failed" +fi diff --git a/src/os-plugins/plugins/vmware/files/README b/src/os-plugins/plugins/vmware/files/README new file mode 100644 index 00000000..ae8bf1e7 --- /dev/null +++ b/src/os-plugins/plugins/vmware/files/README @@ -0,0 +1,12 @@ +Files +- nvram (version from VMware5) + This nvram supports a second Floppy drive. Helpfull if you want to + get some data from linux to your Windows VirtualMachine (like + Scanner-IP or Userinformation) +- run-virt.include + The main include script for the vmchooser plugin run-virt.sh vir- + tualization environments start script. All vmware related stuff like + the creation of the configuration file is handled within this script. +- install-vmpl.sh + Install script, can handle different vmware version installations + diff --git a/src/os-plugins/plugins/vmware/files/install-vmpl.sh b/src/os-plugins/plugins/vmware/files/install-vmpl.sh new file mode 100644 index 00000000..e0795b30 --- /dev/null +++ b/src/os-plugins/plugins/vmware/files/install-vmpl.sh @@ -0,0 +1,284 @@ +#!/bin/sh + +cd /opt/openslx/plugin-repo/vmware/ + +### Check if player are still installed +if [ -d ${1}/vmroot/ ]; then + echo " * $1 seems to be installed. There shouldn't be a need for a new installation." + echo " If you want to reinstall $1 press \"y\" else we will exit" + read + if [ "${REPLY}" != "y" ]; then + echo " * $1 is already installed. Nothing to do." + exit + fi + echo " * $1 will be reinstalled" +fi + + +### Now define values +if [ "$1" = "vmpl1.0" ]; then + vmplversion="vmpl1.0" + tgzfile=$(ls packages/VMware-player-1.0.*|sort|tail -n 1) +elif [ "$1" = "vmpl2.0" ]; then + vmplversion="vmpl2.0" + tgzfile=$(ls packages/VMware-player-2.0.*|sort|tail -n 1) +elif [ "$1" = "vmpl2.5" ]; then + vmplversion="vmpl2.5" + tgzfile=$(ls packages/VMware-Player-2.5.*.bundle|sort|tail -n 1) +else + echo "Attribute of install-vmpl.sh isn't valid!" + echo "This shouldn't happen! Fix vmware.pm!" + exit 1; +fi + + +### Main installation part +if [ "${vmplversion}" != "vmpl2.5" ]; then + # tgz Installation of vmpl1.0 and vmpl2.0 + cd ${vmplversion} + + echo " * Unpacking vmplayer ${vmplversion}" + tar xfz ../${tgzfile} + # TODO: errorcheck if tgz wasnt downloaded properly. + # ask on mailinglist if theres a way how to handle it + # in preInstallation() "exit 1" is enough. Perhaps it will work + # here, too. Try first, and then document it in the wiki + + # reduce some errors + echo " * deleting old files if available" + rm -rf vmroot + + echo " * copying files..." + mkdir vmroot + mkdir -p vmroot/modules + mkdir -p vmroot/lib + mv vmware-player-distrib/lib vmroot/lib/vmware + mv vmware-player-distrib/bin vmroot/ + if [ "${vmplversion}" != "vmpl1.0" ]; then + mv vmware-player-distrib/sbin vmroot/ + fi + mv vmware-player-distrib/doc vmroot/ + rm -rf vmware-player-distrib/ + rm -rf vmroot/lib/vmware/modules/binary + + echo " * fixing file permission" + chmod 04755 vmroot/lib/vmware/bin/vmware-vmx + + # I don't want to understand what vmware is doing, but without this + # step we need to have LD_LIBRARY_PATH with 53 entrys. welcome to + # library hell + echo " * fixing librarys..." + cd vmroot/lib/vmware/lib + mkdir test + mv lib* test + mv test/lib*/* . + rm -rf test + cd ../../../.. + + echo " * fixing gdk and pango config files" + sed -i \ + "s,/build/mts/.*/vmui/../libdir/libconf,/opt/openslx/plugin-repo/vmware/${vmplversion}/vmroot/lib/vmware/libconf," \ + vmroot/lib/vmware/libconf/etc/gtk-2.0/gdk-pixbuf.loaders + sed -i \ + "s,/build/mts/.*/vmui/../libdir/libconf,/opt/openslx/plugin-repo/vmware/${vmplversion}/vmroot/lib/vmware/libconf," \ + vmroot/lib/vmware/libconf/etc/gtk-2.0/gtk.immodules + sed -i \ + "s,/build/mts/.*/vmui/../libdir/libconf,/opt/openslx/plugin-repo/vmware/${vmplversion}/vmroot/lib/vmware/libconf," \ + vmroot/lib/vmware/libconf/etc/pango/pango.modules + sed -i \ + "s,/build/mts/.*/vmui/../libdir/libconf,/opt/openslx/plugin-repo/vmware/${vmplversion}/vmroot/lib/vmware/libconf," \ + vmroot/lib/vmware/libconf/etc/pango/pangorc + sed -i \ + "s,/etc/pango/pango/,/etc/pango/," \ + vmroot/lib/vmware/libconf/etc/pango/pangorc + + echo " * creating /etc/vmware" + rm -rf /etc/vmware + mkdir -p /etc/vmware + + echo " * unpacking kernel modules" + cd vmroot/lib/vmware/modules/source + tar xf vmnet.tar + tar xf vmmon.tar + if [ "${vmplversion}" != "vmpl1.0" ]; then + tar xf vmblock.tar + fi + + echo " * building vmblock module" + if [ "${vmplversion}" != "vmpl1.0" ]; then + cd vmblock-only/ + sed -i "s%^VM_UNAME = .*%VM_UNAME = $(find /boot/vmlinuz* -maxdepth 0|sed 's,/boot/vmlinuz-,,g'|sort|tail -n 1)%" Makefile + make -s + mv vmblock.ko vmblock.o ../../../../../modules + cd .. + fi + + echo " * building vmmon module" + cd vmmon-only + sed -i "s%^VM_UNAME = .*%VM_UNAME = $(find /boot/vmlinuz* -maxdepth 0|sed 's,/boot/vmlinuz-,,g'|sort|tail -n 1)%" Makefile + make -s + mv vmmon.ko vmmon.o ../../../../../modules + cd .. + + echo " * building vmnet module" + cd vmnet-only + sed -i "s%^VM_UNAME = .*%VM_UNAME = $(find /boot/vmlinuz* -maxdepth 0|sed 's,/boot/vmlinuz-,,g'|sort|tail -n 1)%" Makefile + make -s + mv vmnet.ko vmnet.o ../../../../../modules + cd ../../../../../.. + + echo " * setting up EULA" + mv vmroot/doc/EULA vmroot/lib/vmware/share/EULA.txt + + echo " * finishing installation" + + +else + # bundle Installation of vmpl2.5 + # note: the rpm just include the stupid .bundle file... + cd ${vmplversion} + + echo " * Manipulating and extracting vmplayer ${vmplversion} package. this may take a while" + + # fool non-root user extraction... just for testing + sed -i 's/ exit 1/ echo 1/' ../${tgzfile} + # don't use deinstallation stuff and checks of /etc... + # and don't modify file size, else it wont work! + sed -i 's/ migrate_networks/ echo te_networks/' ../${tgzfile} + sed -i 's/ uninstall_legacy/ echo tall_legacy/' ../${tgzfile} + sed -i 's/ uninstall_rpm/ echo tall_rpm/' ../${tgzfile} + sed -i 's/ uninstall_bundle/ echo tall_bundle/' ../${tgzfile} + # this won't work as root on our clients... I hope it don't break + # anything on our clients in stage1 + sh ../${tgzfile} -x temp + # TODO: errorcheck if rpm wasnt downloaded properly. + # ask on mailinglist if theres a way how to handle it + # in preInstallation() "exit 1" is enough. Perhaps it will work + # here, too. Try first, and then document it in the wiki + + # reduce some errors + echo " * deleting old files if available" + rm -rf vmroot + + echo " * copying files..." + mkdir -p vmroot + mkdir -p vmroot/lib + mkdir -p vmroot/modules + + mv temp/vmware-player/lib vmroot/lib/vmware + mv temp/vmware-player/sbin vmroot/ + # the following shouldn't be needed, just to have it 1:1 self-created + # copy of /usr/lib/vmware + # Todo: clean it out when everything is running + mv temp/vmware-installer vmroot/lib/vmware/installer + rm -rf vmroot/lib/vmware/installer/.installer + rm -rf vmroot/lib/vmware/installer/bootstrap + mkdir -p vmroot/lib/vmware/setup + mv temp/vmware-player-setup/vmware-config vmroot/lib/vmware/setup + mv temp/vmware-player/doc vmroot/ + mv temp/vmware-player/bin vmroot/ + + ## + ## left files/dirs + ## + # temp/vmware-player/files/index.theme ... hopefully not needed, + # temp/vmware-player/share => /usr/share ... icons + # temp/vmware-player/etc/... => /etc + # temp/vmware-player/build => unknown... not found... + + + # etc/vmware/ + # bootstrap => Path definitions. confusing due of version 1.0 + # which looks like the instller version + # perhaps just for installer... hopefully + # config => path definition, networking, different configurations + # database => sqlite3 db. includes all files mapped to component + # hopefully just used by installer and some path config + # networking => networking config... has options which are in + # dhcpd.conf, hopefully not needed + # vmnet(1|8) => we know it from v1/v2 + + echo " * fixing file permission" + chmod 755 vmroot/lib/vmware/bin/* + chmod 04755 vmroot/lib/vmware/bin/vmware-vmx + chmod 04755 vmroot/lib/vmware/bin/vmware-vmx-debug + chmod 04755 vmroot/lib/vmware/bin/vmware-vmx-stats + chmod 755 vmroot/bin/* + chmod 755 vmroot/lib/vmware/lib/wrapper-gtk24.sh + + # I don't want to understand what vmware is doing, but without this + # step we need to have LD_LIBRARY_PATH with 53 entrys. welcome to + # library hell + # if this fact is still valid for 2.5 is unclear, but lets do it + echo " * fixing librarys..." + cd vmroot/lib/vmware/lib + mkdir test + mv lib* test + mv test/lib*/* . + rm -rf test + cd ../../../.. + + echo " * fixing gdk and pango config files" + sed -i \ + "s,@@LIBCONF_DIR@@,/opt/openslx/plugin-repo/vmware/${vmplversion}/vmroot/lib/vmware/libconf," \ + vmroot/lib/vmware/libconf/etc/gtk-2.0/gdk-pixbuf.loaders + sed -i \ + "s,@@LIBCONF_DIR@@,/opt/openslx/plugin-repo/vmware/${vmplversion}/vmroot/lib/vmware/libconf," \ + vmroot/lib/vmware/libconf/etc/gtk-2.0/gtk.immodules + sed -i \ + "s,@@LIBCONF_DIR@@,/opt/openslx/plugin-repo/vmware/${vmplversion}/vmroot/lib/vmware/libconf," \ + vmroot/lib/vmware/libconf/etc/pango/pango.modules + sed -i \ + "s,@@LIBCONF_DIR@@,/opt/openslx/plugin-repo/vmware/${vmplversion}/vmroot/lib/vmware/libconf," \ + vmroot/lib/vmware/libconf/etc/pango/pangorc + sed -i \ + "s,/etc/pango/pango/,/etc/pango/," \ + vmroot/lib/vmware/libconf/etc/pango/pangorc + + echo " * creating /etc/vmware" + rm -rf /etc/vmware + mkdir -p /etc/vmware + + echo " * unpacking kernel modules" + cd vmroot/lib/vmware/modules/source + tar xf vmnet.tar + tar xf vmmon.tar + tar xf vmblock.tar + #tar xf vmci.tar # just for 2 or more VMs => not needed + #tar xf vmppuser.tar # we don't need it + tar xf vsock.tar + + echo " * building vmblock module" + cd vmblock-only/ + sed -i "s%^VM_UNAME = .*%VM_UNAME = $(find /boot/vmlinuz* -maxdepth 0|sed 's,/boot/vmlinuz-,,g'|sort|tail -n 1)%" Makefile + make -s + mv vmblock.ko vmblock.o ../../../../../modules + cd .. + + echo " * building vmmon module" + cd vmmon-only + sed -i "s%^VM_UNAME = .*%VM_UNAME = $(find /boot/vmlinuz* -maxdepth 0|sed 's,/boot/vmlinuz-,,g'|sort|tail -n 1)%" Makefile + make -s + mv vmmon.ko vmmon.o ../../../../../modules + cd .. + + echo " * building vmnet module" + cd vmnet-only + sed -i "s%^VM_UNAME = .*%VM_UNAME = $(find /boot/vmlinuz* -maxdepth 0|sed 's,/boot/vmlinuz-,,g'|sort|tail -n 1)%" Makefile + make -s + mv vmnet.ko vmnet.o ../../../../../modules + cd .. + + echo " * building vmsock module" + cd vsock-only + sed -i "s%^VM_UNAME = .*%VM_UNAME = $(find /boot/vmlinuz* -maxdepth 0|sed 's,/boot/vmlinuz-,,g'|sort|tail -n 1)%" Makefile + make -s + mv vsock.ko vsock.o ../../../../../modules + cd ../../../../../.. + + echo " * setting up EULA" + mv vmroot/doc/EULA vmroot/lib/vmware/share/EULA.txt + + echo " * finishing installation" + +fi diff --git a/src/os-plugins/plugins/vmware/files/nvram b/src/os-plugins/plugins/vmware/files/nvram new file mode 100644 index 00000000..85125f1e Binary files /dev/null and b/src/os-plugins/plugins/vmware/files/nvram differ diff --git a/src/os-plugins/plugins/vmware/files/run-virt.include b/src/os-plugins/plugins/vmware/files/run-virt.include new file mode 100644 index 00000000..2010dc4b --- /dev/null +++ b/src/os-plugins/plugins/vmware/files/run-virt.include @@ -0,0 +1,448 @@ +# run-virt.include +# ----------------------------------------------------------------------------- +# Copyright (c) 2009..2010 - RZ Uni Freiburg +# Copyright (c) 2009..2010 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# run-virt.include +# - component for vmware/player of the vmchooser plugin run-virt.sh +################################################################################ + +# configuration writer functions +################################################################################ + +runvmwareconfheader () +{ +echo "# This configuration file was generated by $0" >${conffile} + +case "$vmversion" in + *) + svga_autodetect="TRUE" + numvcpus="1" + shared_folder="FALSE" + echo ".encoding = \"UTF-8\" +# version specific stuff - all versions +config.version = \"8\"" >>${conffile} + ;; +esac +case "$vmversion" in + 2.*|3.*|6.*|7.*) + shared_folder="TRUE" + echo " +# version specific stuff - ver. 2.*|3.*|6.*|7.* +sharedFolder.option = \"alwaysEnabled\"" >>${conffile} + ;; +esac +case "$vmversion" in + 2.5|3.*|6.5|7.*) + if [ "${cpu_cores}" -ge "2" 2>/dev/null ]; then + numvcpus="2" + fi + cap3d="TRUE" # helper var for loging output + echo " +# version specific stuff - ver. 2.5|3.*|6.5|7.* +ehci.present = \"TRUE\" +mks.enable3d = \"${enable3d}\"" >>${conffile} + ;; +esac +case "$vmversion" in + 3.*|7.*) + numvcpus="${cpu_cores}" + # svga_autodetect="FALSE" # if defined manual, see below + echo " +# version specific stuff - ver. 3.*|7.* +cpuid.coresPerSocket = \"${cpu_cores}\" +maxvcpus = \"4\" +# svga.numDisplays = "2" +# svga.maxWidth = "2560" +# svga.maxHeight = "2048" +# svga.vramSize = "134217728" +monitor.virtual_mmu = \"automatic\" +monitor.virtual_exec = \"automatic\" +floppy1.clientDevice = \"FALSE\" +floppy1.readonly = \"TRUE\"" >>${conffile} + ;; +esac + +echo " +# id +virtualHW.version = \"${hwver}\" +displayName = \"${displayname}\" +guestOS = \"${vmostype}\" + +# CPU/MEM +numvcpus = \"${numvcpus}\" +memsize = \"${mem}\" +MemAllowAutoScaleDown = \"FALSE\" +MemTrimRate = \"-1\" + +# ide-disks +ide0:0.present = \"${ide}\" +ide0:0.fileName = \"${diskfile}\" +ide0:0.mode = \"independent-nonpersistent\" +ide1:0.present = \"${cdrom0}\" +ide1:0.autodetect = \"TRUE\" +ide1:0.fileName = \"auto detect\" +ide1:0.deviceType = \"cdrom-raw\" +ide1:1.present = \"${cdrom1}\" +ide1:1.autodetect = \"TRUE\" +ide1:1.fileName = \"auto detect\" +ide1:1.deviceType = \"cdrom-raw\" + +# scsi-disks +scsi0.present = \"${scsi}\" +scsi0:0.present = \"${scsi}\" +scsi0:0.fileName = \"${diskfile}\" +scsi0.virtualDev = \"${hddrv}\" +scsi0:0.mode = \"independent-nonpersistent\" + +# floppies +floppy0.present = \"${floppy0}\" +floppy0.startConnected = \"FALSE\" +floppy0.autodetect = \"TRUE\" +floppy0.fileName = \"auto detect\" +# we need floppy b: for our windows client configuration +floppy1.present = \"${floppy1}\" +floppy1.startConnected = \"TRUE\" +floppy1.fileType = \"file\" +floppy1.fileName = \"${floppy1name}\" + +# nics +ethernet0.present = \"TRUE\" +ethernet0.addressType = \"static\" +${network_virtualDev} +ethernet0.connectionType = \"${network_kind}\" +#ethernet1.connectionType = \"custom\" +#ethernet1.vnet = \"/dev/vmnet2\" +ethernet0.address = \"00:50:56:${VM_ID}:${machostpart}\" +ethernet0.wakeOnPcktRcv = \"FALSE\" + +# sound +sound.present = \"TRUE\" +sound.fileName = \"-1\" +sound.autodetect = \"TRUE\" + +# svga +svga.autodetect = \"${svga_autodetect}\" + +# usb +usb.present = \"TRUE\" +usb.generic.autoconnect = \"TRUE\" + +# shared folders +sharedFolder0.present = \"TRUE\" +sharedFolder0.enabled = \"${shared_folder}\" +sharedFolder0.expiration = \"never\" +sharedFolder0.guestName = \"${sharename}\" +sharedFolder0.hostPath = \"${sharepath}\" +sharedFolder0.readAccess = \"TRUE\" +sharedFolder0.writeAccess = \"TRUE\" +sharedFolder.maxNum = \"1\" + +# dirs/configs +tmpDirectory = \"${redodir}\" +redoLogDir = \"${redodir}\" +mainMem.useNamedFile = \"TRUE\" +snapshot.disabled = \"TRUE\" +tools.syncTime = \"TRUE\" +isolation.tools.hgfs.disable = \"FALSE\" +hgfs.mapRootShare = \"TRUE\" +isolation.tools.dnd.disable = \"FALSE\" +isolation.tools.copy.enable = \"TRUE\" +isolation.tools.paste.enabled = \"TRUE\" + +# serial port +serial0.present = \"${serial}\" +${serialdev} + +# parallel port +parallel0.present = \"${parallel}\" +parallel0.bidirectional = \"${paralbidi}\" +${paraldev}" >>${conffile} + +# set the appropriate permissions for the vmware config file +chmod u+rwx ${conffile} >/dev/null 2>&1 +} + +preferencesheader () +{ +echo ".encoding = \"UTF-8\" +# This configuration file was generated by $0 + +# updates/tips +webUpdate.enabled = \"FALSE\" +pref.downloadPermission = \"deny\" +pref.vmplayer.downloadPermission = \"deny\" +pref.vmplayer.webUpdateOnStartup = \"FALSE\" +pref.tip.startup = \"FALSE\" +hints.hideAll = \"TRUE\" +hint.vmui.showAllUSBDevs = \"FALSE\" + +# configs +prefvmx.defaultVMPath = \"${vmhome}\" +prefvmx.mru.config = \"${conffile}:\" + +# hot keys +pref.hotkey.control = \"true\" +pref.hotkey.alt = \"true\" +pref.hotkey.shift = \"true\" +pref.hotkey.gui = \"true\" +gui.restricted = \"true\" + +# fullscreen/mouse/keyboard +pref.fullscreen.toolbarPixels = \"0\" +pref.vmplayer.fullscreen.autohide = \"TRUE\" +pref.grabOnMouseClick = \"TRUE\" +pref.grabOnKeyPress = \"FALSE\" +pref.motionGrab = \"TRUE\" +pref.motionUngrab = \"TRUE\" +pref.hideCursorOnUngrab = \"TRUE\" +pref.autoFit = \"TRUE\" +pref.autoFitFullScreen = \"fitGuestToHost\" +pref.vmplayer.exit.vmAction = \"poweroff\" +pref.vmplayer.confirmOnExit = \"TRUE\" + +# shared folders +pref.enableAllSharedFolders = \"TRUE\" + +# eula +pref.eula.size = \"2\" +pref.eula.0.appName = \"VMware Player\" +pref.eula.0.buildNumber = \"${vmbuild}\" +pref.eula.1.appName = \"VMware Workstation\" +pref.eula.1.buildNumber = \"${vmbuild}\"" >${vmhome}/preferences +} + + +# declaration of default variables +################################################################################ + +# VM-ID static (0D), remove if changed to 00 +VM_ID="0D" +# temporary disk space for logs, etc... +redodir=/tmp/vmware/${USER} +# dir for configs and vmem file +confdir=${redodir} +# configfile +conffile="${confdir}/run-vmware.conf" +# diskfile +diskfile=${vmpath} +# users vmware config folder +vmhome="${HOME}/.vmware" + +# get several version infos for vmware/player +. ${OPENSLX_DEFAULT_CONFDIR}/plugins/vmware/vmware.conf +vmbuild=$buildversion +vmversion=$version + +# VMware start options +# "-X": start in fullscreen +vmopt="-X" + + +# hardware checks +################################################################################ + +# use different network card +if [ -n "${network_card}" ]; then + network_virtualDev='ethernet0.virtualDev = "e1000"' +else + network_virtualDev='# using default virtualDev for ethernet0' +fi + +case "$enable3d" in + *true*|*TRUE*|*yes*|*YES*) + enable3d="TRUE" + ;; + *) + enable3d="FALSE" + ;; +esac + +# serial/parallel port defined (e.g. "ttyS0, lp0" or "autodetect") +case "$serial" in + tty*) + serialdev="serial0.filename = \"/dev/${serial}\"" + serial="TRUE" + ;; + auto*) + serialdev="serial0.autodetect = \"TRUE\"" + serial="TRUE" + ;; + *) + serialdev="# no serial port configured" + serial="FALSE" + ;; +esac +case "$parallel" in + lp*|parport*) + paraldev="parallel0.filename = \"/dev/${parallel}\"" + paralbidi="TRUE" + parallel="TRUE" + ;; + auto*) + paraldev="parallel0.autodetect = \"TRUE\"" + paralbidi="TRUE" + parallel="TRUE" + ;; + *) + paraldev="# no parallel port configured" + paralbidi="FALSE" + parallel="FALSE" + ;; +esac + +# adjust memory available for vmware guests +#if [ -n "${forcemem}" ]; then +# mem="${forcemem}" +#else +# case "$vmversion" in +# 2.*|6.*) +# permem=30 +# ;; +# 3.*|7.*) +# permem=25 +# ;; +# esac +# if [ "${totalmem}" -ge "2500" ]; then +# permem=40 +# fi +# # check if /tmp is on harddisk +# if grep -qe "/dev/.* /tmp " /proc/mounts ; then +# permem=60 +# id44="1" +# # Hack, if more than 2,5G RAM use 40% of Ram and write vmem into Ram as well +# # (40% vmware | 40% confdir(vmem...) | 20% host +# # VMplayer 2+ issue +# if [ "${totalmem}" -ge "2500" ]; then +# permem=40 +# confdir=/dev/shm/vmware/$USER +# conffile=${confdir}/run-vmware.conf +# mkdir -p /dev/shm/vmware/$USER +# fi +# fi +# mem=$(expr ${totalmem} / 100 \* ${permem} / 4 \* 4) +# if [ "${id44}" = "1" ]; then +# hostmem=$(expr ${totalmem} - ${mem}) +# else +# hostmem=$(expr ${totalmem} - ${mem} - ${mem}) +# fi +#fi + +# check if ide/scsi and hwver of image +# read only the first 30 lines to be shure +imghead=$(head -30 ${diskfile}) +hddrv=$(echo "${imghead}" | grep -m1 -ia "ddb.adapterType" |\ + awk -F '"' '{print $2}') +hwver=$(echo "${imghead}" | grep -m1 -ia "ddb.virtualHWVersion" |\ + awk -F '"' '{print $2}') +case "${hddrv}" in + ide) + ide="TRUE" + scsi="FALSE" + ;; + lsilogic|buslogic) + ide="FALSE" + scsi="TRUE" + ;; +esac + + +# write configuration files +################################################################################ + +# create vmware directories +mkdir -p ${redodir} >/dev/null 2>&1 +mkdir -p ${confdir} >/dev/null 2>&1 +mkdir -p ${vmhome} >/dev/null 2>&1 + +# create preferences +preferencesheader + +# create VMware startup file +runvmwareconfheader +# link to conffile if confdir != redodir +ln -s ${conffile} ${redodir}/run-vmware.conf >/dev/null 2>&1 + +# sync is needed to ensure that data is really written to virtual disk +sync + +# own nvram. We need it for floppy drive b, default nvram has just drive a +# TODO: optimize, currently kinda inefficient, too much copys, but we +# don't know which one is installed... +for i in /opt/openslx/plugin-repo/vmware/*; do + cp ${i}/nvram ${confdir}/nvram 2>/dev/null +done + + +# logging and stdout +################################################################################ + +# log script information +writelog "# File created by $0 (VMversion ${vmversion})\n# on $(date)\n" +writelog "Starting with non-persistent mode ...\n" + +# check memory range +if [ "${mem}" -lt "256" ] || [ "${hostmem}" -lt "256" ]; then + writelog "\tMemory out of range: ${mem} MB (guest) / ${hostmem} MB (host)!" + writelog "\tMin. 256 MB for host and guest!" + exit 1 +fi + +# write all results to logfile +# log disksetup +writelog "Directories:" +writelog "\tConfdir:\t${confdir}" +writelog "\tConffile:\t${conffile}" +writelog "\tRedodir:\t${redodir}" +writelog "\tVMhome:\t\t${vmhome}" +writelog "\t/tmp info: \ + $(grep "/tmp " /proc/mounts) $(df -h | grep " /tmp$" | awk '{print $2}')" +# hw setup +writelog "Hardware:" +writelog "\tMAC:\t\t00:50:56:${VM_ID}:${machostpart}" +if [ -n "${network_card}" ]; then + writelog "\tNet Adaptor:\t${network_card}" +fi +writelog "\tMem:\t\t${mem} MB" +# echo nur wenn hostmem gesetzt +[ -n "${hostmem}" ] && writelog "\tHostmem:\t${hostmem} MB" +writelog "\tMax. res.:\t${xres}x${yres}" +writelog "\tCD-ROM1:\t${cdrom0}" +writelog "\tCD-ROM2:\t${cdrom1}" +writelog "\tFloppy_A:\t${floppy0}" +if [ "${serial}" = "TRUE" ]; then + writelog "\tSerial Port:\t${serialdev}" +fi +if [ "${parallel}" = "TRUE" ]; then + writelog "\tParallel Port:\t${paraldev}" +fi +# image +writelog "Diskimage:" +writelog "\tDiskfile:\t${diskfile}" +writelog "\tDisktype:\t${hddrv}" +writelog "\tHWVersion:\t${hwver}" +writelog "\tVMostype:\t${vmostype}" +# misc +writelog "Misc:" +writelog "\tDisplayname:\t${displayname}" +if [ "${cap3d}" = "TRUE" -a "${enable3d}" = "TRUE" ]; then + writelog "\t3D Graphics:\tenabled" +fi +# empty line at end +writelog "" + + +# finally set env for run-virt.sh +################################################################################ + +# using the modified version of the wrapper script +VIRTCMD="${OPENSLX_DEFAULT_BINDIR}/vmplayer" +VIRTCMDOPTS="${vmopt} ${conffile}" diff --git a/src/os-plugins/plugins/vmware/init-hooks/20-nw-bridge-config/bridge.sh b/src/os-plugins/plugins/vmware/init-hooks/20-nw-bridge-config/bridge.sh new file mode 100755 index 00000000..3ae7e946 --- /dev/null +++ b/src/os-plugins/plugins/vmware/init-hooks/20-nw-bridge-config/bridge.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Copyright (c) 2009..2010 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your feedback to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org +# +# Init hook to create a bridge on the active network interface +# (should be kept identical to the files of virtualbox and qemukvm plugins) +############################################################################# + +local bridge=br0 +local brnwif=${nwif} +local nwifmac=${macaddr} + +# bridge 0 already defined or some other problem +brctl addbr ${bridge} || exit 0 +brctl stp ${bridge} 0 +brctl setfd ${bridge} 0.000000000001 +ip link set addr ${nwifmac} ${bridge} +ip link set dev ${nwif} up +brctl addif ${bridge} ${nwif} + +# fixme: sending back the variable to init does not work properly at the +# moment +nwif=${bridge} diff --git a/src/os-plugins/plugins/vmware/init-hooks/60-have-servconfig/vm-dhcpd.sh b/src/os-plugins/plugins/vmware/init-hooks/60-have-servconfig/vm-dhcpd.sh new file mode 100755 index 00000000..b4f02389 --- /dev/null +++ b/src/os-plugins/plugins/vmware/init-hooks/60-have-servconfig/vm-dhcpd.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# Copyright (c) 2010 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your feedback to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org +# +# Init hook to create a bridge on the active network interface +# (should be kept identical in vmware, virtualbox and qemukvm plugins) +############################################################################# + +. /etc/openslx.conf + +CONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR} +testmkd ${CONFDIR} + +# configuring dhcpd stub for virtual networks +cat > ${CONFDIR}/udhcpd.conf << EOF +# general udhcpd configuration file for virtual machines written by +# $0 during OpenSLX stage3 configuration + +# start and end of the IP lease block +start CNETWORK.20 +end CNETWORK.100 + +# interface that udhcpd will use +interface NWIF + +# how long an offered address is reserved (leased) in seconds +offer_time 6000 + +# location of the leases file +lease_file LEASEFILE + +# location of the pid file +pidfile PIDFILE + +option dns ${domain_name_servers} +option subnet 255.255.255.0 +option router CNETWORK.1 +option wins CNETWORK.10 +option domain virtual.site ${domain_name} + +# additional options known to udhcpd +#subnet #timezone +#router #timesvr +#namesvr #dns +#logsvr #cookiesvr +#lprsvr #bootsize +#domain #swapsvr +#rootpath #ipttl +#mtu #broadcast +#wins #lease +#ntpsrv #tftp +#bootfile +EOF diff --git a/src/os-plugins/plugins/vmware/init-hooks/80-after-plugins/adapt-tmpfs.sh b/src/os-plugins/plugins/vmware/init-hooks/80-after-plugins/adapt-tmpfs.sh new file mode 100644 index 00000000..a28a8c6f --- /dev/null +++ b/src/os-plugins/plugins/vmware/init-hooks/80-after-plugins/adapt-tmpfs.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# Copyright (c) 2010 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your feedback to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org +# +# Init hook to adapt the tmpfs size for VMware/Player +# (should be kept identical to the files of virtualbox plugin) +############################################################################# + +# adapt tmpfs size (overbook) +case $(grep tmpfs /proc/mounts) in + */tmp*) + mount -o remount,size=160% /mnt/tmp + ;; + */uniontmp*) + mount -o remount,size=160% /mnt/uniontmp + ;; +esac -- cgit v1.2.3-55-g7522