if (get_answer('Setup is unable to find the "' . $bin . '" program on your machine. Please make sure it is installed. Do you want to specify the location of this program by hand?', 'yesno', 'yes') eq 'no') {
return '';
}
return get_answer('What is the location of the "' . $bin . '" program on your machine?', 'binpath', '');
}
# Execute the command passed as an argument
# _without_ interpolating variables (Perl does it by default)
sub direct_command {
return `$_[0]`;
}
# chmod() that reports errors
sub safe_chmod {
my $mode = shift;
my $file = shift;
if (chmod($mode, $file) != 1) {
error('Unable to change the access rights of the file ' . $file . '.' . "\n\n");
}
}
# Emulate a simplified ls program for directories
sub internal_ls {
my $dir = shift;
my @fn;
opendir(LS, $dir);
@fn = grep(!/^\.\.?$/, readdir(LS));
closedir(LS);
return @fn;
}
# Install a file permission
sub install_permission {
my $src = shift;
my $dst = shift;
my @statbuf;
@statbuf = stat($src);
if (not (defined($statbuf[2]))) {
error('Unable to get the access rights of the source file ' . $src . '.' . "\n\n");
# The previous answer is valid. Make it the default value
$default = $answer;
}
}
$answer = get_answer($msg, $type, $default);
db_add_answer($id, $answer);
return $answer;
}
# Find a suitable backup name and backup a file
sub backup_file {
my $file = shift;
my $i;
for ($i = 0; $i < 100; $i++) {
if (! -e $file . '.old.' . $i) {
my %patch;
undef %patch;
if (internal_sed($file, $file . '.old.' . $i, 0, \%patch)) {
print wrap('File ' . $file . ' is backed up to ' . $file . '.old.' . $i . '.' . "\n\n", 0);
} else {
print STDERR wrap('Unable to backup the file ' . $file . ' to ' . $file . '.old.' . $i .'.' . "\n\n", 0);
}
return;
}
}
print STDERR wrap('Unable to backup the file ' . $file . '. You have too many backups files. They are files of the form ' . $file . '.old.N, where N is a number. Please delete some of them.' . "\n\n", 0);
}
# Uninstall a file previously installed by us
sub uninstall_file {
my $file = shift;
if (not db_file_in($file)) {
# Not installed by this script
return;
}
if (file_name_exist($file)) {
if (db_file_ts($file)) {
my @statbuf;
@statbuf = stat($file);
if (defined($statbuf[9])) {
if (db_file_ts($file) != $statbuf[9]) {
# Modified since this script installed it
backup_file($file);
}
} else {
print STDERR wrap('Unable to get the last modification timestamp of the file ' . $file . '.' . "\n\n", 0);
}
}
if (not unlink($file)) {
print STDERR wrap('Unable to remove the file ' . $file . '.' . "\n\n", 0);
}
} else {
print wrap('This script previously created the file ' . $file . ', and was about to remove it. Somebody else apparently did it already.' . "\n\n", 0);
}
db_remove_file($file);
}
# Return the version of VMware
sub vmware_version {
my $buildNr;
$buildNr = '1.1.2 ' . q$Name: $;
$buildNr =~ s/Name: //;
return remove_whitespaces($buildNr);
}
# Check the validity of an answer whose type is yesno
# Return a clean answer if valid, or ''
sub check_answer_yesno {
my $answer = shift;
my $source = shift;
if (lc($answer) =~ /^y(es)?$/) {
return 'yes';
}
if (lc($answer) =~ /^n(o)?$/) {
return 'no';
}
if ($source eq 'user') {
print wrap('The answer "' . $answer . '" is invalid. It must be one of "y" or "n".' . "\n\n", 0);
}
return '';
}
$gAnswerSize{'yesno'} = 3;
$gCheckAnswerFct{'yesno'} = \&check_answer_yesno;
# Check the validity of an answer based on its type
# Return a clean answer if valid, or ''
sub check_answer {
my $answer = shift;
my $type = shift;
my $source = shift;
if (not defined($gCheckAnswerFct{$type})) {
die 'check_answer(): type ' . $type . ' not implemented :(' . "\n\n";
# Check the validity of an answer whose type is dirpath
# Return a clean answer if valid, or ''
sub check_answer_dirpath {
my $answer = shift;
my $source = shift;
$answer = dir_remove_trailing_slashes($answer);
if (-d $answer) {
# The path is an existing directory
return $answer;
}
# The path is not a directory
if (-e $answer) {
if ($source eq 'user') {
print wrap('The path "' . $answer . '" exists, but is not a directory.' . "\n\n", 0);
}
return '';
}
# The path does not exist
if ($source eq 'user') {
return (get_answer('The path "' . $answer . '" does not exist currently. This script is going to create it, including needed parent directories. Is this what you want?', 'yesno', 'yes') eq 'yes') ? $answer : '';
# Install the uninstaller ASAP, otherwise other installers will not be able
# remove this installation cleanly
$answer = get_persistent_answer('In which directory do you want to install the binary files?', 'BINDIR', 'dirpath', $rootdir . '/bin');
undef %patch;
install_dir('./bin', $answer, \%patch);
# Make vmware and vmware-ping suid root
safe_chmod(04555, $answer . '/vmware');
safe_chmod(04555, $answer . '/vmware-ping');
$rootdir = internal_dirname($answer);
# We don't use get_persistent_answer() here because once the user has
# selected the root directory, we can give him better default answers than
# his/her previous answers.
$answer = get_answer('In which directory do you want to install the library files?', 'dirpath', $rootdir . '/lib/vmware');
db_add_answer('LIBDIR', $answer);
undef %patch;
install_dir('./lib', $answer, \%patch);
$answer = get_answer('In which directory do you want to install the manual files?', 'dirpath', $rootdir . '/man');
db_add_answer('MANDIR', $answer);
undef %patch;
$patch{'%LIBDIR%'} = db_get_answer('LIBDIR');
install_dir('./man', $answer, \%patch);
$answer = get_persistent_answer('In which directory do you want to install the documentation files?', 'DOCDIR', 'dirpath', '/usr/doc/vmware');
undef %patch;
install_dir('./doc', $answer, \%patch);
# Install the startup script (and make the old installer aware of this one)
$initdir = '/sbin/init.d';
if (check_answer_initdirpath($initdir, 'default') eq '') {
$initdir = '/etc/rc.d';
if (check_answer_initdirpath($initdir, 'default') eq '') {
$initdir = '/etc';
if (check_answer_initdirpath($initdir, 'default') eq '') {
$initdir = '';
}
}
}
$answer = get_persistent_answer('What is the directory under which the init scripts reside (it should contain init.d/, and from rc0.d/ to rc6.d/)?', 'INITDIR', 'initdirpath', $initdir);
# Install a tar package or upgrade an already installed tar package
sub install_or_upgrade {
print wrap('Installing the content of the package.' . "\n\n", 0);
install_content();
print wrap('The installation of VMware ' . vmware_version() . ' for Linux completed successfully. You can decide to remove this software from your system at any time by invoking the following command: "' . db_get_answer('BINDIR') . '/' . $cUninstallerFileName . '".' . "\n\n", 0);
}
# Uninstall a tar package
sub uninstall {
my $startup;
my $file;
my $dir;
if (system(shell_string(db_get_answer('INITDIR') . '/init.d/vmware') . ' stop')) {
# Reset these answers in case we have installed new versions of these
# documents
db_remove_answer('EULA_AGREED');
db_remove_answer('ISC_COPYRIGHT_SEEN');
$answer = get_persistent_answer('Before running VMware for the first time, you need to configure it for your running kernel by invoking the following command: "' . db_get_answer('BINDIR') . '/vmware-config.pl". Do you want this script to invoke the command for you now?', 'RUN_CONFIGURATOR', 'yesno', 'yes');