Qual: Add perltidy & perlcritic + updates to fix notices. (#36370)

* Qual: Add pre-commit hooks for Perl code formatting and linting

- Added perltidy hook to format Perl code
- Added perlcritic hook to lint Perl code

* Qual: Update file opening syntax in build scripts (perltidy)

The changes update the syntax for opening files in several build scripts to use the three-argument form of the `open` function, which is more secure and recommended in modern Perl practices.

* Qual: Improve file handling and add strict/warnings pragmas (perlcritic)

The changes include:
- Adding 'use strict' and 'use warnings' pragmas to enforce better coding practices
- Improving file handling by using lexical filehandles (my $IN, my $SPECFROM, etc.)
- Fixing file opening and closing operations to use proper error handling
- Updating various file operations to use the new lexical filehandles
- Fixing indentation and formatting issues in the code

* Qual: Add strict and warnings pragmas to Perl scripts (perlcritic)

The changes add 'use strict;' and 'use warnings;' pragmas
- dev/build/doxygen/dolibarr-doxygen-build.pl
- dev/build/doxygen/dolibarr-doxygen-filter.pl
- dev/build/doxygen/dolibarr-doxygen-getversion.pl
- dev/build/gource/getavatars.pl
- dev/tools/dolibarr-mysql2pgsql.pl

* Qual: Add Perl no critic pragmas (perlcritic)

- Ignore some perlcritic notices

* Qual: Improve code formatting and readability

Perltidy:

- Indentation and spacing
- Improved variable naming and alignment
- Better code organization and structure
- Enhanced readability of conditional statements and loops

These changes do not alter the functionality of the script but make it more maintainable and easier to understand.

* qual: Exclude virtualmin from perltidy and perlcritic hooks

Exclude the virtualmin directory from both perltidy and perlcritic hooks due to specific reasons mentioned in the comment. This change ensures that these hooks do not process files in the virtualmin directory.

* Qual: Add installation of perltidy and perlcritic for pre-commit workflow

This commit adds the installation of perltidy and perlcritic as part of the pre-commit hooks workflow.

* Fix: Update version detection in dolibarr-doxygen-build.pl

- Add support for detecting version from DOL_MAJOR_VERSION and DOL_MINOR_VERSION constants
- Fix undefined variable issue in version detection

* Fix: Update getavatars.pl to use HTTPS and reverse git log

- Changed the URL from HTTP to HTTPS for Gravatar
- Added `--reverse` flag to git log command to process commits in chronological order (faster)
- Updated error message to indicate .git repository instead of .git directory (+ correct test)

* fix: Correct spelling in error messages and prompts

- Fixed typo in error message for missing environment variables
- Corrected spelling in prompt for module name input
- Improved clarity in comment for target checking
This commit is contained in:
MDW
2025-11-23 01:52:07 +01:00
committed by GitHub
parent 54134eb0fa
commit 63a78d8c00
10 changed files with 2266 additions and 1682 deletions

View File

@@ -109,6 +109,10 @@ jobs:
coverage: none # disable xdebug, pcov
tools: phpcs
# Install perltidy and perlcritic
- name: Install perltidy and perlcritic
run: sudo apt-get update && sudo apt-get install -y perltidy libperl-critic-perl
# Run all the precommit tools (defined into pre-commit-config.yaml).
# We can force exclusion of some of them here.
- name: Run pre-commit hooks

View File

@@ -274,3 +274,21 @@ repos:
|htdocs/install/pgsql/functions/functions.*\.sql
|htdocs/modulebuilder/template/sql/.*\.sql
)$
- repo: https://github.com/perltidy/perltidy
rev: '20250105.03'
hooks:
- id: perltidy
# virtualmin excuded - reason https://github.com/Dolibarr/dolibarr/pull/36370#issuecomment-3565101823
exclude: (?x)^
(dev/build/perl/virtualmin/dolibarr.pl
)$
args: [ --tabs, --nola ]
- repo: https://github.com/henryykt/pre-commit-perl
rev: v0.0.5
hooks:
- id: perlcritic
# virtualmin excuded - reason https://github.com/Dolibarr/dolibarr/pull/36370#issuecomment-3565101823
exclude: (?x)^
(dev/build/perl/virtualmin/dolibarr.pl
)$

View File

