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
/
make_release_ready.pl,v
< prev
Wrap
Text File
|
2003-10-26
|
38KB
|
1,720 lines
head 1.9;
access;
symbols;
locks; strict;
comment @# @;
1.9
date 2003.10.26.01.53.10; author bule; state Exp;
branches;
next 1.8;
1.8
date 2003.10.17.00.39.35; author bule; state Exp;
branches;
next 1.7;
1.7
date 2003.10.04.18.22.57; author bule; state Exp;
branches;
next 1.6;
1.6
date 2003.09.05.06.42.30; author bule; state Exp;
branches;
next 1.5;
1.5
date 2003.08.31.18.48.47; author bule; state Exp;
branches;
next 1.4;
1.4
date 2003.08.22.06.07.19; author bule; state Exp;
branches;
next 1.3;
1.3
date 2003.08.22.00.46.20; author bule; state Exp;
branches;
next 1.2;
1.2
date 2003.08.21.20.20.57; author bule; state Exp;
branches;
next 1.1;
1.1
date 2003.08.21.06.18.07; author bule; state Exp;
branches;
next ;
desc
@@
1.9
log
@*** empty log message ***
@
text
@#!/usr/bin/perl -w
#/////////////////////////////////////////////////////////////////////////////
#/////////////////////////////////////////////////////////////////////////////
#/ Project Name: Bahasa Indonesia Dictionary
#/ Directory: bahasa/utilities
#/ File Name: make_release_ready.pl
#/ Author(s): John L. Whiteman
#/ Created: August 20, 2003
#/ Modified: October 21, 2003
#/ Description: The purpose of this script is to create a
#/ public release copy of this project.
#/ I typically do my development on a live
#/ installation which means I have installation
#/ specific things like passwords, database user,
#/ administrators (other than default), e-mail
#/ addresses, PHP require paths, and other items
#/ that are not applicable for fresh installations.
#/ This script will first make a copy of my live
#/ system to a release directory of your choice,
#/ then replace various items in the source code
#/ with generic entries required for public release,
#/ fresh installations.
#/
#/ If you are not a developer then it's likely that
#/ you will not be using this script.
#/
#/ You optionally specify -s followed by source directory
#/ and -t followed by target release directory to run
#/ this script in non-interactive mode.
#/
#/ 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 Getopt::Std;
use File::Copy;
my (%args) = ();
getopts("s:t:", \%args);
show_introduction();
if (!$args{s} || !$args{t}) {
while(1) {
my ($response) =
promptyn("Would you like to continue?");
if (!$response) {
print "\nInstallation script terminated!\n\n";
exit(0);
}
last;
}
}
my (%DICTIONARY_CFG) = ();
my ($INSTALLATION_DIRECTORY) = "";
my ($RELEASE_DIRECTORY) = "";
if (!$args{s}) {
$INSTALLATION_DIRECTORY =
prompt_installation_directory();
} else {
$INSTALLATION_DIRECTORY =
prompt_installation_directory($args{s});
}
if (!$args{t}) {
while(1) {
TRY_AGAIN:
$RELEASE_DIRECTORY =
prompt(
"Enter the target release directory: ", 1);
#Remove trailing slash for UNIX systems if exists
$RELEASE_DIRECTORY =~ s/\/$//;
#Remove trailing slash for Windows systems if exists
$RELEASE_DIRECTORY =~ s/\\$//;
if (!-d "$RELEASE_DIRECTORY") {
show_error(
"Target release directory ${RELEASE_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 "Script terminated!\n\n";
exit(0);
}
} else {
my ($response) =
promptyn(
"Is this target release directory " .
"${RELEASE_DIRECTORY} " .
"correct?");
if (!$response) {
$response =
promptyn(
"Would you like to try another " .
"target release " .
"directory?");
goto TRY_AGAIN if ($response);
exit(0);
}
last;
}
}
} else {
$RELEASE_DIRECTORY = $args{t};
#Remove trailing slash for UNIX systems if exists
$RELEASE_DIRECTORY =~ s/\/$//;
#Remove trailing slash for Windows systems if exists
$RELEASE_DIRECTORY =~ s/\\$//;
if (!-d "$RELEASE_DIRECTORY") {
show_error(
"Target release directory ${RELEASE_DIRECTORY} " .
"does not exist.\n" .
"Manually create this directory or use an " .
"existing one before continuing", -1);
}
}
my ($SLASH) = "/";
$SLASH = "\\"
if ($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}tasks.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}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 (@@subdirectories) = (
"${SLASH}backups",
"${SLASH}docs",
"${SLASH}mysql",
"${SLASH}php",
"${SLASH}utilities",
"${SLASH}web");
my ($dictionary_class) =
"${RELEASE_DIRECTORY}${SLASH}php${SLASH}Dictionary.php";
my ($web_class) =
"${RELEASE_DIRECTORY}${SLASH}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};
my($source_path) =
$INSTALLATION_DIRECTORY . $SLASH . $path;
my ($target_path) =
$RELEASE_DIRECTORY . $SLASH . $path;
$modified_manifest{$target_path} = $permissions;
print "${source_path} ";
show_error("\nCan't find ${source_path}", -1) if (!-e "$source_path");
print "[OK]\n";
}
reset(%manifest);
print "Copying ${INSTALLATION_DIRECTORY} => ${RELEASE_DIRECTORY}...\n";
#Create the release subdirectories if they don't exist
foreach(@@subdirectories) {
my ($subdirectory) = "${RELEASE_DIRECTORY}${_}";
if (!-d "$subdirectory") {
my ($rc) = mkdir("$subdirectory", 0700);
show_error(
"Can't create release sub-directory " .
"${subdirectory}: $!", -1) if (!$rc);
chmod(0700, "$subdirectory");
}
}
#Now perform the file copies
foreach(sort(keys(%manifest))) {
my ($path) = $_;
my ($permissions) = $manifest{$path};
my($source_path) =
$INSTALLATION_DIRECTORY . $SLASH . $path;
my ($target_path) =
$RELEASE_DIRECTORY . $SLASH . $path;
#This is a file
if (($path ne "backups") &&
($path ne "docs") &&
($path ne "mysql") &&
($path ne "php") &&
($path ne "utilities") &&
($path ne "web")) {
copy("$source_path", "$target_path");
show_error(
"Can't copy\n${source_path} to \n${target_path}\n" .
"Check file permissions and/or disk space for " .
"possible causes: $!\n") if (!-f "$target_path");
chmod($permissions, "$target_path");
}
}
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) =
$RELEASE_DIRECTORY .
$SLASH . ${_};
my ($class_file) =
$RELEASE_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) =
$RELEASE_DIRECTORY .
$SLASH . ${_};
my ($parent_class) =
$RELEASE_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_CFG{"DB_HOST"} =
"Enter database server name or ip";
$DICTIONARY_CFG{"DB_NAME"} =
"Enter database name";
$DICTIONARY_CFG{"DB_PASSWORD"} =
"Enter database user's password";
$DICTIONARY_CFG{"DB_USER"} =
"Enter database user name";
$DICTIONARY_CFG{"EMAIL"} =
"Enter website's e-maill address";
$DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} =
"Enter project's installation directory";
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, "", 1);
}
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);
}
#Clean various mySQL files that should not have data for fresh installs
print "Preparing mySQL files...\n";
prepare_mysql_files("${RELEASE_DIRECTORY}${SLASH}mysql${SLASH}");
print "Setting default permissions to directories and files...\n";
change_permissions(\%modified_manifest);
print "Installation script done!\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{$_};
$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 generic relative class file paths
#----------------------------------------------------------------------------
sub configure_php_file {
my ($file) = shift;
my ($class_file) = shift;
my ($slash) = shift;
my ($web_class) = shift || "";
my ($class_flag) = shift || 0;
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 "\\");
$class_file = get_basename($class_file);
my ($new_require);
#For web files
if (!$class_flag) {
#New require_once() string
$new_require =
"require_once(\"..${slash}php${slash}${class_file}\");\n";
#For class files
} else {
#New require_once() string
$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(\"..${slash}php${slash}Web.php\");\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);
}
#----------------------------------------------------------------------------
#Prepares various mySQL files for fresh installs
#----------------------------------------------------------------------------
sub prepare_mysql_files {
my ($mysql_directory) = shift;
my ($default_administration) =
"INSERT INTO administration VALUES\n" .
"(\"\", \"offline\", \"0\", " .
"\"Disables dictionary searches when set to 1\");";
my ($default_administrators) =
"INSERT INTO administrators VALUES\n" .
"(\"\", \"administrator\", \"BISlaW8N/JdYE\", " .
"\"1\", \"0\", \"0\");";
#These files should contain nothing but copyright notice
#and possible defaults as seen above
my (@@sql_files) = (
"${mysql_directory}hits.sql",
"${mysql_directory}misses.sql",
"${mysql_directory}requests.sql",
"${mysql_directory}searches.sql",
"${mysql_directory}tasks.sql",
"${mysql_directory}administration.sql",
"${mysql_directory}administrators.sql");
foreach(@@sql_files) {
my ($sql_file) = $_;
my ($copyright) = "";
open(SQL_FILE, "$sql_file") ||
show_error("Can't open ${sql_file}: $!", -1);
while(<SQL_FILE>) {
my ($sql) = $_;
trim(\$sql);
$copyright .= "$sql\n" if ($sql =~ /^\#\//);
}
close(SQL_FILE);
open(NEW_SQL_FILE, ">${sql_file}") ||
show_error("Can't create new ${sql_file}: $!", -1);
print NEW_SQL_FILE "${copyright}";
if ($sql_file =~ /administration\.sql$/) {
print NEW_SQL_FILE $default_administration . "\n";
} elsif ($sql_file =~ /administrators\.sql$/) {
print NEW_SQL_FILE $default_administrators . "\n";
}
close(NEW_SQL_FILE);
}
return;
}
#----------------------------------------------------------------------------
#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 ($installation_directory) = shift || "";
my ($pwd) = cwd();
my ($default_dir) = "";
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 ("$installation_directory" ne "") {
show_error("${installation_directory} does not exist", -1)
if (!-d "$installation_directory");
#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");
}
if (-d "$default_dir") {
while(1) {
$installation_directory =
promptx(
"Enter the source development 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 development 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 DEVELOPER'S MAKE RELEASE 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 create a
public release copy of this project.
I typically do my development on a live
installation which means I have installation
specific things like passwords, database user,
administrators (other than default), e-mail
addresses, PHP require paths, and other items
that are not applicable for fresh installations.
This script will first make a copy of my live
system to a release directory of your choice,
then replace various items in the source code
with generic entries required for public release,
fresh installations.
If you are not a developer than it's likely
you will not be using this script.
You optionally specify -s followed by source directory
and -t followed by target release directory to run
this script in non-interactive mode.
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.8
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: October 16, 2003
d230 1
d232 1
d288 3
d292 3
@
1.7
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: October 01, 2003
d222 2
@
1.6
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: September 04, 2003
d934 1
a934 1
"INSERT INTO administrators VALUES\n" .
@
1.5
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: August 31, 2003
d24 1
a24 1
#/ If you are not a developer than it's likely
d208 1
a208 1
"mysql${SLASH}pronunciation.sql" => 0606,
d235 1
d303 3
@
1.4
log
@*** empty log message ***
@
text
@d9 1
a9 1
#/ Modified: August 21, 2003
d226 1
d275 3
@
1.3
log
@*** empty log message ***
@
text
@d531 3
a533 1
purge_mysql_files("${RELEASE_DIRECTORY}${SLASH}mysql");
d919 1
a919 1
#Purges various mySQL files that should not contain data for fresh installs
d921 1
a921 1
sub purge_mysql_files {
d925 26
d952 30
@
1.2
log
@*** empty log message ***
@
text
@d26 4
a29 1
#/
d54 1
d57 4
d63 3
a65 1
while(1) {
d67 2
a68 2
my ($response) =
promptyn("Would you like to continue?");
d70 1
a70 1
if (!$response) {
d72 1
a72 1
print "\nInstallation script terminated!\n\n";
d74 4
a77 1
exit(0);
a78 2
last;
d82 4
d87 2
a88 2
my ($INSTALLATION_DIRECTORY) =
prompt_installation_directory();
d90 9
a98 1
while(1) {
d102 3
a104 4
my ($RELEASE_DIRECTORY) =
prompt(
"What is the name of the release directory " .
"to copy the project for release?", 1);
d106 2
a107 2
#Remove trailing slash for UNIX systems if exists
$RELEASE_DIRECTORY =~ s/\/$//;
d109 2
a110 2
#Remove trailing slash for Windows systems if exists
$RELEASE_DIRECTORY =~ s/\\$//;
d112 1
a112 1
if (!-d "$RELEASE_DIRECTORY") {
d114 6
a119 4
show_error(
"Release directory ${RELEASE_DIRECTORY} does not exist.\n" .
"Manually create this directory or use an existing one\n" .
"before continuing. I'll wait.", 0);
d121 2
a122 2
my ($response) =
promptyn("Try again?", 1);
d124 1
a124 1
if (!$response) {
d126 1
a126 1
print "Script terminated!\n\n";
d128 25
a152 1
exit(0);
d154 1
d156 1
a156 1
} else {
d158 1
a158 3
my ($response) =
promptyn(
"Is this release directory ${RELEASE_DIRECTORY} correct?");
d160 2
a161 1
if (!$response) {
d163 2
a164 3
$response =
promptyn(
"Would you like to try another release directory?");
d166 1
a166 1
goto TRY_AGAIN if ($response);
d168 5
a172 2
exit(0);
}
d196 3
d218 1
d240 1
d327 1
a327 1
my ($subdirectories) = (
d336 1
a336 1
"${INSTALLATION_DIRECTORY}${SLASH}php${SLASH}Dictionary.php";
d339 1
a339 1
"${INSTALLATION_DIRECTORY}${SLASH}php${SLASH}Web.php";
d354 1
a354 1
$path =
d357 2
a358 1
$modified_manifest{$path} = $permissions;
d360 1
a360 1
print "${path} ";
d362 3
a364 1
show_error("\nCan't find ${path}", -1) if (!-e "$path");
d369 23
a391 1
#Now copy these files and directories to installation directory
d393 1
d395 1
d397 2
d400 21
d431 1
a431 1
$INSTALLATION_DIRECTORY .
d435 1
a435 1
$INSTALLATION_DIRECTORY .
d459 1
a459 1
$INSTALLATION_DIRECTORY .
d463 1
a463 1
$INSTALLATION_DIRECTORY .
d531 1
a531 1
purge_mysql_files("${INSTALLATION_DIRECTORY}${SLASH}mysql");
d537 1
a537 1
print "\nInstallation script completed!\n";
d1060 1
a1062 1
my ($installation_directory) = "";
d1079 16
d1101 1
a1101 1
"Enter the directory to make changes:\n",
d1123 1
a1123 1
"Enter the directory to make changes: ", 1);
d1165 1
a1165 1
print "\n\n";
d1167 23
a1189 1
print "-" x 77;
d1191 1
a1191 4
print "\n";
print <<EOF;
[BAHASA INDONESIA DICTIONARY DEVELOPER'S MAKE RELEASE SCRIPT]
d1210 3
a1212 16
The purpose of this script is to format the source
code and data in such a fashion that it can be
released to the general public for distribution.
This script is really a developer's script. I do
most of development on a live system which means
my code contains things like passwords and
require paths that are not applicable for a
generic release. This script replaces these
items with more generic entries required for
clean installation. If you are not a developer then
it's likely you will not be using this script.
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.
d1214 2
a1215 2
Please feel free to modify this script to best
fit your needs.
d1219 2
a1221 4
print "-" x 77;
print "\n";
@
1.1
log
@*** empty log message ***
@
text
@d9 17
a25 12
#/ Modified: August 20, 2003
#/ Description: The purpose of this script is to format the source
#/ code and data in such a fashion that it can be
#/ released to the general public for distribution.
#/ This script is really a developer's script. I do
#/ most of development on a live system which means
#/ my code contains things like passwords and
#/ require paths that are not applicable for a
#/ generic release. This script replaces these
#/ items with more generic entries required for
#/ clean installation. If you are not a developer then
#/ it's likely you will not be using this script.
d75 52
d272 8
d311 6
d425 3
d432 1
a432 2
print
"\nInstallation script completed!\n";
d812 1
a812 3
#Verifies given token is an e-mail address. This can be greatly enhanced.
#It just lloks for @@ and . with spacing before, in between, and after for
#the time being. Should be good enough though.
d814 1
a814 1
sub is_email {
d816 1
a816 1
my ($token) = shift;
d818 3
a820 1
return(1) if ($token =~ /\w+\@@\w+\.\w+/);
d1051 18
a1068 1
[BAHASA INDONESIA DICTIONARY DEVELOPER'S MAKE RELEASE]
@