home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.pdx.edu
/
2014.02.ftp.ee.pdx.edu.tar
/
ftp.ee.pdx.edu
/
oss
/
cvs-2004
/
bahasa
/
utilities
/
config_app.pl,v
< prev
next >
Wrap
Text File
|
2003-12-07
|
32KB
|
1,476 lines
head 1.11;
access;
symbols
Initial:1.1.1.1 bule:1.1.1;
locks; strict;
comment @# @;
1.11
date 2003.12.07.07.43.54; author bule; state Exp;
branches;
next 1.10;
1.10
date 2003.10.26.01.53.09; author bule; state Exp;
branches;
next 1.9;
1.9
date 2003.10.17.00.39.35; author bule; state Exp;
branches;
next 1.8;
1.8
date 2003.10.04.18.22.57; author bule; state Exp;
branches;
next 1.7;
1.7
date 2003.09.05.06.42.30; author bule; state Exp;
branches;
next 1.6;
1.6
date 2003.08.31.18.48.47; author bule; state Exp;
branches;
next 1.5;
1.5
date 2003.08.22.00.46.20; author bule; state Exp;
branches;
next 1.4;
1.4
date 2003.08.21.20.20.57; author bule; state Exp;
branches;
next 1.3;
1.3
date 2003.08.21.06.18.06; author bule; state Exp;
branches;
next 1.2;
1.2
date 2003.08.19.06.20.01; author bule; state Exp;
branches;
next 1.1;
1.1
date 2003.08.12.19.18.23; author bule; state Exp;
branches
1.1.1.1;
next ;
1.1.1.1
date 2003.08.12.19.18.23; author bule; state Exp;
branches;
next ;
desc
@@
1.11
log
@*** empty log message ***
@
text
@#!/usr/bin/perl -w
#/////////////////////////////////////////////////////////////////////////////
#/////////////////////////////////////////////////////////////////////////////
#/ Project Name: Bahasa Indonesia Dictionary
#/ Directory: bahasa/utilities
#/ File Name: config_app.pl
#/ Author(s): John L. Whiteman
#/ Created: June 23, 2003
#/ Modified: November 08, 2003
#/ Description: The purpose of this PERL script is to assist you
#/ with installing the Bahasa Indonesia Dictionary
#/ application. It doesn't create the database. Use
#/ the config_db.pl script to help you with configuring
#/ the database required for this project.
#/
#/ Copyright (c) 2003 John L. Whiteman
#/
#/ Permission is herby granted, free of charge, to any person obtaining a
#/ copy of this software, data, and associated documentation files
#/ (the "Software"), to deal in the Software without restriction,
#/ including without limitation the rights to use, copy, modify, merge,
#/ publish, distribute, sublicense, and/or sell copies of Software, and to
#/ permit persons to whom the Software is furnished to do so, subject to
#/ the following conditions:
#/
#/ The above copyright notice and this permission notice shall be
#/ included in all copies or substantial portions of the Software.
#/
#/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#/ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
#/ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
#/ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
#/ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHERE IN AN ACTION OF CONTRACT,
#/ TORT OR OTHERWISE, ARISING IN THE SOFTWARE.
#/////////////////////////////////////////////////////////////////////////////
#/////////////////////////////////////////////////////////////////////////////
use strict;
use Cwd;
use File::Copy;
show_introduction();
while(1) {
my ($response) =
promptyn("Would you like to continue?");
if (!$response) {
print "\nInstallation script terminated!\n\n";
exit(0);
}
last;
}
my (%DICTIONARY_CFG) = ();
$DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} =
prompt_installation_directory();
my ($SLASH) = "/";
$SLASH = "\\"
if ($DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} =~ /\\/);
#These are all the required directories and
#files associated with this project.
#They are followed by default permissions.
#Change these permissions to best suite your needs
#Add your own files and directories if applicable
#Changing the paths to these files is likely cause
#the project to fail
my (%manifest) = (
"backups" => 0703,
"docs" => 0700,
"mysql" => 0703,
"php" => 0701,
"utilities" => 0700,
"web" => 0700,
"backups${SLASH}empty.sql" => 0600,
"docs${SLASH}installation.txt" => 0600,
"docs${SLASH}readme.txt" => 0600,
"mysql${SLASH}administration.sql" => 0606,
"mysql${SLASH}administrators.sql" => 0606,
"mysql${SLASH}alphabet.sql" => 0606,
"mysql${SLASH}create.sql" => 0604,
"mysql${SLASH}destroy.sql" => 0604,
"mysql${SLASH}dictionary.sql" => 0606,
"mysql${SLASH}hits.sql" => 0606,
"mysql${SLASH}misses.sql" => 0606,
"mysql${SLASH}parts_of_speech.sql" => 0606,
"mysql${SLASH}pronunciations.sql" => 0606,
"mysql${SLASH}requests.sql" => 0606,
"mysql${SLASH}searches.sql" => 0606,
"mysql${SLASH}tasks.sql" => 0606,
"php${SLASH}Dictionary.php" => 0604,
"php${SLASH}Indonesia.php" => 0604,
"php${SLASH}Statistics.php" => 0604,
"php${SLASH}Web.php" => 0604,
"utilities${SLASH}config_app.pl" => 0700,
"utilities${SLASH}config_db.pl" => 0700,
"utilities${SLASH}make_release_ready.pl" => 0700,
"web${SLASH}admin.php" => 0604,
"web${SLASH}admins.php" => 0604,
"web${SLASH}backup.php" => 0604,
"web${SLASH}bahasa.css" => 0604,
"web${SLASH}bahasa.js" => 0604,
"web${SLASH}cpwd.php" => 0604,
"web${SLASH}delete.php" => 0604,
"web${SLASH}dictionary.php" => 0604,
"web${SLASH}download.php" => 0604,
"web${SLASH}editor.php" => 0604,
"web${SLASH}email.php" => 0604,
"web${SLASH}help.php" => 0604,
"web${SLASH}insert.php" => 0604,
"web${SLASH}ipa.php" => 0604,
"web${SLASH}login.php" => 0604,
"web${SLASH}logout.php" => 0604,
"web${SLASH}misses.php" => 0604,
"web${SLASH}offline.php" => 0604,
"web${SLASH}online.php" => 0604,
"web${SLASH}pos.php" => 0604,
"web${SLASH}pronunciations.php" => 0604,
"web${SLASH}reference.php" => 0604,
"web${SLASH}request.php" => 0604,
"web${SLASH}requests.php" => 0604,
"web${SLASH}search.php" => 0604,
"web${SLASH}sql.php" => 0604,
"web${SLASH}statistics.php" => 0604,
"web${SLASH}update.php" => 0604,
"web${SLASH}upload.php" => 0604
);
my (%class_files) = (
"php${SLASH}Indonesia.php" =>
"php${SLASH}Dictionary.php",
"php${SLASH}Statistics.php" =>
"php${SLASH}Dictionary.php");
my (%web_files) = (
"web${SLASH}admin.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}admins.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}backup.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}bahasa.css" =>
"php${SLASH}Indonesia.php",
"web${SLASH}bahasa.js" =>
"php${SLASH}Indonesia.php",
"web${SLASH}cpwd.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}delete.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}download.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}dictionary.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}editor.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}email.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}help.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}insert.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}ipa.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}login.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}logout.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}misses.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}offline.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}online.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}pos.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}pronunciations.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}reference.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}request.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}requests.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}search.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}sql.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}statistics.php" =>
"php${SLASH}Statistics.php",
"web${SLASH}tasks.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}update.php" =>
"php${SLASH}Indonesia.php",
"web${SLASH}upload.php" =>
"php${SLASH}Indonesia.php");
my ($dictionary_class) = "php${SLASH}Dictionary.php";
my ($web_class) = "php${SLASH}Web.php";
my (%modified_manifest) = ();
print "Verifying setup directories and files...\n\n";
#Now verify that all directories and files exist
#We will change the permissions only after the
#configuration is finished.
foreach(sort(keys(%manifest))) {
my ($path) = $_;
my ($permissions) = $manifest{$path};
$path =
$DICTIONARY_CFG{INSTALLATION_DIRECTORY} . $SLASH . $path;
$modified_manifest{$path} = $permissions;
print "${path} ";
show_error("\nCan't find ${path}", -1) if (!-e "$path");
print "[OK]\n";
}
$DICTIONARY_CFG{"DB_HOST"} =
prompt("What is or will be the name or IP address of the database server?", 1);
$DICTIONARY_CFG{"DB_NAME"} =
prompt("What is or will be the database name for the dictionary database?", 1);
$DICTIONARY_CFG{"DB_USER"} =
prompt("What is or will be the database user's name?", 1);
$DICTIONARY_CFG{"DB_PASSWORD"} =
prompt("What is or will be $DICTIONARY_CFG{DB_USER}'s password?", 1);
while(1) {
$DICTIONARY_CFG{"EMAIL"} =
prompt("What is or will be the website's primary e-mail address?", 1);
last if (is_email($DICTIONARY_CFG{"EMAIL"}));
show_error(
"This doesn't appear to be a valid e-mail address. Try again.", 0);
}
my (%modified_web_files) = ();
#Qualify the default directories by prepending the installation
#directories then check to ensure the files exist then assign
#then to hash that indicates which class file to use. These files
#pertain to the PHP web code.
foreach(sort(keys(%web_files))) {
my ($web_file) =
$DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} .
$SLASH . ${_};
my ($class_file) =
$DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} .
$SLASH . $web_files{$_};
#Check here if exists...abort if doesn't
show_error(
"Can't find PHP web file ${web_file}\n" .
"Please make sure you installation path is correct.", -1)
if (!-f "$web_file");
#Check here if exists...abort if doesn't
show_error(
"Can't find PHP class file ${class_file}\n" .
"Please make sure you installation path is correct.", -1)
if (!-f "$class_file");
$modified_web_files{"$web_file"} = "$class_file";
}
my (%modified_class_files) = ();
#Do the same for child class files
foreach(sort(keys(%class_files))) {
my ($child_class) =
$DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} .
$SLASH . ${_};
my ($parent_class) =
$DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} .
$SLASH . $class_files{$_};
#Check here if exists...abort if doesn't
show_error(
"Can't find PHP class file ${child_class}\n" .
"Please make sure you installation path is correct.", -1)
if (!-f "$child_class");
#Check here if exists...abort if doesn't
show_error(
"Can't find PHP parent class file ${parent_class}\n" .
"Please make sure you installation path is correct.", -1)
if (!-f "$parent_class");
$modified_class_files{"$child_class"} = "$parent_class";
}
#Dictionary class is the parent class of everything
$dictionary_class = $DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} .
$SLASH . $dictionary_class;
#Check here if exists...abort if doesn't
show_error(
"Can't find PHP parent dictionary class file ${dictionary_class}\n" .
"Please make sure you installation path is correct.", -1)
if (!-f "$dictionary_class");
#Web class to be inserted into web PHP files
$web_class = $DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} .
$SLASH . $web_class;
#Check here if exists...abort if doesn't
show_error(
"Can't find PHP web class file ${web_class}\n" .
"Please make sure you installation path is correct.", -1)
if (!-f "$web_class");
#Verify that configuration values given are correct before
#proceeding
while(1) {
print "\n[VERIFY THESE VALUES]\n\n";
foreach(sort(keys(%DICTIONARY_CFG))) {
my ($name) = $_;
my ($value) = $DICTIONARY_CFG{$name};
print "${name} = ${value}\n";
}
my ($response) =
promptyn("Are these values correct?");
if (!$response) {
print "\nInstallation script terminated!\n\n";
exit(0);
}
last;
}
print "Configuring Dictionary.pm class file...\n";
#Configure the Dictionary.php class with given values
configure_dictionary_class("$dictionary_class", \%DICTIONARY_CFG, $SLASH);
print "Configuring other class files...\n";
#Modify the web files' require_once() statements to include full path
#to source class files
foreach(sort(keys(%modified_class_files))) {
my ($child_class) = $_;
my ($parent_class) = $modified_class_files{$child_class};
configure_php_file($child_class, $parent_class, $SLASH, "");
}
print "Configuring PHP web files...\n";
#Modify the web files' require_once() statements to include full path
#to source class files
foreach(sort(keys(%modified_web_files))) {
my ($web_file) = $_;
my ($class_file) = $modified_web_files{$web_file};
configure_php_file($web_file, $class_file, $SLASH, $web_class);
}
print "Setting default permissions to directories and files...\n";
change_permissions(\%modified_manifest);
#Prompt if user wants to install web files to web server
while(1) {
my ($response) =
promptyn(
"Would you like to install the PHP web files to your web server?");
if (!$response) {
print
"\nInstallation script done!\n" .
"Once again double check permissions " .
"for directories and files.\n\n";
exit(0);
}
last;
}
#Change permissions to installation directory
chmod(0701, $DICTIONARY_CFG{"INSTALLATION_DIRECTORY"});
my ($web_directory) = "";
#Prompt for web server installation directory
while(1) {
TRY_AGAIN:
$web_directory =
prompt(
"What is the name of the web directory to copy the " .
"PHP web files?", 1);
#Remove trailing slash for UNIX systems if exists
$web_directory =~ s/\/$//;
#Remove trailing slash for Windows systems if exists
$web_directory =~ s/\\$//;
if (!-d "$web_directory") {
show_error(
"Web directory ${web_directory} does not exist.\n" .
"Manually create this directory or use an existing one\n" .
"before continuing. I'll wait.", 0);
my ($response) =
promptyn("Try again?", 1);
if (!$response) {
print
"\nInstallation script done.\n" .
"Manually copy web PHP files and sub-directories " .
"when you are ready.\n\n";
exit(0);
}
} else {
my ($response) =
promptyn("Is web directory ${web_directory} correct?");
if (!$response) {
$response =
promptyn(
"Would you like to try another web directory?");
goto TRY_AGAIN if ($response);
print
"\nInstallation script done.\n" .
"Manually copy web PHP files and sub-directories " .
"when you are ready.\n\n";
exit(0);
}
last;
}
}
print "Copying PHP web files...\n";
foreach(sort(keys(%modified_web_files))) {
my ($src) = $_;
my ($tgt) = $web_directory . $SLASH . get_basename($src);
copy("$src", "$tgt");
chmod(0604, "$tgt");
show_error(
"Can't copy\n${src} to\n${tgt}\n" .
"Read documentation about manual web installation.", -1)
if (!-f "$tgt");
}
print
"Installation script done!\n" .
"Once again double check permissions for directories and files.\n\n";
#----------------------------------------------------------------------------
#Changes installation directories and files to default permissions
#----------------------------------------------------------------------------
sub change_permissions {
my ($modified_manifest) = shift;
foreach(sort(keys(%$modified_manifest))) {
my ($path) = $_;
my ($permissions) = $$modified_manifest{$path};
chmod($permissions, $path);
}
return;
}
#----------------------------------------------------------------------------
#Configures the Dictionary.pm class files to run under this environment.
#----------------------------------------------------------------------------
sub configure_dictionary_class {
my ($file) = shift;
my ($cfg) = shift;
my ($slash) = shift;
my ($file_backup) = $file . "." . $$ . ".bak";
my ($cfg_entry) = "";
#Compose the dictionary configuration PHP entries
#Also change permissions to directories if applicable
foreach(sort(keys(%$cfg))) {
my ($name) = $_;
my ($value) = $$cfg{$_};
$value =~ s/\\/\\\\/g
if (($name eq "INSTALLATION_DIRECTORY") && ($slash eq "\\"));
$cfg_entry .=
"\$this->configuration[\"${name}\"] = \"${value}\";\n\n";
}
#Clean it up
chomp($cfg_entry);
#Remove existing backup file if exists
unlink("$file_backup") if (-f "$file_backup");
#Make a backup copy just to be safe
copy("$file", "$file_backup") || goto RECOVER_AND_ABORT_A;
#Remove the original file
unlink("$file");
#Create a new PHP file
open(NEW_FILE, ">${file}") || goto RECOVER_AND_ABORT_B;
#Open the original file (backup)
open(OLD_FILE, "${file_backup}") || goto RECOVERY_AND_ABORT_C;
my ($ignore_flag) = 0;
while(<OLD_FILE>) {
my ($tmp) = $_;
if ($tmp =~ /\/\/\<CONFIGURATION\>/) {
print NEW_FILE $tmp;
print NEW_FILE $cfg_entry;
$ignore_flag = 1;
next;
} elsif (($tmp =~ /\/\/\<\/CONFIGURATION\>/) &&
($ignore_flag)) {
print NEW_FILE $tmp;
$ignore_flag = 0;
} elsif (!$ignore_flag) {
print NEW_FILE $tmp;
}
}
close(NEW_FILE);
close(OLD_FILE);
#Double check to ensure new file exists
goto RECOVERY_AND_ABORT_D if (!-f "$file");
#Remove the backup file
unlink("$file_backup") if (-f "$file_backup");
#Give proper permissions
chmod(0604, "$file");
return;
RECOVER_AND_ABORT_A:
#Remove backup if exists
unlink("$file_backup") if (-f "$file_backup");
show_error(
"Can't copy ${file} to ${file_backup}\n" .
"Make sure you have proper permissions or enough space.",
-1);
RECOVER_AND_ABORT_B:
close(NEW_FILE);
#Remove the new file if it was partially created
unlink("$file");
#Move backup file back to its original spot
move("$file_backup", "$file");
if (!-f "$file") {
show_error(
"Could not configure and restore PHP file ${file}\n" .
"Correct the error and reinstall before running " .
"this script again.", -1);
}
show_error(
"Could not configure PHP file ${file}\n" .
"Correct the error and try again.", -1);
RECOVER_AND_ABORT_C:
close(NEW_FILE);
close(OLD_FILE);
#Remove the new file if it was partially created
unlink("$file");
#Move backup file back to its original spot
move("$file_backup", "$file");
if (!-f "$file") {
show_error(
"Could not configure and restore PHP file ${file}\n" .
"Correct the error and reinstall before running " .
"this script again.", -1);
}
show_error(
"Could not configure PHP file ${file}\n" .
"Correct the error and try again.", -1);
RECOVER_AND_ABORT_D:
#Remove the new file if it was partially created
unlink("$file");
#Move backup file back to its original spot
move("$file_backup", "$file");
if (!-f "$file") {
show_error(
"Could not configure and restore PHP file ${file}\n" .
"Correct the error and reinstall before running " .
"this script again.", -1);
}
show_error(
"Could not configure PHP file ${file}\n" .
"Correct the error and try again.", -1);
}
#----------------------------------------------------------------------------
#Configures PHP files to include required absolute class file paths
#----------------------------------------------------------------------------
sub configure_php_file {
my ($file) = shift;
my ($class_file) = shift;
my ($slash) = shift;
my ($web_class) = shift || "";
my ($file_backup) = $file . "." . $$ . ".bak";
#Remove existing backup file if exists
unlink("$file_backup") if (-f "$file_backup");
#Make a backup copy just to be safe
copy("$file", "$file_backup") || goto RECOVER_AND_ABORT_A;
#Remove the original file
unlink("$file");
#Create a new PHP file
open(NEW_FILE, ">${file}") || goto RECOVER_AND_ABORT_B;
#Open the original file (backup)
open(OLD_FILE, "${file_backup}") || goto RECOVERY_AND_ABORT_C;
$class_file =~ s/\\/\\\\/g if ($slash eq "\\");
#New require_once() string
my ($new_require) =
"require_once(\"${class_file}\");\n";
#Also add web class if applicable
if ($web_class ne "") {
$web_class =~ s/\\/\\\\/g if ($slash eq "\\");
$new_require .=
"require_once(\"${web_class}\");\n";
}
my ($ignore_old_require_flag) = 0;
while(<OLD_FILE>) {
my ($tmp) = $_;
#Insert the new one
if (
($tmp =~ /require_once\(/) &&
($tmp =~ /\)\;/) &&
(!$ignore_old_require_flag)) {
print NEW_FILE $new_require;
$ignore_old_require_flag = 1;
#Ignore the old requires
} elsif (
($tmp =~ /require_once\(/) &&
($tmp =~ /\)\;/)) {
next;
} else {
print NEW_FILE $tmp;
}
}
close(NEW_FILE);
close(OLD_FILE);
#Double check to ensure new file exists
goto RECOVERY_AND_ABORT_D if (!-f "$file");
#Remove the backup file
unlink("$file_backup") if (-f "$file_backup");
chmod(0604, "$file");
return;
RECOVER_AND_ABORT_A:
#Remove backup if exists
unlink("$file_backup") if (-f "$file_backup");
show_error(
"Can't copy ${file} to ${file_backup}\n" .
"Make sure you have propery permissions or enough space.",
-1);
RECOVER_AND_ABORT_B:
close(NEW_FILE);
#Remove the new file if it was partially created
unlink("$file");
#Move backup file back to its original spot
move("$file_backup", "$file");
if (!-f "$file") {
show_error(
"Could not configure and restore PHP file ${file}\n" .
"Correct the error and reinstall before running " .
"this script again.", -1);
}
show_error(
"Could not configure PHP file ${file}\n" .
"Correct the error and try again.", -1);
RECOVER_AND_ABORT_C:
close(NEW_FILE);
close(OLD_FILE);
#Remove the new file if it was partially created
unlink("$file");
#Move backup file back to its original spot
move("$file_backup", "$file");
if (!-f "$file") {
show_error(
"Could not configure and restore PHP file ${file}\n" .
"Correct the error and reinstall before running " .
"this script again.", -1);
}
show_error(
"Could not configure PHP file ${file}\n" .
"Correct the error and try again.", -1);
RECOVER_AND_ABORT_D:
#Remove the new file if it was partially created
unlink("$file");
#Move backup file back to its original spot
move("$file_backup", "$file");
if (!-f "$file") {
show_error(
"Could not configure and restore PHP file ${file}\n" .
"Correct the error and reinstall before running " .
"this script again.", -1);
}
show_error(
"Could not configure PHP file ${file}\n" .
"Correct the error and try again.", -1);
}
#----------------------------------------------------------------------------
#Returns the basename of a path
#----------------------------------------------------------------------------
sub get_basename {
my ($path) = shift;
my (@@path_tree) = shift;
if ($path =~ /\\/) {
@@path_tree = split(/\\/, $path);
return($path_tree[$#path_tree]);
} elsif ($path =~ /\//) {
@@path_tree = split(/\//, $path);
return($path_tree[$#path_tree]);
}
return($path);
}
#----------------------------------------------------------------------------
#Verifies given token is an e-mail address. This can be greatly enhanced.
#It just looks for @@ and . with spacing before, in between, and after for
#the time being. Should be good enough though.
#----------------------------------------------------------------------------
sub is_email {
my ($token) = shift;
return(1) if ($token =~ /\w+\@@\w+\.\w+/);
}
#----------------------------------------------------------------------------
#Generic prompt
#----------------------------------------------------------------------------
sub prompt {
my ($prompt) = shift;
my ($required_flag) = shift;
my ($response) = "";
#Iterate until correct response is found
while(1) {
#Show prompt message
print "\n${prompt}\n\n";
#Grab response
$response = <STDIN>;
#Remove leading and trailing white-spaces
trim(\$response);
if (($response) eq "" && ($required_flag)) {
show_error("This parameter requires a value!", 0);
next;
}
last;
}
return($response);
}
#----------------------------------------------------------------------------
#Generic yes or no prompt. Returns 1 for yes and 0 for no.
#----------------------------------------------------------------------------
sub promptyn {
my ($prompt) = shift;
my ($response);
my ($ucresponse);
my (%responses) = (YES => 1, NO => 1, Y => 1, N => 1);
#Iterate until correct response is found
while(1) {
#Show prompt message
print "\n${prompt} [y|n]\n\n";
#Grab response
$response = <STDIN>;
#Clean leading and trailing white spaces
trim(\$response);
if ($response eq "") {
show_error(
"Please respond with a 'y' or 'n' answer!", 0);
next;
} else {
$ucresponse = uc($response);
if (exists($responses{$ucresponse})) {
last;
} else {
show_error(
"Please respond with a 'y' or 'n' answer!", 0);
}
}
}
return(1) if ($ucresponse =~ /^Y/);
return(0);
}
#----------------------------------------------------------------------------
#Generic prompt with default
#----------------------------------------------------------------------------
sub promptx {
my ($prompt) = shift;
my ($default) = shift;
my ($required_flag) = shift;
my ($response) = "";
#Iterate until correct response is found
while(1) {
print "\n${prompt} [${default}]\n\n";
$response = <STDIN>;
chomp($response);
if ($response eq "") {
$response = $default;
last;
} else {
trim(\$response);
if (($response) eq "" && ($required_flag)) {
show_error(
"This parameter requires a value!", 0);
next;
} else {
last;
}
}
}
return("$response");
}
#----------------------------------------------------------------------------
#Prompt for installation directory
#----------------------------------------------------------------------------
sub prompt_installation_directory {
my ($pwd) = cwd();
my ($default_dir) = "";
my ($installation_directory) = "";
if ($pwd) {
if (-d "$pwd") {
show_error(
"You must run this installation script " .
"under the same directory that it resides.", -1)
if ($pwd !~ /utilities$/);
$default_dir = $pwd;
$default_dir =~ s/\/utilities$//;
}
}
if (-d "$default_dir") {
while(1) {
$installation_directory =
promptx(
"Enter the installation directory:\n",
"$default_dir", 1);
if (!-d "$installation_directory") {
show_error(
"'${installation_directory}'" .
" does not exists. Please try again.", 0);
next;
}
last;
}
} else {
while(1) {
$installation_directory =
prompt("Enter the installation directory: ", 1);
if (!-d "$installation_directory") {
show_error(
"'${installation_directory}'" .
" does not exists. Please try again.", 0);
next;
}
last;
}
}
#Remove trailing slash for UNIX systems if exists
$installation_directory =~ s/\/$//;
#Remove trailing slash for Windows systems if exists
$installation_directory =~ s/\\$//;
return("$installation_directory");
}
#----------------------------------------------------------------------------
#Display error message then terminate script
#----------------------------------------------------------------------------
sub show_error {
my ($msg) = shift;
my ($exit_flag) = shift || 0;
print "\nInstallation Error:\n${msg}\n\n";
exit(-1) if ($exit_flag);
return;
}
#----------------------------------------------------------------------------
#Introduction message
#----------------------------------------------------------------------------
sub show_introduction {
print <<EOF;
/////////////////////////////////////////////////////////////////////////////
BAHASA INDONESIA DICTIONARY APPLICATION CONFIGURATION SCRIPT
/////////////////////////////////////////////////////////////////////////////
Copyright (c) 2003 John L. Whiteman
Permission is herby granted, free of charge, to any person obtaining a
copy of this software, data, and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHERE IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING IN THE SOFTWARE.
/////////////////////////////////////////////////////////////////////////////
The purpose of this script is to configure
the Bahasa Indonesia Dictionary PHP files to
run on this host. It doesn't do any
mySQL database configuration, but it will
prompt you for database questions.
This script assumes that your web server is
running on this host. You are responsible
for setting the correct permissions for
these files after configuration.
I've tried to make this script as portable
as possible. If for some reason this script
fails then you will have to configure the files
manually. See documentation for more details.
Please feel free to modify this script to what
best fits your needs.
You can abort at any time by pressing CTRL C.
/////////////////////////////////////////////////////////////////////////////
EOF
return;
}
#----------------------------------------------------------------------------
#Trim leading and trailing white-spaces from string token. Pass token by
#reference only.
#----------------------------------------------------------------------------
sub trim {
my ($token) = shift;
return if (!$token);
$$token =~ s/^\s+//;
$$token =~ s/\s+$//;
return;
}
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
@
1.10
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: October 21, 2003
d153 6
@
1.9
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: October 16, 2003
d116 1
d118 1
d173 3
d177 3
@
1.8
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: October 01, 2003
d108 2
@
1.7
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: September 04, 2003
d433 3
@
1.6
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: August 31, 2003
d94 1
a94 1
"mysql${SLASH}pronunciation.sql" => 0606,
d121 1
d188 3
@
1.5
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: August 21, 2003
d112 1
d160 3
@
1.4
log
@*** empty log message ***
@
text
@d416 1
a416 1
"\nInstallation script completed!\n" .
d507 1
a507 1
"\nInstallation script completed!\n" .
@
1.3
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: August 20, 2003
d82 3
d876 1
a876 1
#It just lloks for @@ and . with spacing before, in between, and after for
d1106 1
a1106 3
print "\n\n";
print "-" x 77;
d1108 23
a1130 1
print "\n";
d1132 1
a1132 2
print <<EOF;
[BAHASA INDONESIA DICTIONARY CONFIGURATION]
d1150 2
a1151 2
Please feel free to modify this script to best
fit your needs.
d1155 2
a1157 4
print "-" x 77;
print "\n";
@
1.2
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: August 18, 2003
d52 1
a52 1
exit;
d101 1
d362 1
a362 1
exit;
d373 1
a373 1
print "Configuring other class file...\n";
d412 4
a415 1
print "\nInstallation script completed!\n\n";
d417 1
a417 1
exit;
d428 2
d444 1
a444 1
"Directory ${web_directory} does not exist.\n" .
d458 1
a458 1
exit;
d463 19
d916 1
a916 1
#Generic yes or no prompt
d1026 1
a1026 1
if ($pwd !~ /bahasa\/utilities$/);
@
1.1
log
@Initial revision
@
text
@d2 35
a1132 1
@
1.1.1.1
log
@Bahasa Indonesia Dictionary
@
text
@@