@@ -1,54 +1,94 @@
#!/usr/bin/perl
##no critic (InputOutput::RequireBriefOpen)
use strict;
use warnings;
#--------------------------------------------------------------------
# Start the generation of the development documentation with doxygen
#--------------------------------------------------------------------
# Determine the patho of this script
($DIR=$0) =~ s/([^\/\\]+)$//;
$DIR||='.';
( my $DIR = $0 ) =~ s/([^\/\\]+)$//;
$DIR ||= '.';
$DIR =~ s/([^\/\\])[\\\/]+$/$1/;
$OPTIONS="";
my $OPTIONS = "";
#$OPTIONS="-d Preprocessor";
$CONFFILE="dolibarr-doxygen.doxyfile";
my $CONFFILE = "dolibarr-doxygen.doxyfile";
use Cwd;
my $dir = getcwd;
print "Current dir is: $dir\n";
#print "Running dir for doxygen must be: $DIR\n";
if (! -s "dev/build/doxygen/$CONFFILE")
{
print "Error: current directory for building Dolibarr doxygen documentation is not correct.\n";
if ( !-s "dev/build/doxygen/$CONFFILE" ) {
print
"Error: current directory for building Dolibarr doxygen documentation is not correct.\n";
print "\n";
print "Change your current directory then, to launch the script, run:\n";
print '> perl .\dolibarr-doxygen-build.pl (on Windows)'."\n";
print '> perl ../dolibarr-doxygen-build.pl (on Linux or BSD)'."\n";
print '> perl .\dolibarr-doxygen-build.pl (on Windows)' . "\n";
print '> perl ../dolibarr-doxygen-build.pl (on Linux or BSD)' . "\n";
sleep 4;
exit 1;
}
$SOURCE=".";
my $SOURCE = ".";
# Get version $MAJOR, $MINOR and $BUILD
$result = open( IN, "< " . $SOURCE . "/htdocs/filefunc.inc.php" );
if ( !$result ) { die "Error: Can't open descriptor file " . $SOURCE . "/htdocs/filefunc.inc.php\n"; }
while (<IN>) {
if ( $_ =~ /define\('DOL_VERSION', '([\d\.a-z\-]+)'\)/ ) { $PROJVERSION = $1; break; }
my $result = open( my $IN, "<", $SOURCE . "/htdocs/filefunc.inc.php" );
if ( !$result ) {
die "Error: Can't open descriptor file " . $SOURCE
. "/htdocs/filefunc.inc.php\n";
}
close IN;
($MAJOR,$MINOR,$BUILD)=split(/\./,$PROJVERSION,3);
if ($MINOR eq '') { die "Error can't detect version into ".$SOURCE . "/htdocs/filefunc.inc.php"; }
my $PROJVERSION = "";
while (<$IN>) {
if ( $_ =~ /define\('DOL_VERSION', '([\d\.a-z\-]+)'\)/ ) {
$PROJVERSION = $1;
last;
}
}
close $IN;
if ( $PROJVERSION eq "" ) {
my $DOL_MAJOR_VERSION;
my $DOL_MINOR_VERSION;
my @VERSION_FILES = ( "filefunc.inc.php", "version.inc.php" );
foreach my $file (@VERSION_FILES) {
$result = open( my $IN, "<", $SOURCE . "/htdocs/$file" );
if ( !$result ) {
die "Error: Can't open descriptor file " . $SOURCE
. "/htdocs/$file\n";
}
while (<$IN>) {
if ( $_ =~ /define\('DOL_MAJOR_VERSION', '([\d\.a-z\-]+)'\)/ ) {
$DOL_MAJOR_VERSION = $1;
}
if ( $_ =~ /define\('DOL_MINOR_VERSION', '([\d\.a-z\-]+)'\)/ ) {
$DOL_MINOR_VERSION = $1;
}
}
close $IN;
}
$PROJVERSION = $DOL_MAJOR_VERSION . '.' . $DOL_MINOR_VERSION;
}
$version=$MAJOR.".".$MINOR.".".$BUILD;
( my $MAJOR, my $MINOR, my $BUILD ) = split( /\./, $PROJVERSION, 3 );
if ( !defined($MINOR) || $MINOR eq '' ) {
die "Error can't detect version from " . $SOURCE
. "/htdocs/filefunc.inc.php";
}
my $version = $MAJOR . "." . $MINOR . "." . $BUILD;
print "Running doxygen for version ".$version.", please wait...\n";
print "cat dev/build/doxygen/$CONFFILE | sed -e 's/x\.y\.z/".$version."/' | doxygen $OPTIONS - 2>&1\n";
$result=`cat dev/build/doxygen/$CONFFILE | sed -e 's/x\.y\.z/$version/' | doxygen $OPTIONS - 2>&1`;
print "Running doxygen for version " . $version . ", please wait...\n";
print "cat dev/build/doxygen/$CONFFILE | sed -e 's/x\.y\.z/" . $version
. "/' | doxygen $OPTIONS - 2>&1\n";
$result =
`cat dev/build/doxygen/$CONFFILE | sed -e 's/x\.y\.z/$version/' | doxygen $OPTIONS - 2>&1`;
print $result;

View File

@@ -4,85 +4,79 @@
# on PHP source files before running Doxygen.
# \author Laurent Destailleur
#--------------------------------------------------------------------
## no critic (InputOutput::RequireBriefOpen)
use strict;
use warnings;
# Usage: dolibarr-doxygen-filter.pl pathtofilefromdolibarrroot
$file=$ARGV[0];
if (! $file)
{
my $file = $ARGV[0];
if ( !$file ) {
print "Usage: dolibarr-doxygen-filter.pl pathtofilefromdolibarrroot\n";
exit;
}
open(FILE,$file) || die "Failed to open file $file";
while (<FILE>)
{
if ($_ =~ /\\version\s/i)
{
open( my $fh, "<", $file ) || die "Failed to open file $file";
while (<$fh>) {
if ( $_ =~ /\\version\s/i ) {
$_ =~ s/\$Id://i;
$_ =~ s/(Exp|)\s\$$//i;
$_ =~ s/(\\version\s+)[^\s]+\s/$1/i;
$_ =~ s/(\w)\s(\w)/$1_$2/g;
}
$_ =~ s/exit\s*;/exit(0);/i;
$i=0;
$len=length($_);
$s="";
$insidequote=0;
$insidedquote=0;
$ignore="";
while ($i < $len)
{
$c=substr($_,$i,1);
if ($c eq "\\")
{
if ($insidequote) { $ignore="'"; };
if ($insidedquote) { $ignore="\""; };
my $i = 0;
my $len = length($_);
my $s = "";
my $insidequote = 0;
my $insidedquote = 0;
my $ignore = "";
while ( $i < $len ) {
my $c = substr( $_, $i, 1 );
if ( $c eq "\\" ) {
if ($insidequote) { $ignore = "'"; }
if ($insidedquote) { $ignore = "\""; }
}
else
{
if ($c eq "'")
{
if (! $insidedquote)
{
$c="\"";
else {
if ( $c eq "'" ) {
if ( !$insidedquote ) {
$c = "\"";
#print "X".$ignore;
if ($ignore ne "'")
{
if ( $ignore ne "'" ) {
#print "Z".$ignore;
$insidequote++;
if ($insidequote == 2)
{
$insidequote=0;
if ( $insidequote == 2 ) {
$insidequote = 0;
}
}
}
#print "X".$insidequote;
}
elsif ($c eq "\"")
{
elsif ( $c eq "\"" ) {
#print "Y".$insidequote;
if ($insidequote)
{
$c="'";
if ($insidequote) {
$c = "'";
}
else
{
if ($ignore ne "\"")
{
else {
if ( $ignore ne "\"" ) {
$insidedquote++;
if ($insidedquote == 2)
{
$insidedquote=0;
if ( $insidedquote == 2 ) {
$insidedquote = 0;
}
}
}
}
$ignore="";
$ignore = "";
}
$s.=$c;
$s .= $c;
$i++;
}
print $s;
}
close(FILE);
close($fh);

View File

@@ -1,4 +1,7 @@
#!/usr/bin/perl
use strict;
use warnings;
#--------------------------------------------------------------------
# Script to get version of a source file
# Does not work with cygwin cvs command on Windows.
@@ -7,15 +10,18 @@
# Usage: dolibarr-doxygen-getversion.pl pathtofilefromdolibarrroot
$file=$ARGV[0];
if (! $file)
{
$file = $ARGV[0];
if ( !$file ) {
print "Usage: dolibarr-doxygen-getversion.pl pathtofilefromdolibarrroot\n";
exit;
}
$commande='cvs status "'.$file.'" | sed -n \'s/^[ \]*Working revision:[ \t]*\([0-9][0-9\.]*\).*/\1/p\'';
$commande =
'cvs status "'
. $file
. '" | sed -n \'s/^[ \]*Working revision:[ \t]*\([0-9][0-9\.]*\).*/\1/p\'';
#print $commande;
$result=`$commande 2>&1`;
$result = `$commande 2>&1`;
print $result;

View File

@@ -1,4 +1,5 @@
#!/usr/bin/perl
## no critic (InputOutput::RequireBriefOpen)
#fetch Gravatars
use strict;
@@ -10,17 +11,18 @@ use Digest::MD5 qw(md5_hex);
my $size = 90;
my $output_dir = './avatars';
die("no .git/ directory found in current path\n") unless -d './avatars';
die("no .git repository found in current path\n") unless -r './.git';
mkdir($output_dir) unless -d $output_dir;
open(GITLOG, q/git log --pretty=format:"%ae|%an" |/) or die("failed to read git-log: $!\n");
open( my $GITLOG, '-|', q/git log --pretty=format:"%ae|%an" --reverse/ )
or die("failed to read git-log: $!\n");
my %processed_authors;
while(<GITLOG>) {
while (<$GITLOG>) {
chomp;
my($email, $author) = split(/\|/, $_);
my ( $email, $author ) = split( /\|/, $_ );
next if $processed_authors{$author}++;
@@ -31,18 +33,22 @@ while(<GITLOG>) {
#try and fetch image
my $grav_url = "http://www.gravatar.com/avatar/".md5_hex(lc $email)."?d=404&size=".$size;
my $grav_url =
"https://www.gravatar.com/avatar/"
. md5_hex( lc $email )
. "?d=404&size="
. $size;
warn "fetching image for '$author' $email ($grav_url)...\n";
my $rc = getstore($grav_url, $author_image_file);
my $rc = getstore( $grav_url, $author_image_file );
sleep(1);
if($rc != 200) {
if ( $rc != 200 ) {
unlink($author_image_file);
next;
}
}
close GITLOG;
close $GITLOG;

File diff suppressed because it is too large Load Diff

View File

@@ -5,41 +5,48 @@
# \author (c)2005-2014 Laurent Destailleur <eldy@users.sourceforge.net>
# \contributor (c)2017 Nicolas ZABOURI <info@inovea-conseil.com>
#----------------------------------------------------------------------------
## no critic (InputOutput::ProhibitExplicitStdin,InputOutput::RequireBriefOpen)
use strict;
use warnings;
use Cwd;
use Term::ANSIColor;
$OWNER="ldestailleur";
$GROUP="ldestailleur";
$OWNER = "ldestailleur";
$GROUP = "ldestailleur";
@LISTETARGET=("ZIP"); # Possible packages
%REQUIREMENTTARGET=( # Tool requirement for each package
"TGZ"=>"tar",
"ZIP"=>"7z"
@LISTETARGET = ("ZIP"); # Possible packages
%REQUIREMENTTARGET = ( # Tool requirement for each package
"TGZ" => "tar",
"ZIP" => "7z"
);
%ALTERNATEPATH=(
);
%ALTERNATEPATH = ();
use vars qw/ $REVISION $VERSION /;
$REVISION='1.0';
$VERSION="3.5 (build $REVISION)";
$REVISION = '1.0';
$VERSION = "3.5 (build $REVISION)";
#------------------------------------------------------------------------------
# MAIN
#------------------------------------------------------------------------------
($DIR=$0) =~ s/([^\/\\]+)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1;
$DIR||='.'; $DIR =~ s/([^\/\\])[\\\/]+$/$1/;
( $DIR = $0 ) =~ s/([^\/\\]+)$//;
( $PROG = $1 ) =~ s/\.([^\.]*)$//;
$Extension = $1;
$DIR ||= '.';
$DIR =~ s/([^\/\\])[\\\/]+$/$1/;
# Detect OS type
# --------------
if ("$^O" =~ /linux/i || (-d "/etc" && -d "/var" && "$^O" !~ /cygwin/i)) { $OS='linux'; $CR=''; }
elsif (-d "/etc" && -d "/Users") { $OS='macosx'; $CR=''; }
elsif ("$^O" =~ /cygwin/i || "$^O" =~ /win32/i) { $OS='windows'; $CR="\r"; }
if (! $OS) {
if ( "$^O" =~ /linux/i || ( -d "/etc" && -d "/var" && "$^O" !~ /cygwin/i ) ) {
$OS = 'linux';
$CR = '';
}
elsif ( -d "/etc" && -d "/Users" ) { $OS = 'macosx'; $CR = ''; }
elsif ( "$^O" =~ /cygwin/i || "$^O" =~ /win32/i ) {
$OS = 'windows';
$CR = "\r";
}
if ( !$OS ) {
print "$PROG.$Extension was not able to detect your OS.\n";
print "Can't continue.\n";
print "$PROG.$Extension aborted.\n";
@@ -49,179 +56,237 @@ if (! $OS) {
# Define buildroot
# ----------------
if ($OS =~ /linux/) {
$TEMP=$ENV{"TEMP"}||$ENV{"TMP"}||"/tmp";
if ( $OS =~ /linux/ ) {
$TEMP = $ENV{"TEMP"} || $ENV{"TMP"} || "/tmp";
}
if ($OS =~ /macos/) {
$TEMP=$ENV{"TEMP"}||$ENV{"TMP"}||"/tmp";
if ( $OS =~ /macos/ ) {
$TEMP = $ENV{"TEMP"} || $ENV{"TMP"} || "/tmp";
}
if ($OS =~ /windows/) {
$TEMP=$ENV{"TEMP"}||$ENV{"TMP"}||"c:/temp";
$PROGPATH=$ENV{"ProgramFiles"};
if ( $OS =~ /windows/ ) {
$TEMP = $ENV{"TEMP"} || $ENV{"TMP"} || "c:/temp";
$PROGPATH = $ENV{"ProgramFiles"};
}
if (! $TEMP || ! -d $TEMP) {
if ( !$TEMP || !-d $TEMP ) {
print "Error: A temporary directory can not be find.\n";
print "Check that TEMP or TMP environment variable is set correctly.\n";
print "$PROG.$Extension aborted.\n";
sleep 2;
exit 2;
}
$BUILDROOT="$TEMP/dolibarr-buildroot";
$BUILDROOT = "$TEMP/dolibarr-buildroot";
my $copyalreadydone = 0;
my $batch = 0;
my $copyalreadydone=0;
my $batch=0;
for (0..@ARGV-1) {
if ($ARGV[$_] =~ /^-*target=(\w+)/i) { $target=$1; $batch=1; }
if ($ARGV[$_] =~ /^-*desti=(.+)/i) { $DESTI=$1; }
if ($ARGV[$_] =~ /^-*prefix=(.+)/i) {
$PREFIX=$1;
$FILENAMESNAPSHOT.="-".$PREFIX;
for ( 0 .. @ARGV - 1 ) {
if ( $ARGV[$_] =~ /^-*target=(\w+)/i ) { $target = $1; $batch = 1; }
if ( $ARGV[$_] =~ /^-*desti=(.+)/i ) { $DESTI = $1; }
if ( $ARGV[$_] =~ /^-*prefix=(.+)/i ) {
$PREFIX = $1;
$FILENAMESNAPSHOT .= "-" . $PREFIX;
}
}
$SOURCE="$DIR/../..";
$DESTI="$SOURCE/dev/build";
if ($ENV{"DESTIMODULES"}) { $DESTI = $ENV{"DESTIMODULES"}; } # Force output dir if env DESTIMODULES is defined
$NEWDESTI=$DESTI;
$SOURCE = "$DIR/../..";
$DESTI = "$SOURCE/dev/build";
if ( $ENV{"DESTIMODULES"} ) {
$DESTI = $ENV{"DESTIMODULES"};
} # Force output dir if env DESTIMODULES is defined
$NEWDESTI = $DESTI;
print "Makepack for modules version $VERSION\n";
print "Source directory: $SOURCE\n";
print "Target directory: $NEWDESTI\n";
# Ask module
print "Enter name for your module (mymodule, mywonderfulmondule, ... or 'all') : ";
$PROJECTINPUT=<STDIN>;
print
"Enter name for your module (mymodule, mywonderfullmodule, ... or 'all') : ";
my $PROJECTINPUT = <STDIN>;
chomp($PROJECTINPUT);
print "Move to ".$DIR." directory.\n";
print "Move to " . $DIR . " directory.\n";
chdir($DIR);
my @PROJECTLIST=();
if ($PROJECTINPUT eq "all")
{
opendir(DIR, $DIR) || return;
local @rv = grep { /^makepack\-(.*)\.conf$/ } sort readdir(DIR);
closedir(DIR);
foreach my $xxx (0..@rv-1) {
if ($rv[$xxx] =~ /^makepack\-(.*)\.conf$/)
{
@PROJECTLIST[$xxx]=$1;
my @PROJECTLIST = ();
if ( $PROJECTINPUT eq "all" ) {
opendir( my $DIR, $DIR ) or return;
local @rv = grep { /^makepack\-(.*)\.conf$/ } sort readdir($DIR);
closedir($DIR);
foreach my $xxx ( 0 .. @rv - 1 ) {
if ( $rv[$xxx] =~ /^makepack\-(.*)\.conf$/ ) {
@PROJECTLIST[$xxx] = $1;
}
}
}
else
{
@PROJECTLIST=($PROJECTINPUT);
else {
@PROJECTLIST = ($PROJECTINPUT);
}
# Loop on each projects
foreach my $PROJECT (@PROJECTLIST) {
$PROJECTLC=lc($PROJECT);
$PROJECTLC = lc($PROJECT);
if (! -f "makepack-".$PROJECT.".conf")
{
print "Error: can't open conf file makepack-".$PROJECT.".conf\n";
if ( !-f "makepack-" . $PROJECT . ".conf" ) {
print "Error: can't open conf file makepack-" . $PROJECT . ".conf\n";
print "\n";
print "For help on building a module package, see web page\n";
print "http://wiki.dolibarr.org/index.php/Module_development#Create_a_package_to_distribute_and_install_your_module\n";
print
"http://wiki.dolibarr.org/index.php/Module_development#Create_a_package_to_distribute_and_install_your_module\n";
print "makepack-dolibarrmodule.pl aborted.\n";
sleep 2;
exit 2;
}
# Get version $MAJOR, $MINOR and $BUILD
print "Version detected for module ".$PROJECT." in file ".$SOURCE."/htdocs/".$PROJECTLC."/core/modules/mod".ucfirst($PROJECT).".class.php";
$result=open(IN,"<".$SOURCE."/htdocs/".$PROJECTLC."/core/modules/mod".ucfirst($PROJECT).".class.php");
$custom=false;
if (! $result) {
$result=open(IN,"<".$SOURCE."/htdocs/custom/".$PROJECTLC."/core/modules/mod".ucfirst($PROJECT).".class.php");
if (! $result) {
die "Error: Can't open descriptor file ".$SOURCE."/htdocs/(or /htdocs/custom/)".$PROJECTLC."/core/modules/mod".ucfirst($PROJECT).".class.php for reading.\n";
}else{
print "Version detected for module "
. $PROJECT
. " in file "
. $SOURCE
. "/htdocs/"
. $PROJECTLC
. "/core/modules/mod"
. ucfirst($PROJECT)
. ".class.php";
$result = open(
my $IN,
"<",
$SOURCE
. "/htdocs/"
. $PROJECTLC
. "/core/modules/mod"
. ucfirst($PROJECT)
. ".class.php"
);
$custom = false;
if ( !$result ) {
$result = open(
my $IN,
"<",
$SOURCE
. "/htdocs/custom/"
. $PROJECTLC
. "/core/modules/mod"
. ucfirst($PROJECT)
. ".class.php"
);
if ( !$result ) {
die "Error: Can't open descriptor file "
. $SOURCE
. "/htdocs/(or /htdocs/custom/)"
. $PROJECTLC
. "/core/modules/mod"
. ucfirst($PROJECT)
. ".class.php for reading.\n";
}
}
else {
$custom = true;
}
while (<$IN>) {
if ( $_ =~ /this->version\s*=\s*'([\d\.]+)'/ ) {
$PROJVERSION = $1;
break;
}
while(<IN>)
{
if ($_ =~ /this->version\s*=\s*'([\d\.]+)'/) { $PROJVERSION=$1; break; }
}
close IN;
print $PROJVERSION."\n";
close $IN;
print $PROJVERSION. "\n";
($MAJOR,$MINOR,$BUILD)=split(/\./,$PROJVERSION,3);
if ($MINOR eq '')
{
print "Enter value for minor version for module ".$PROJECT.": ";
$MINOR=<STDIN>;
( $MAJOR, $MINOR, $BUILD ) = split( /\./, $PROJVERSION, 3 );
if ( $MINOR eq '' ) {
print "Enter value for minor version for module " . $PROJECT . ": ";
$MINOR = <STDIN>;
chomp($MINOR);
}
$FILENAME="$PROJECTLC";
$FILENAMETGZ="module_$PROJECTLC-$MAJOR.$MINOR".($BUILD ne ''?".$BUILD":"");
$FILENAMEZIP="module_$PROJECTLC-$MAJOR.$MINOR".($BUILD ne ''?".$BUILD":"");
if (-d "/usr/src/redhat") {
# redhat
$RPMDIR="/usr/src/redhat";
}
if (-d "/usr/src/RPM") {
# mandrake
$RPMDIR="/usr/src/RPM";
}
$FILENAME = "$PROJECTLC";
$FILENAMETGZ =
"module_$PROJECTLC-$MAJOR.$MINOR" . ( $BUILD ne '' ? ".$BUILD" : "" );
$FILENAMEZIP =
"module_$PROJECTLC-$MAJOR.$MINOR" . ( $BUILD ne '' ? ".$BUILD" : "" );
if ( -d "/usr/src/redhat" ) {
# redhat
$RPMDIR = "/usr/src/redhat";
}
if ( -d "/usr/src/RPM" ) {
# mandrake
$RPMDIR = "/usr/src/RPM";
}
# Choose package targets
#-----------------------
$target="ZIP"; # Dolibarr modules are this format
$CHOOSEDTARGET{uc($target)}=1;
$target = "ZIP"; # Dolibarr modules are this format
$CHOOSEDTARGET{ uc($target) } = 1;
# Test if requirement is ok
#--------------------------
foreach my $target (keys %CHOOSEDTARGET) {
foreach my $req (split(/[,\s]/,$REQUIREMENTTARGET{$target})) {
foreach my $target ( keys %CHOOSEDTARGET ) {
foreach my $req ( split( /[,\s]/, $REQUIREMENTTARGET{$target} ) ) {
# Test
print "Test requirement for target $target: Search '$req'... ";
$ret=`"$req" 2>&1`;
$coderetour=$?; $coderetour2=$coderetour>>8;
if ($coderetour != 0 && (($coderetour2 == 1 && $OS =~ /windows/ && $ret !~ /Usage/i) || ($coderetour2 == 127 && $OS !~ /windows/)) && $PROGPATH) {
$ret = `"$req" 2>&1`;
$coderetour = $?;
$coderetour2 = $coderetour >> 8;
if (
$coderetour != 0
&& (
(
$coderetour2 == 1
&& $OS =~ /windows/
&& $ret !~ /Usage/i
)
|| ( $coderetour2 == 127 && $OS !~ /windows/ )
)
&& $PROGPATH
)
{
# Not found error, we try in PROGPATH
$ret=`"$PROGPATH/$ALTERNATEPATH{$req}/$req\" 2>&1`;
$coderetour=$?; $coderetour2=$coderetour>>8;
$REQUIREMENTTARGET{$target}="$PROGPATH/$ALTERNATEPATH{$req}/$req";
$ret = `"$PROGPATH/$ALTERNATEPATH{$req}/$req\" 2>&1`;
$coderetour = $?;
$coderetour2 = $coderetour >> 8;
$REQUIREMENTTARGET{$target} =
"$PROGPATH/$ALTERNATEPATH{$req}/$req";
}
if ($coderetour != 0 && (($coderetour2 == 1 && $OS =~ /windows/ && $ret !~ /Usage/i) || ($coderetour2 == 127 && $OS !~ /windows/))) {
if (
$coderetour != 0
&& (
(
$coderetour2 == 1
&& $OS =~ /windows/
&& $ret !~ /Usage/i
)
|| ( $coderetour2 == 127 && $OS !~ /windows/ )
)
)
{
# Not found error
print "Not found\nCan't build target $target. Requirement '$req' not found in PATH\n";
$CHOOSEDTARGET{$target}=-1;
print
"Not found\nCan't build target $target. Requirement '$req' not found in PATH\n";
$CHOOSEDTARGET{$target} = -1;
last;
} else {
}
else {
# Pas erreur ou erreur autre que programme absent
print " Found ".$REQUIREMENTTARGET{$target}."\n";
print " Found " . $REQUIREMENTTARGET{$target} . "\n";
}
}
}
print "\n";
# Check if there is at least on target to build
# Check if there is at least one target to build
#----------------------------------------------
$nboftargetok=0;
$nboftargetneedbuildroot=0;
$nboftargetneedcvs=0;
foreach my $target (keys %CHOOSEDTARGET) {
if ($CHOOSEDTARGET{$target} < 0) { next; }
if ($target ne 'EXE' && $target ne 'EXEDOLIWAMP')
{
$nboftargetok = 0;
$nboftargetneedbuildroot = 0;
$nboftargetneedcvs = 0;
foreach my $target ( keys %CHOOSEDTARGET ) {
if ( $CHOOSEDTARGET{$target} < 0 ) { next; }
if ( $target ne 'EXE' && $target ne 'EXEDOLIWAMP' ) {
$nboftargetneedbuildroot++;
}
if ($target eq 'SNAPSHOT')
{
if ( $target eq 'SNAPSHOT' ) {
$nboftargetneedcvs++;
}
$nboftargetok++;
@@ -231,153 +296,187 @@ foreach my $PROJECT (@PROJECTLIST) {
# Update CVS if required
#-----------------------
if ($nboftargetneedcvs)
{
if ($nboftargetneedcvs) {
print "Go to directory $SOURCE\n";
$olddir=getcwd();
$olddir = getcwd();
chdir("$SOURCE");
print "Run cvs update -P -d\n";
$ret=`cvs update -P -d 2>&1`;
$ret = `cvs update -P -d 2>&1`;
chdir("$olddir");
}
# Update buildroot if required
#-----------------------------
if ($nboftargetneedbuildroot)
{
if (! $copyalreadydone) {
if ($nboftargetneedbuildroot) {
if ( !$copyalreadydone ) {
print "Delete directory $BUILDROOT\n";
$ret=`rm -fr "$BUILDROOT"`;
$ret = `rm -fr "$BUILDROOT"`;
mkdir "$BUILDROOT";
mkdir "$BUILDROOT/$PROJECTLC";
print "Now, we will copy all files declared in the makepack-".$PROJECT.".conf into the directory $BUILDROOT\n";
print "Now, we will copy all files declared in the makepack-"
. $PROJECT
. ".conf into the directory $BUILDROOT\n";
$result=open(IN,"<makepack-".$PROJECT.".conf");
if (! $result) { die "Error: Can't open conf file makepack-".$PROJECT.".conf for reading.\n"; }
while(<IN>)
{
$entry=$_;
open( my $IN2, "<", "makepack-" . $PROJECT . ".conf" )
or die "Error: Can't open conf file makepack-"
. $PROJECT
. ".conf for reading.\n";
while (<$IN2>) {
$entry = $_;
if ($entry =~ /^#/) { next; } # Do not process comments
if ( $entry =~ /^#/ ) { next; } # Do not process comments
$entry =~ s/\n//;
if ($entry =~ /^!(.*)$/) # Exclude so remove file/dir
if ( $entry =~ /^!(.*)$/ ) # Exclude so remove file/dir
{
print "Remove $BUILDROOT/$PROJECTLC/$1\n";
$ret=`rm -fr "$BUILDROOT/$PROJECTLC/"$1`;
if ($? != 0) { die "Failed to delete a file to exclude declared into makepack-".$PROJECT.".conf file (Failed on the line ".$entry.")\n"; }
$ret = `rm -fr "$BUILDROOT/$PROJECTLC/"$1`;
if ( $? != 0 ) {
die
"Failed to delete a file to exclude declared into makepack-"
. $PROJECT
. ".conf file (Failed on the line "
. $entry . ")\n";
}
next;
}
$entry =~ /^(.*)\/[^\/]+/;
print "Create directory $BUILDROOT/$PROJECTLC/$1\n";
$ret=`mkdir -p "$BUILDROOT/$PROJECTLC/$1"`;
if ($entry !~ /version\-/)
{
print "Copy $SOURCE/$entry into $BUILDROOT/$PROJECTLC/$entry\n";
$ret=`cp -pr "$SOURCE/$entry" "$BUILDROOT/$PROJECTLC/$entry"`;
if ($? != 0) { die "Failed to make copy of a file declared into makepack-".$PROJECT.".conf file (Failed on the line '".$entry."')\n"; }
$ret = `mkdir -p "$BUILDROOT/$PROJECTLC/$1"`;
if ( $entry !~ /version\-/ ) {
print
"Copy $SOURCE/$entry into $BUILDROOT/$PROJECTLC/$entry\n";
$ret =
`cp -pr "$SOURCE/$entry" "$BUILDROOT/$PROJECTLC/$entry"`;
if ( $? != 0 ) {
die
"Failed to make copy of a file declared into makepack-"
. $PROJECT
. ".conf file (Failed on the line '"
. $entry . "')\n";
}
}
}
close IN;
close $IN2;
@timearray=localtime(time());
$fulldate=($timearray[5]+1900).'-'.($timearray[4]+1).'-'.$timearray[3].' '.$timearray[2].':'.$timearray[1];
#open(VF,">$BUILDROOT/$PROJECTLC/dev/build/version-".$PROJECTLC.".txt");
#print "Create version file $BUILDROOT/$PROJECTLC/dev/build/version-".$PROJECTLC.".txt with date ".$fulldate."\n";
#$ret=`mkdir -p "$BUILDROOT/$PROJECTLC/dev/build"`;
#print VF "Version: ".$MAJOR.".".$MINOR.($BUILD ne ''?".$BUILD":"")."\n";
#print VF "Build : ".$fulldate."\n";
#close VF;
@timearray = localtime( time() );
$fulldate =
( $timearray[5] + 1900 ) . '-'
. ( $timearray[4] + 1 ) . '-'
. $timearray[3] . ' '
. $timearray[2] . ':'
. $timearray[1];
#open(VF,">$BUILDROOT/$PROJECTLC/dev/build/version-".$PROJECTLC.".txt");
#print "Create version file $BUILDROOT/$PROJECTLC/dev/build/version-".$PROJECTLC.".txt with date ".$fulldate."\n";
#$ret=`mkdir -p "$BUILDROOT/$PROJECTLC/dev/build"`;
#print VF "Version: ".$MAJOR.".".$MINOR.($BUILD ne ''?".$BUILD":"")."\n";
#print VF "Build : ".$fulldate."\n";
#close VF;
}
print "Clean $BUILDROOT\n";
$ret=`rm -fr $BUILDROOT/$PROJECTLC/.cache`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/.git`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/.project`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/.settings`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/index.php`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/dev/build/html`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/documents`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/document`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/htdocs/conf/conf.php.mysql`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/htdocs/conf/conf.php.old`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/htdocs/conf/conf.php.postgres`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/htdocs/conf/conf*sav*`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/.cache`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/.git`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/.project`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/.settings`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/index.php`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/dev/build/html`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/documents`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/document`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/htdocs/conf/conf.php.mysql`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/htdocs/conf/conf.php.old`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/htdocs/conf/conf.php.postgres`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/htdocs/conf/conf*sav*`;
if ($custom) {
$ret=`cp -r $BUILDROOT/$PROJECTLC/htdocs/custom/* $BUILDROOT/$PROJECTLC/htdocs/.`;
$ret =
`cp -r $BUILDROOT/$PROJECTLC/htdocs/custom/* $BUILDROOT/$PROJECTLC/htdocs/.`;
}
$ret=`rm -fr $BUILDROOT/$PROJECTLC/htdocs/custom`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/htdocs/custom2`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/test`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/Thumbs.db $BUILDROOT/$PROJECTLC/*/Thumbs.db $BUILDROOT/$PROJECTLC/*/*/Thumbs.db $BUILDROOT/$PROJECTLC/*/*/*/Thumbs.db $BUILDROOT/$PROJECTLC/*/*/*/*/Thumbs.db`;
$ret=`rm -fr $BUILDROOT/$PROJECTLC/CVS* $BUILDROOT/$PROJECTLC/*/CVS* $BUILDROOT/$PROJECTLC/*/*/CVS* $BUILDROOT/$PROJECTLC/*/*/*/CVS* $BUILDROOT/$PROJECTLC/*/*/*/*/CVS* $BUILDROOT/$PROJECTLC/*/*/*/*/*/CVS*`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/htdocs/custom`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/htdocs/custom2`;
$ret = `rm -fr $BUILDROOT/$PROJECTLC/test`;
$ret =
`rm -fr $BUILDROOT/$PROJECTLC/Thumbs.db $BUILDROOT/$PROJECTLC/*/Thumbs.db $BUILDROOT/$PROJECTLC/*/*/Thumbs.db $BUILDROOT/$PROJECTLC/*/*/*/Thumbs.db $BUILDROOT/$PROJECTLC/*/*/*/*/Thumbs.db`;
$ret =
`rm -fr $BUILDROOT/$PROJECTLC/CVS* $BUILDROOT/$PROJECTLC/*/CVS* $BUILDROOT/$PROJECTLC/*/*/CVS* $BUILDROOT/$PROJECTLC/*/*/*/CVS* $BUILDROOT/$PROJECTLC/*/*/*/*/CVS* $BUILDROOT/$PROJECTLC/*/*/*/*/*/CVS*`;
}
# Build package for each target
#------------------------------
foreach my $target (keys %CHOOSEDTARGET) {
if ($CHOOSEDTARGET{$target} < 0) { next; }
foreach my $target ( keys %CHOOSEDTARGET ) {
if ( $CHOOSEDTARGET{$target} < 0 ) { next; }
print "\nBuild package for target $target\n";
if ($target eq 'TGZ') {
$NEWDESTI=$DESTI;
if (-d $DESTI.'/../modules') { $NEWDESTI=$DESTI.'/../modules'; }
if ( $target eq 'TGZ' ) {
$NEWDESTI = $DESTI;
if ( -d $DESTI . '/../modules' ) {
$NEWDESTI = $DESTI . '/../modules';
}
print "Remove target $FILENAMETGZ.tgz...\n";
unlink("$NEWDESTI/$FILENAMETGZ.tgz");
print "Compress $BUILDROOT/* into $FILENAMETGZ.tgz...\n";
$cmd="tar --exclude-vcs --exclude *.tgz --directory \"$BUILDROOT\" --mode=go-w --group=500 --owner=500 -czvf \"$FILENAMETGZ.tgz\" .";
$ret=`$cmd`;
if ($OS =~ /windows/i) {
print "Move $FILENAMETGZ.tgz to $NEWDESTI/$FILENAMETGZ.tgz\n";
$ret=`mv "$FILENAMETGZ.tgz" "$NEWDESTI/$FILENAMETGZ.tgz"`;
$cmd =
"tar --exclude-vcs --exclude *.tgz --directory \"$BUILDROOT\" --mode=go-w --group=500 --owner=500 -czvf \"$FILENAMETGZ.tgz\" .";
$ret = `$cmd`;
if ( $OS =~ /windows/i ) {
print
"Move $FILENAMETGZ.tgz to $NEWDESTI/$FILENAMETGZ.tgz\n";
$ret = `mv "$FILENAMETGZ.tgz" "$NEWDESTI/$FILENAMETGZ.tgz"`;
}
else
{
$ret=`mv "$FILENAMETGZ.tgz" "$NEWDESTI/$FILENAMETGZ.tgz"`;
else {
$ret = `mv "$FILENAMETGZ.tgz" "$NEWDESTI/$FILENAMETGZ.tgz"`;
}
next;
}
if ($target eq 'ZIP') {
$NEWDESTI=$DESTI;
if (-d $DESTI.'/../modules') { $NEWDESTI=$DESTI.'/../modules'; }
if ( $target eq 'ZIP' ) {
$NEWDESTI = $DESTI;
if ( -d $DESTI . '/../modules' ) {
$NEWDESTI = $DESTI . '/../modules';
}
print "Remove target $FILENAMEZIP.zip...\n";
unlink "$NEWDESTI/$FILENAMEZIP.zip";
print "Compress $FILENAMEZIP into $FILENAMEZIP.zip...\n";
print "Go to directory $BUILDROOT/$PROJECTLC\n";
$olddir=getcwd();
$olddir = getcwd();
chdir("$BUILDROOT/$PROJECTLC");
$cmd= "7z a -r -tzip -mx $BUILDROOT/$FILENAMEZIP.zip *";
print $cmd."\n";
$ret= `$cmd`;
$cmd = "7z a -r -tzip -mx $BUILDROOT/$FILENAMEZIP.zip *";
print $cmd. "\n";
$ret = `$cmd`;
chdir("$olddir");
print "Move $FILENAMEZIP.zip to $NEWDESTI/$FILENAMEZIP.zip\n";
$ret=`mv "$BUILDROOT/$FILENAMEZIP.zip" "$NEWDESTI/$FILENAMEZIP.zip"`;
$ret=`chown $OWNER:$GROUP "$NEWDESTI/$FILENAMEZIP.zip"`;
$ret =
`mv "$BUILDROOT/$FILENAMEZIP.zip" "$NEWDESTI/$FILENAMEZIP.zip"`;
$ret = `chown $OWNER:$GROUP "$NEWDESTI/$FILENAMEZIP.zip"`;
next;
}
if ($target eq 'EXE') {
$NEWDESTI=$DESTI;
if (-d $DESTI.'/../modules') { $NEWDESTI=$DESTI.'/../modules'; }
if ( $target eq 'EXE' ) {
$NEWDESTI = $DESTI;
if ( -d $DESTI . '/../modules' ) {
$NEWDESTI = $DESTI . '/../modules';
}
print "Remove target $FILENAMEEXE.exe...\n";
unlink "$NEWDESTI/$FILENAMEEXE.exe";
print "Compress into $FILENAMEEXE.exe by $FILENAMEEXE.nsi...\n";
$command="\"$REQUIREMENTTARGET{$target}\" /DMUI_VERSION_DOT=$MAJOR.$MINOR.$BUILD /X\"SetCompressor bzip2\" \"$SOURCE\\dev\\build\\exe\\$FILENAME.nsi\"";
$command =
"\"$REQUIREMENTTARGET{$target}\" /DMUI_VERSION_DOT=$MAJOR.$MINOR.$BUILD /X\"SetCompressor bzip2\" \"$SOURCE\\dev\\build\\exe\\$FILENAME.nsi\"";
print "$command\n";
$ret=`$command`;
$ret = `$command`;
print "Move $FILENAMEEXE.exe to $NEWDESTI\n";
rename("$SOURCE\\dev\\build\\exe\\$FILENAMEEXE.exe","$NEWDESTI/$FILENAMEEXE.exe");
rename( "$SOURCE\\dev\\build\\exe\\$FILENAMEEXE.exe",
"$NEWDESTI/$FILENAMEEXE.exe" );
next;
}
@@ -386,21 +485,20 @@ foreach my $PROJECT (@PROJECTLIST) {
}
print "\n----- Summary -----\n";
foreach my $target (keys %CHOOSEDTARGET) {
if ($CHOOSEDTARGET{$target} < 0) {
foreach my $target ( keys %CHOOSEDTARGET ) {
if ( $CHOOSEDTARGET{$target} < 0 ) {
print "Package $target not built (bad requirement).\n";
} else {
}
else {
print "Package $target built successfully in $NEWDESTI\n";
}
}
}
if (! $batch) {
if ( !$batch ) {
print "\nPress key to finish...";
my $WAITKEY=<STDIN>;
my $WAITKEY = <STDIN>;
}
0;

View File

@@ -4,44 +4,53 @@
# \brief Script to build a theme Package for Dolibarr
# \author (c)2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
#-----------------------------------------------------------------------------
## no critic (InputOutput::ProhibitExplicitStdin)
use strict;
use warnings;
use Cwd;
use Term::ANSIColor;
$PROJECT="dolibarr";
$PROJECT = "dolibarr";
@LISTETARGET=("TGZ"); # Possible packages
%REQUIREMENTTARGET=( # Tool requirement for each package
"TGZ"=>"tar",
"ZIP"=>"7z",
"RPM"=>"rpmbuild",
"DEB"=>"dpkg-buildpackage",
"EXE"=>"makensis.exe"
@LISTETARGET = ("TGZ"); # Possible packages
%REQUIREMENTTARGET = ( # Tool requirement for each package
"TGZ" => "tar",
"ZIP" => "7z",
"RPM" => "rpmbuild",
"DEB" => "dpkg-buildpackage",
"EXE" => "makensis.exe"
);
%ALTERNATEPATH=(
"7z"=>"7-ZIP",
"makensis.exe"=>"NSIS"
%ALTERNATEPATH = (
"7z" => "7-ZIP",
"makensis.exe" => "NSIS"
);
use vars qw/ $REVISION $VERSION /;
$REVISION='1.11';
$VERSION="1.0 (build $REVISION)";
$REVISION = '1.11';
$VERSION = "1.0 (build $REVISION)";
#------------------------------------------------------------------------------
# MAIN
#------------------------------------------------------------------------------
($DIR=$0) =~ s/([^\/\\]+)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1;
$DIR||='.'; $DIR =~ s/([^\/\\])[\\\/]+$/$1/;
( $DIR = $0 ) =~ s/([^\/\\]+)$//;
( $PROG = $1 ) =~ s/\.([^\.]*)$//;
$Extension = $1;
$DIR ||= '.';
$DIR =~ s/([^\/\\])[\\\/]+$/$1/;
# Detect OS type
# --------------
if ("$^O" =~ /linux/i || (-d "/etc" && -d "/var" && "$^O" !~ /cygwin/i)) { $OS='linux'; $CR=''; }
elsif (-d "/etc" && -d "/Users") { $OS='macosx'; $CR=''; }
elsif ("$^O" =~ /cygwin/i || "$^O" =~ /win32/i) { $OS='windows'; $CR="\r"; }
if (! $OS) {
if ( "$^O" =~ /linux/i || ( -d "/etc" && -d "/var" && "$^O" !~ /cygwin/i ) ) {
$OS = 'linux';
$CR = '';
}
elsif ( -d "/etc" && -d "/Users" ) { $OS = 'macosx'; $CR = ''; }
elsif ( "$^O" =~ /cygwin/i || "$^O" =~ /win32/i ) {
$OS = 'windows';
$CR = "\r";
}
if ( !$OS ) {
print "$PROG.$Extension was not able to detect your OS.\n";
print "Can't continue.\n";
print "$PROG.$Extension aborted.\n";
@@ -51,139 +60,153 @@ if (! $OS) {
# Define buildroot
# ----------------
if ($OS =~ /linux/) {
$TEMP=$ENV{"TEMP"}||$ENV{"TMP"}||"/tmp";
if ( $OS =~ /linux/ ) {
$TEMP = $ENV{"TEMP"} || $ENV{"TMP"} || "/tmp";
}
if ($OS =~ /macos/) {
$TEMP=$ENV{"TEMP"}||$ENV{"TMP"}||"/tmp";
if ( $OS =~ /macos/ ) {
$TEMP = $ENV{"TEMP"} || $ENV{"TMP"} || "/tmp";
}
if ($OS =~ /windows/) {
$TEMP=$ENV{"TEMP"}||$ENV{"TMP"}||"c:/temp";
$PROGPATH=$ENV{"ProgramFiles"};
if ( $OS =~ /windows/ ) {
$TEMP = $ENV{"TEMP"} || $ENV{"TMP"} || "c:/temp";
$PROGPATH = $ENV{"ProgramFiles"};
}
if (! $TEMP || ! -d $TEMP) {
if ( !$TEMP || !-d $TEMP ) {
print "Error: A temporary directory can not be find.\n";
print "Check that TEMP or TMP environment variable is set correctly.\n";
print "makepack-dolibarrtheme.pl aborted.\n";
sleep 2;
exit 2;
}
$BUILDROOT="$TEMP/dolibarr-buildroot";
$BUILDROOT = "$TEMP/dolibarr-buildroot";
my $copyalreadydone=0;
my $batch=0;
my $copyalreadydone = 0;
my $batch = 0;
print "Makepack theme version $VERSION\n";
print "Enter name of theme(s) to package (separated with space): ";
$PROJECT=<STDIN>;
$PROJECT = <STDIN>;
chomp($PROJECT);
@PROJECTLIST=split(/ /,$PROJECT);
$PROJECT=join('',@PROJECTLIST);
@PROJECTLIST = split( / /, $PROJECT );
$PROJECT = join( '', @PROJECTLIST );
# Ask and set version $MAJOR and $MINOR
print "Enter value for version: ";
$PROJVERSION=<STDIN>;
$PROJVERSION = <STDIN>;
chomp($PROJVERSION);
($MAJOR,$MINOR)=split(/\./,$PROJVERSION,2);
if ($MINOR eq '')
{
( $MAJOR, $MINOR ) = split( /\./, $PROJVERSION, 2 );
if ( $MINOR eq '' ) {
print "Enter value for minor version: ";
$MINOR=<STDIN>;
$MINOR = <STDIN>;
chomp($MINOR);
}
$FILENAME = "$PROJECT";
$FILENAMETGZ = "theme_$PROJECT-$MAJOR.$MINOR";
$FILENAMEZIP = "theme_$PROJECT-$MAJOR.$MINOR";
$FILENAME="$PROJECT";
$FILENAMETGZ="theme_$PROJECT-$MAJOR.$MINOR";
$FILENAMEZIP="theme_$PROJECT-$MAJOR.$MINOR";
if ( -d "/usr/src/redhat" ) {
if (-d "/usr/src/redhat") {
# redhat
$RPMDIR="/usr/src/redhat";
$RPMDIR = "/usr/src/redhat";
}
if (-d "/usr/src/RPM") {
if ( -d "/usr/src/RPM" ) {
# mandrake
$RPMDIR="/usr/src/RPM";
$RPMDIR = "/usr/src/RPM";
}
$SOURCE="$DIR/../..";
$DESTI="$SOURCE/build";
$SOURCE = "$DIR/../..";
$DESTI = "$SOURCE/build";
# Choose package targets
#-----------------------
$target="ZIP"; # Packages uses this format
$target = "ZIP"; # Packages uses this format
if ($target) {
$CHOOSEDTARGET{uc($target)}=1;
$CHOOSEDTARGET{ uc($target) } = 1;
}
else {
my $found=0;
my $found = 0;
my $NUM_SCRIPT;
while (! $found) {
my $cpt=0;
printf(" %d - %3s (%s)\n",$cpt,"All","Need ".join(",",values %REQUIREMENTTARGET));
while ( !$found ) {
my $cpt = 0;
printf( " %d - %3s (%s)\n",
$cpt, "All", "Need " . join( ",", values %REQUIREMENTTARGET ) );
foreach my $target (@LISTETARGET) {
$cpt++;
printf(" %d - %3s (%s)\n",$cpt,$target,"Need ".$REQUIREMENTTARGET{$target});
printf( " %d - %3s (%s)\n",
$cpt, $target, "Need " . $REQUIREMENTTARGET{$target} );
}
# Are asked to select the file to move
print "Choose one package number or several separated with space: ";
$NUM_SCRIPT=<STDIN>;
$NUM_SCRIPT = <STDIN>;
chomp($NUM_SCRIPT);
if ($NUM_SCRIPT =~ s/-//g) {
if ( $NUM_SCRIPT =~ s/-//g ) {
# Do not do copy
$copyalreadydone=1;
$copyalreadydone = 1;
}
if ($NUM_SCRIPT !~ /^[0-$cpt\s]+$/)
{
if ( $NUM_SCRIPT !~ /^[0-$cpt\s]+$/ ) {
print "This is not a valid package number list.\n";
$found = 0;
}
else
{
else {
$found = 1;
}
}
print "\n";
if ($NUM_SCRIPT) {
foreach my $num (split(/\s+/,$NUM_SCRIPT)) {
$CHOOSEDTARGET{$LISTETARGET[$num-1]}=1;
foreach my $num ( split( /\s+/, $NUM_SCRIPT ) ) {
$CHOOSEDTARGET{ $LISTETARGET[ $num - 1 ] } = 1;
}
}
else {
foreach my $key (@LISTETARGET) {
$CHOOSEDTARGET{$key}=1;
$CHOOSEDTARGET{$key} = 1;
}
}
}
# Test if requirement is ok
#--------------------------
foreach my $target (keys %CHOOSEDTARGET) {
foreach my $req (split(/[,\s]/,$REQUIREMENTTARGET{$target})) {
foreach my $target ( keys %CHOOSEDTARGET ) {
foreach my $req ( split( /[,\s]/, $REQUIREMENTTARGET{$target} ) ) {
# Test
print "Test requirement for target $target: Search '$req'... ";
$ret=`"$req" 2>&1`;
$coderetour=$?; $coderetour2=$coderetour>>8;
if ($coderetour != 0 && (($coderetour2 == 1 && $OS =~ /windows/ && $ret !~ /Usage/i) || ($coderetour2 == 127 && $OS !~ /windows/)) && $PROGPATH) {
$ret = `"$req" 2>&1`;
$coderetour = $?;
$coderetour2 = $coderetour >> 8;
if (
$coderetour != 0
&& ( ( $coderetour2 == 1 && $OS =~ /windows/ && $ret !~ /Usage/i )
|| ( $coderetour2 == 127 && $OS !~ /windows/ ) )
&& $PROGPATH
)
{
# Not found error, we try in PROGPATH
$ret=`"$PROGPATH/$ALTERNATEPATH{$req}/$req\" 2>&1`;
$coderetour=$?; $coderetour2=$coderetour>>8;
$REQUIREMENTTARGET{$target}="$PROGPATH/$ALTERNATEPATH{$req}/$req";
$ret = `"$PROGPATH/$ALTERNATEPATH{$req}/$req\" 2>&1`;
$coderetour = $?;
$coderetour2 = $coderetour >> 8;
$REQUIREMENTTARGET{$target} = "$PROGPATH/$ALTERNATEPATH{$req}/$req";
}
if ($coderetour != 0 && (($coderetour2 == 1 && $OS =~ /windows/ && $ret !~ /Usage/i) || ($coderetour2 == 127 && $OS !~ /windows/))) {
if (
$coderetour != 0
&& ( ( $coderetour2 == 1 && $OS =~ /windows/ && $ret !~ /Usage/i )
|| ( $coderetour2 == 127 && $OS !~ /windows/ ) )
)
{
# Not found error
print "Not found\nCan't build target $target. Requirement '$req' not found in PATH\n";
$CHOOSEDTARGET{$target}=-1;
print
"Not found\nCan't build target $target. Requirement '$req' not found in PATH\n";
$CHOOSEDTARGET{$target} = -1;
last;
} else {
}
else {
# Pas erreur ou erreur autre que programme absent
print " Found ".$REQUIREMENTTARGET{$target}."\n";
print " Found " . $REQUIREMENTTARGET{$target} . "\n";
}
}
}
@@ -192,9 +215,9 @@ print "\n";
# Check if there is at least on target to build
#----------------------------------------------
$nboftargetok=0;
foreach my $target (keys %CHOOSEDTARGET) {
if ($CHOOSEDTARGET{$target} < 0) { next; }
$nboftargetok = 0;
foreach my $target ( keys %CHOOSEDTARGET ) {
if ( $CHOOSEDTARGET{$target} < 0 ) { next; }
$nboftargetok++;
}
@@ -202,51 +225,53 @@ if ($nboftargetok) {
# Update buildroot
#-----------------
if (! $copyalreadydone) {
if ( !$copyalreadydone ) {
print "Delete directory $BUILDROOT\n";
$ret=`rm -fr "$BUILDROOT"`;
$ret = `rm -fr "$BUILDROOT"`;
mkdir "$BUILDROOT";
mkdir "$BUILDROOT/htdocs";
mkdir "$BUILDROOT/htdocs/theme";
print "Copy $SOURCE into $BUILDROOT\n";
mkdir "$BUILDROOT";
foreach my $tmp (@PROJECTLIST)
{
$ret=`cp -pr "$SOURCE/htdocs/theme/$tmp" "$BUILDROOT/htdocs/theme"`;
foreach my $tmp (@PROJECTLIST) {
$ret =
`cp -pr "$SOURCE/htdocs/theme/$tmp" "$BUILDROOT/htdocs/theme"`;
}
}
print "Clean $BUILDROOT\n";
$ret=`rm -fr $BUILDROOT/htdocs/theme/$PROJECT/Thumbs.db $BUILDROOT/htdocs/theme/$PROJECT/*/Thumbs.db $BUILDROOT/htdocs/theme/$PROJECT/*/*/Thumbs.db $BUILDROOT/htdocs/theme/$PROJECT/*/*/*/Thumbs.db`;
$ret=`rm -fr $BUILDROOT/htdocs/theme/$PROJECT/CVS* $BUILDROOT/htdocs/theme/$PROJECT/*/CVS* $BUILDROOT/htdocs/theme/$PROJECT/*/*/CVS* $BUILDROOT/htdocs/theme/$PROJECT/*/*/*/CVS* $BUILDROOT/htdocs/theme/$PROJECT/*/*/*/*/CVS* $BUILDROOT/htdocs/theme/$PROJECT/*/*/*/*/*/CVS*`;
$ret =
`rm -fr $BUILDROOT/htdocs/theme/$PROJECT/Thumbs.db $BUILDROOT/htdocs/theme/$PROJECT/*/Thumbs.db $BUILDROOT/htdocs/theme/$PROJECT/*/*/Thumbs.db $BUILDROOT/htdocs/theme/$PROJECT/*/*/*/Thumbs.db`;
$ret =
`rm -fr $BUILDROOT/htdocs/theme/$PROJECT/CVS* $BUILDROOT/htdocs/theme/$PROJECT/*/CVS* $BUILDROOT/htdocs/theme/$PROJECT/*/*/CVS* $BUILDROOT/htdocs/theme/$PROJECT/*/*/*/CVS* $BUILDROOT/htdocs/theme/$PROJECT/*/*/*/*/CVS* $BUILDROOT/htdocs/theme/$PROJECT/*/*/*/*/*/CVS*`;
# Build package for each target
#------------------------------
foreach my $target (keys %CHOOSEDTARGET) {
if ($CHOOSEDTARGET{$target} < 0) { next; }
foreach my $target ( keys %CHOOSEDTARGET ) {
if ( $CHOOSEDTARGET{$target} < 0 ) { next; }
print "\nBuild package for target $target\n";
if ($target eq 'TGZ') {
unlink $FILENAMETGZ.tgz;
if ( $target eq 'TGZ' ) {
unlink $FILENAMETGZ . tgz;
print "Compress $BUILDROOT/htdocs into $FILENAMETGZ.tgz...\n";
$cmd="tar --exclude-vcs --exclude-from \"$DESTI/tgz/tar_exclude.txt\" --directory \"$BUILDROOT\" --mode=go-w --group=500 --owner=500 -czvf \"$FILENAMETGZ.tgz\" htdocs";
$ret=`$cmd`;
if ($OS =~ /windows/i) {
$cmd =
"tar --exclude-vcs --exclude-from \"$DESTI/tgz/tar_exclude.txt\" --directory \"$BUILDROOT\" --mode=go-w --group=500 --owner=500 -czvf \"$FILENAMETGZ.tgz\" htdocs";
$ret = `$cmd`;
if ( $OS =~ /windows/i ) {
print "Move $FILENAMETGZ.tgz to $DESTI/$FILENAMETGZ.tgz\n";
$ret=`mv "$FILENAMETGZ.tgz" "$DESTI/$FILENAMETGZ.tgz"`;
$ret = `mv "$FILENAMETGZ.tgz" "$DESTI/$FILENAMETGZ.tgz"`;
}
next;
}
if ($target eq 'ZIP') {
unlink $FILENAMEZIP.zip;
if ( $target eq 'ZIP' ) {
unlink $FILENAMEZIP . zip;
print "Compress $FILENAMETGZ into $FILENAMEZIP.zip...\n";
chdir("$BUILDROOT");
$ret=`7z a -r -tzip -mx $BUILDROOT/$FILENAMEZIP.zip htdocs`;
$ret = `7z a -r -tzip -mx $BUILDROOT/$FILENAMEZIP.zip htdocs`;
print "Move $FILENAMEZIP.zip to $DESTI\n";
$ret=`mv "$FILENAMEZIP.zip" "$DESTI/$FILENAMEZIP.zip"`;
$ret = `mv "$FILENAMEZIP.zip" "$DESTI/$FILENAMEZIP.zip"`;
next;
}
@@ -255,17 +280,18 @@ if ($nboftargetok) {
}
print "\n----- Summary -----\n";
foreach my $target (keys %CHOOSEDTARGET) {
if ($CHOOSEDTARGET{$target} < 0) {
foreach my $target ( keys %CHOOSEDTARGET ) {
if ( $CHOOSEDTARGET{$target} < 0 ) {
print "Package $target not built (bad requirement).\n";
} else {
}
else {
print "Package $target built successfully in $DESTI\n";
}
}
if (! $btach) {
if ( !$btach ) {
print "\nPress key to finish...";
my $WAITKEY=<STDIN>;
my $WAITKEY = <STDIN>;
}
0;

View File

@@ -11,51 +11,55 @@
# Pour les cles autoincrement: rowid integer AUTO_INCREMENT PRIMARY KEY,
# Mettre les index dans fichier.key.sql
#------------------------------------------------------------------------------
## no critic (InputOutput::ProhibitExplicitStdin,InputOutput::RequireBriefOpen)
use Data::Dumper;
use Getopt::Long;
use strict;
use warnings;
use vars qw/ $DIR $PROG $Extension $SOURCE $DESTI %filelist $stop /;
# command line options
my( $opt_debug, $opt_help);
my ( $opt_debug, $opt_help );
# general values
my ($out, $size);
my ( $out, $size );
# variables for constructing pre-create-table entities
my $create_sql=''; # if empty we are not making a create statement
my $create_index=''; # if empty we are not making a create statement
my %enum_datafield=(); # holds enumeration choices
my (@column_values,$enum_column, $seq);
my $table="";
my $create_sql = ''; # if empty we are not making a create statement
my $create_index = ''; # if empty we are not making a create statement
my %enum_datafield = (); # holds enumeration choices
my ( @column_values, $enum_column, $seq );
my $table = "";
#------------------------------------------------------------------------------
# MAIN
#------------------------------------------------------------------------------
($DIR=$0) =~ s/([^\/\\]+)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1;
$DIR||='.'; $DIR =~ s/([^\/\\])[\\\/]+$/$1/;
( $DIR = $0 ) =~ s/([^\/\\]+)$//;
( $PROG = $1 ) =~ s/\.([^\.]*)$//;
$Extension = $1;
$DIR ||= '.';
$DIR =~ s/([^\/\\])[\\\/]+$/$1/;
$SOURCE="$DIR/install/mysql/tables";
$DESTI="$DIR/install/pgsql/tables";
$SOURCE = "$DIR/install/mysql/tables";
$DESTI = "$DIR/install/pgsql/tables";
# Recherche tous les fichiers .sql
opendir(DIR, $SOURCE);
foreach my $file (readdir(DIR)) {
if ($file =~ /\.sql$/ && -f "$SOURCE/$file") {
opendir( my $dir, $SOURCE );
foreach my $file ( readdir($dir) ) {
if ( $file =~ /\.sql$/ && -f "$SOURCE/$file" ) {
print "Found file $file\n";
$filelist{$file}=1;
$filelist{$file} = 1;
}
}
closedir(DIR);
}
closedir($dir);
# Boucle sur tous les fichiers de SOURCE
#---------------------------------------
foreach my $file (keys %filelist) {
foreach my $file ( keys %filelist ) {
$ARGV[0]="$SOURCE/$file";
$ARGV[1]="$DESTI/$file";
local $ARGV[0] = "$SOURCE/$file";
local $ARGV[1] = "$DESTI/$file";
print "Convert file $ARGV[0] into $ARGV[1]\n";
@@ -82,88 +86,98 @@ foreach my $file (keys %filelist) {
# 2004-06-29 converts: year(4), year(2)
# homepage: gborg.postgresql.org
GetOptions("debug", "help");
GetOptions( "debug", "help" );
my $DEBUG = $opt_debug || 0;
my $HELP = $opt_help || 0;
if (($HELP) || ! defined($ARGV[0]) || ! defined($ARGV[1])) {
print "Usage: perl $0 {--verbose|--help|--debug} mysql_dump_file.sql pg_dump_file.sql\n";
if ( ($HELP) || !defined( $ARGV[0] ) || !defined( $ARGV[1] ) ) {
print
"Usage: perl $0 {--verbose|--help|--debug} mysql_dump_file.sql pg_dump_file.sql\n";
print "\t* OPTIONS\n";
print "\t--verbose tees to pg_dump_file.sql and STDOUT during conversion\n";
print
"\t--verbose tees to pg_dump_file.sql and STDOUT during conversion\n";
print "\t--debug does ?? \n";
print "\t--help prints this message \n";
print "\t* REQUIRED ARGUMENTS\n";
if (defined ($ARGV[0])) {
if ( defined( $ARGV[0] ) ) {
print "\tmysql_dump_file.sql ($ARGV[0])\n";
} else {
}
else {
print "\tmysql_dump_file.sql (undefined)\n";
}
if (defined ($ARGV[1])) {
if ( defined( $ARGV[1] ) ) {
print "\tpg_dump_file.sql ($ARGV[1])\n";
} else {
}
else {
print "\tpg_dump_file.sql (undefined)\n";
}
exit 1;
}
open(IN,"<$ARGV[0]") || die "can't open mysql dump file $ARGV[0]";
open(OUT,">$ARGV[1]") || die "can't open pg dump file $ARGV[1]";
print OUT "-- Generated by $PROG\n";
print OUT "-- (c) 2004, PostgreSQL Inc.\n";
print OUT "-- (c) 2005, Laurent Destailleur.\n";
print OUT "\n";
open( my $in, "<", "$ARGV[0]" )
|| die "can't open mysql dump file $ARGV[0]";
open( my $out, ">", "$ARGV[1]" ) || die "can't open pg dump file $ARGV[1]";
print $out "-- Generated by $PROG\n";
print $out "-- (c) 2004, PostgreSQL Inc.\n";
print $out "-- (c) 2005, Laurent Destailleur.\n";
print $out "\n";
# Output for create table and create index
sub output_create {
# If command ends with "xxx,);", we change to "xxx);"
$create_sql =~ s/,(\s*)\);/$1\);/m;
# If command ends with "xxx, -- yyy );", we change to "xxx -- yyy);"
$create_sql =~ s/,(\s*\-\-[^\)\n]*)(\s*)\);/$1\n\);/m;
print OUT $create_sql;
print $out $create_sql;
if ($create_index) {
print OUT "\n";
print OUT $create_index;
print $out "\n";
print $out $create_index;
}
return;
}
# Reset when moving from each "create table" to "insert" part of dump
sub reset_vars() {
$create_sql="";
$create_index="";
%enum_datafield=();
$enum_column='';
$create_sql = "";
$create_index = "";
%enum_datafield = ();
$enum_column = '';
return;
}
# Boucle sur contenu fichier source
#----------------------------------
while(<IN>) {
while (<$in>) {
# comments or empty lines
if (/^-- \$Id/) {
$_ =~ s/\$//g;
print OUT $_;
print $out $_;
next;
}
# comments or empty lines
if (/^#/ || /^$/ || /^--/) {
print OUT $_;
if ( /^#/ || /^$/ || /^--/ ) {
print $out $_;
next;
}
if (/^USE\s*([^;]*);/) {
print OUT "\\c ". $1;
print $out "\\c " . $1;
next;
}
if ($create_sql ne "") { # we are inside create table statement so let's process datatypes
if ( $create_sql ne "" )
{ # we are inside create table statement so let's process datatypes
if (/\);/i) { # end of create table sequence
$create_sql =~ s/,$//g; # strip last , inside create table
&output_create;
&reset_vars();
next;
# LDR Added "innodb" and "engine"
}
elsif (/(ISAM|innodb)/i) { # end of create table sequence
@@ -177,36 +191,50 @@ foreach my $file (keys %filelist) {
}
# enum -> check
if (/([\w\"]*)\s+enum\s*\(((?:['"][\?\w]+['"]\s*,)+['"][\?\w]+['"])\)(.*)$/i) {
$enum_column=$1;
$enum_datafield{$enum_column}=$2; # 'abc','def', ...
my $suite=$3;
my $maxlength=0;
foreach my $enum (split(',',$enum_datafield{$enum_column})) {
if (
/([\w\"]*)\s+enum\s*\(((?:['"][\?\w]+['"]\s*,)+['"][\?\w]+['"])\)(.*)$/i
)
{
$enum_column = $1;
$enum_datafield{$enum_column} = $2; # 'abc','def', ...
my $suite = $3;
my $maxlength = 0;
foreach my $enum ( split( ',', $enum_datafield{$enum_column} ) )
{
$enum =~ s/[\"\']//g;
if ($maxlength<length($enum)) { $maxlength=length($enum); }
if ( $maxlength < length($enum) ) {
$maxlength = length($enum);
}
}
$enum_datafield{$enum_column} =~ s/\"/\'/g;
$_ = qq~ $enum_column CHAR($maxlength) CHECK ($enum_column IN ($enum_datafield{$enum_column})) $suite\n~;
$_ =
qq~ $enum_column CHAR($maxlength) CHECK ($enum_column IN ($enum_datafield{$enum_column})) $suite\n~;
# int, auto_increment -> serial
} elsif (/^[\s\t]*(\w*)\s*.*int.*auto_increment/i) {
}
elsif (/^[\s\t]*(\w*)\s*.*int.*auto_increment/i) {
$seq = qq~${table}_${1}_seq~;
s/[\s\t]*([a-zA-Z_0-9]*)\s*.*int.*auto_increment[^,]*/ $1 SERIAL PRIMARY KEY/ig;
$create_sql.=$_;
s/[\s\t]*([a-zA-Z_0-9]*)\s*.*int.*auto_increment[^,]*/ $1 SERIAL PRIMARY KEY/ig;
$create_sql .= $_;
next;
# int type conversion
} elsif (/(\w*)int\(\d+\)/i) {
$size=$1;
}
elsif (/(\w*)int\(\d+\)/i) {
$size = $1;
$size =~ tr [A-Z] [a-z];
if ($size eq "tiny" || $size eq "small") {
if ( $size eq "tiny" || $size eq "small" ) {
$out = "int2";
} elsif ($size eq "big") {
}
elsif ( $size eq "big" ) {
$out = "int8";
} else {
}
else {
$out = "int4";
}
s/\w*int\(\d+\)/$out/g;
}
# tinyint -> smallint
elsif (/tinyint/i) {
s/tinyint/smallint/g;
@@ -215,7 +243,6 @@ foreach my $file (keys %filelist) {
# nuke unsigned
s/(int\w+|smallint)\s+unsigned/$1/gi;
# blob -> text
s/\w*blob/text/gi;
@@ -252,78 +279,85 @@ foreach my $file (keys %filelist) {
# unique key(field1,field2)
if (/unique key\s*\((\w+\s*,\s*\w+)\)/i) {
s/unique key\s*\((\w+\s*,\s*\w+)\)/UNIQUE\($1\)/i;
$create_sql.=$_;
$create_sql .= $_;
next;
}
# unique index(field1,field2)
if (/unique index\s*\((\w+\s*,\s*\w+)\)/i) {
s/unique index\s*\((\w+\s*,\s*\w+)\)/UNIQUE\($1\)/i;
$create_sql.=$_;
$create_sql .= $_;
next;
}
# unique key [name] (field)
if (/unique key\s*(\w*)\s*\((\w+)\)/i) {
s/unique key\s*(\w*)\s*\((\w+)\)/UNIQUE\($2\)/i;
my $idxname=($1?"$1":"idx_${table}_$2");
$create_sql.=$_;
my $idxname = ( $1 ? "$1" : "idx_${table}_$2" );
$create_sql .= $_;
$create_index .= "CREATE INDEX $idxname ON $table ($2);\n";
next;
}
# unique index [name] (field)
if (/unique index\s*(\w*)\s*\((\w+)\)/i) {
s/unique index\s*(\w*)\s*\((\w+)\)/UNIQUE\($2\)/i;
my $idxname=($1?"$1":"idx_${table}_$2");
$create_sql.=$_;
my $idxname = ( $1 ? "$1" : "idx_${table}_$2" );
$create_sql .= $_;
$create_index .= "CREATE INDEX $idxname ON $table ($2);\n";
next;
}
# unique (field) et unique (field1, field2 ...)
if (/unique\s*\(([\w,\s]+)\)/i) {
s/unique\s*\(([\w,\s]+)\)/UNIQUE\($1\)/i;
my $fieldlist="$1";
my $idxname="idx_${table}_${fieldlist}";
$idxname =~ s/\W/_/g; $idxname =~ tr/_/_/s;
$create_sql.=$_;
$create_index .= "CREATE INDEX $idxname ON $table ($fieldlist);\n";
my $fieldlist = "$1";
my $idxname = "idx_${table}_${fieldlist}";
$idxname =~ s/\W/_/g;
$idxname =~ tr/_/_/s;
$create_sql .= $_;
$create_index .=
"CREATE INDEX $idxname ON $table ($fieldlist);\n";
next;
}
# index(field)
if (/index\s*(\w*)\s*\((\w+)\)/i) {
my $idxname=($1?"$1":"idx_${table}_$2");
my $idxname = ( $1 ? "$1" : "idx_${table}_$2" );
$create_index .= "CREATE INDEX $idxname ON $table ($2);\n";
next;
}
# primary key
if (/\bkey\b/i && !/^\s+primary key\s+/i) {
s/KEY(\s+)[^(]*(\s+)/$1 UNIQUE $2/i; # hack off name of the non-primary key
if ( /\bkey\b/i && !/^\s+primary key\s+/i ) {
s/KEY(\s+)[^(]*(\s+)/$1 UNIQUE $2/i
; # hack off name of the non-primary key
}
# key(xxx)
if (/key\s*\((\w+)\)/i) {
my $idxname="idx_${table}_$1";
my $idxname = "idx_${table}_$1";
$create_index .= "CREATE INDEX $idxname ON $table ($1);\n";
next;
}
# Quote column names
s/(^\s*)([^\s\-\(]+)(\s*)/$1"$2"$3/gi if (!/\bkey\b/i);
s/(^\s*)([^\s\-\(]+)(\s*)/$1"$2"$3/gi if ( !/\bkey\b/i );
# Remap columns with names of existing system attribute
if (/"oid"/i) {
s/"oid"/"_oid"/g;
print STDERR "WARNING: table $table uses column \"oid\" which is renamed to \"_oid\"\nYou should fix application manually! Press return to continue.";
my $wait=<STDIN>;
print STDERR
"WARNING: table $table uses column \"oid\" which is renamed to \"_oid\"\nYou should fix application manually! Press return to continue.";
my $wait = <STDIN>;
}
s/oid/_oid/i if (/key/i && /oid/i); # fix oid in key
$create_sql.=$_;
s/oid/_oid/i if ( /key/i && /oid/i ); # fix oid in key
$create_sql .= $_;
} # END of if ($create_sql ne "") i.e. were inside create table statement so processed datatypes
else { # not inside create table
#---- fix data in inserted data: (from MS world)
# FIX: disabled for now
if (00 && /insert into/i) {
if ( 00 && /insert into/i ) {
s!\x96!-!g; # --
s!\x93!"!g; # ``
s!\x94!"!g; # ''
@@ -335,27 +369,28 @@ foreach my $file (keys %filelist) {
s/'0000-00-00 00:00:00'/null/gi;
s/'0000-00-00'/null/gi;
s/'00:00:00'/null/gi;
s/([12]\d\d\d)([01]\d)([0-3]\d)([0-2]\d)([0-6]\d)([0-6]\d)/'$1-$2-$3 $4:$5:$6'/;
s/([12]\d\d\d)([01]\d)([0-3]\d)([0-2]\d)([0-6]\d)([0-6]\d)/'$1-$2-$3 $4:$5:$6'/;
if (/create\s+table\s+(\w+)/i) {
$create_sql = $_;
/create\s*table\s*(\w+)/i;
$table=$1 if (defined($1));
} else {
print OUT $_;
$table = $1 if ( defined($1) );
}
else {
print $out $_;
}
} # end of if inside create_table
} # END while(<IN>)
close IN;
close OUT;
close $in;
close $out;
}
print "\n";
print "Build ".(scalar keys %filelist)." file(s).\n";
print "Build " . ( scalar keys %filelist ) . " file(s).\n";
print "\n";
print "Press a key to finish...\n";
$stop=<STDIN>;
$stop = <STDIN>;
0;