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 coverage: none # disable xdebug, pcov
tools: phpcs 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). # Run all the precommit tools (defined into pre-commit-config.yaml).
# We can force exclusion of some of them here. # We can force exclusion of some of them here.
- name: Run pre-commit hooks - name: Run pre-commit hooks

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,5 @@
#!/usr/bin/perl #!/usr/bin/perl
## no critic (InputOutput::RequireBriefOpen)
#fetch Gravatars #fetch Gravatars
use strict; use strict;
@@ -10,39 +11,44 @@ use Digest::MD5 qw(md5_hex);
my $size = 90; my $size = 90;
my $output_dir = './avatars'; 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; 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; my %processed_authors;
while(<GITLOG>) { while (<$GITLOG>) {
chomp; chomp;
my($email, $author) = split(/\|/, $_); my ( $email, $author ) = split( /\|/, $_ );
next if $processed_authors{$author}++; next if $processed_authors{$author}++;
my $author_image_file = $output_dir . '/' . $author . '.png'; my $author_image_file = $output_dir . '/' . $author . '.png';
#skip images we have #skip images we have
next if -e $author_image_file; next if -e $author_image_file;
#try and fetch image #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"; 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); sleep(1);
if($rc != 200) { if ( $rc != 200 ) {
unlink($author_image_file); unlink($author_image_file);
next; next;
} }
} }
close GITLOG; close $GITLOG;

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@@ -11,351 +11,386 @@
# Pour les cles autoincrement: rowid integer AUTO_INCREMENT PRIMARY KEY, # Pour les cles autoincrement: rowid integer AUTO_INCREMENT PRIMARY KEY,
# Mettre les index dans fichier.key.sql # Mettre les index dans fichier.key.sql
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
## no critic (InputOutput::ProhibitExplicitStdin,InputOutput::RequireBriefOpen)
use Data::Dumper; use Data::Dumper;
use Getopt::Long; use Getopt::Long;
use strict; use strict;
use warnings;
use vars qw/ $DIR $PROG $Extension $SOURCE $DESTI %filelist $stop /; use vars qw/ $DIR $PROG $Extension $SOURCE $DESTI %filelist $stop /;
# command line options # command line options
my( $opt_debug, $opt_help); my ( $opt_debug, $opt_help );
# general values # general values
my ($out, $size); my ( $out, $size );
# variables for constructing pre-create-table entities # variables for constructing pre-create-table entities
my $create_sql=''; # if empty we are not making a create statement 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 $create_index = ''; # if empty we are not making a create statement
my %enum_datafield=(); # holds enumeration choices my %enum_datafield = (); # holds enumeration choices
my (@column_values,$enum_column, $seq); my ( @column_values, $enum_column, $seq );
my $table=""; my $table = "";
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# MAIN # MAIN
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
($DIR=$0) =~ s/([^\/\\]+)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1; ( $DIR = $0 ) =~ s/([^\/\\]+)$//;
$DIR||='.'; $DIR =~ s/([^\/\\])[\\\/]+$/$1/; ( $PROG = $1 ) =~ s/\.([^\.]*)$//;
$Extension = $1;
$DIR ||= '.';
$DIR =~ s/([^\/\\])[\\\/]+$/$1/;
$SOURCE="$DIR/install/mysql/tables"; $SOURCE = "$DIR/install/mysql/tables";
$DESTI="$DIR/install/pgsql/tables"; $DESTI = "$DIR/install/pgsql/tables";
# Recherche tous les fichiers .sql # Recherche tous les fichiers .sql
opendir(DIR, $SOURCE); opendir( my $dir, $SOURCE );
foreach my $file (readdir(DIR)) { foreach my $file ( readdir($dir) ) {
if ($file =~ /\.sql$/ && -f "$SOURCE/$file") { if ( $file =~ /\.sql$/ && -f "$SOURCE/$file" ) {
print "Found file $file\n"; print "Found file $file\n";
$filelist{$file}=1; $filelist{$file} = 1;
} }
} }
closedir(DIR); closedir($dir);
# Boucle sur tous les fichiers de SOURCE # Boucle sur tous les fichiers de SOURCE
#--------------------------------------- #---------------------------------------
foreach my $file (keys %filelist) { foreach my $file ( keys %filelist ) {
$ARGV[0]="$SOURCE/$file"; local $ARGV[0] = "$SOURCE/$file";
$ARGV[1]="$DESTI/$file"; local $ARGV[1] = "$DESTI/$file";
print "Convert file $ARGV[0] into $ARGV[1]\n"; print "Convert file $ARGV[0] into $ARGV[1]\n";
# MySQL to PostgreSQL dump file converter # MySQL to PostgreSQL dump file converter
# #
# For usage: perl mysql2pgsql.perl --help # For usage: perl mysql2pgsql.perl --help
# #
# homepage: http://www.rot13.org/~dpavlin/projects.html # homepage: http://www.rot13.org/~dpavlin/projects.html
# 1999-12-15 DbP -- Dobrica Pavlinusic <dpavlin@rot13.org> # 1999-12-15 DbP -- Dobrica Pavlinusic <dpavlin@rot13.org>
# 1999-12-26 DbP don't make serial from auto_increment, create all manually # 1999-12-26 DbP don't make serial from auto_increment, create all manually
# (to set start value right) # (to set start value right)
# 2000-01-11 DbP now creates sequences with correct value # 2000-01-11 DbP now creates sequences with correct value
# 2000-04-25 DbP import into CVS (at cvs.linux.hr) # 2000-04-25 DbP import into CVS (at cvs.linux.hr)
# 2001-01-29 tpo -- Tomas Pospisek <tpo@sourcepole.ch>: # 2001-01-29 tpo -- Tomas Pospisek <tpo@sourcepole.ch>:
# 1) make script comply to usage: # 1) make script comply to usage:
# 2) make script output to STDOUT instead of STERR # 2) make script output to STDOUT instead of STERR
# 3) change verbosity behaveour # 3) change verbosity behaveour
# 4) add debug option # 4) add debug option
# see rest of changelog at http://cvs.linux.hr/cvsweb.cgi/sql/mysql2pgsql # see rest of changelog at http://cvs.linux.hr/cvsweb.cgi/sql/mysql2pgsql
# 2003-12-16 jsp -- Joe Speigle <joe.speigle@jklh.us>: # 2003-12-16 jsp -- Joe Speigle <joe.speigle@jklh.us>:
# converts: s/\) *Type=MyISAM;/);/i, enum data type -> references, # converts: s/\) *Type=MyISAM;/);/i, enum data type -> references,
# auto_increment->sequences # auto_increment->sequences
# 2004-01-13 jsp -- moved project to gborg; both the above declined ownership # 2004-01-13 jsp -- moved project to gborg; both the above declined ownership
# 2004-06-29 converts: year(4), year(2) # 2004-06-29 converts: year(4), year(2)
# homepage: gborg.postgresql.org # homepage: gborg.postgresql.org
GetOptions("debug", "help"); GetOptions( "debug", "help" );
my $DEBUG = $opt_debug || 0; my $DEBUG = $opt_debug || 0;
my $HELP = $opt_help || 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";
print "\t* OPTIONS\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] ) ) {
print "\tmysql_dump_file.sql ($ARGV[0])\n";
}
else {
print "\tmysql_dump_file.sql (undefined)\n";
}
if ( defined( $ARGV[1] ) ) {
print "\tpg_dump_file.sql ($ARGV[1])\n";
}
else {
print "\tpg_dump_file.sql (undefined)\n";
}
exit 1;
}
if (($HELP) || ! defined($ARGV[0]) || ! defined($ARGV[1])) { open( my $in, "<", "$ARGV[0]" )
print "Usage: perl $0 {--verbose|--help|--debug} mysql_dump_file.sql pg_dump_file.sql\n"; || die "can't open mysql dump file $ARGV[0]";
print "\t* OPTIONS\n"; open( my $out, ">", "$ARGV[1]" ) || die "can't open pg dump file $ARGV[1]";
print "\t--verbose tees to pg_dump_file.sql and STDOUT during conversion\n"; print $out "-- Generated by $PROG\n";
print "\t--debug does ?? \n"; print $out "-- (c) 2004, PostgreSQL Inc.\n";
print "\t--help prints this message \n"; print $out "-- (c) 2005, Laurent Destailleur.\n";
print "\t* REQUIRED ARGUMENTS\n"; print $out "\n";
if (defined ($ARGV[0])) {
print "\tmysql_dump_file.sql ($ARGV[0])\n";
} else {
print "\tmysql_dump_file.sql (undefined)\n";
}
if (defined ($ARGV[1])) {
print "\tpg_dump_file.sql ($ARGV[1])\n";
} else {
print "\tpg_dump_file.sql (undefined)\n";
}
exit 1;
}
open(IN,"<$ARGV[0]") || die "can't open mysql dump file $ARGV[0]"; # Output for create table and create index
open(OUT,">$ARGV[1]") || die "can't open pg dump file $ARGV[1]"; sub output_create {
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 # If command ends with "xxx,);", we change to "xxx);"
sub output_create { $create_sql =~ s/,(\s*)\);/$1\);/m;
# 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; # If command ends with "xxx, -- yyy );", we change to "xxx -- yyy);"
if ($create_index) { $create_sql =~ s/,(\s*\-\-[^\)\n]*)(\s*)\);/$1\n\);/m;
print OUT "\n";
print OUT $create_index;
}
}
# Reset when moving from each "create table" to "insert" part of dump print $out $create_sql;
sub reset_vars() { if ($create_index) {
$create_sql=""; print $out "\n";
$create_index=""; print $out $create_index;
%enum_datafield=(); }
$enum_column=''; return;
} }
# Reset when moving from each "create table" to "insert" part of dump
sub reset_vars() {
$create_sql = "";
$create_index = "";
%enum_datafield = ();
$enum_column = '';
return;
}
# Boucle sur contenu fichier source # Boucle sur contenu fichier source
#---------------------------------- #----------------------------------
while(<IN>) { while (<$in>) {
# comments or empty lines # comments or empty lines
if (/^-- \$Id/) { if (/^-- \$Id/) {
$_ =~ s/\$//g; $_ =~ s/\$//g;
print OUT $_; print $out $_;
next; next;
} }
# comments or empty lines # comments or empty lines
if (/^#/ || /^$/ || /^--/) { if ( /^#/ || /^$/ || /^--/ ) {
print OUT $_; print $out $_;
next; next;
} }
if (/^USE\s*([^;]*);/) { if (/^USE\s*([^;]*);/) {
print OUT "\\c ". $1; print $out "\\c " . $1;
next; 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 if (/\);/i) { # end of create table sequence
$create_sql =~ s/,$//g; # strip last , inside create table $create_sql =~ s/,$//g; # strip last , inside create table
&output_create; &output_create;
&reset_vars(); &reset_vars();
next; next;
# LDR Added "innodb" and "engine"
}
elsif (/(ISAM|innodb)/i) { # end of create table sequence
s/\) *type=(MyISAM|innodb);/);/i;
s/\) *engine=(MyISAM|innodb);/);/i;
$create_sql =~ s/,$//g; # strip last , inside create table
$create_sql .= $_;
&output_create;
&reset_vars();
next;
}
# enum -> check # LDR Added "innodb" and "engine"
if (/([\w\"]*)\s+enum\s*\(((?:['"][\?\w]+['"]\s*,)+['"][\?\w]+['"])\)(.*)$/i) { }
$enum_column=$1; elsif (/(ISAM|innodb)/i) { # end of create table sequence
$enum_datafield{$enum_column}=$2; # 'abc','def', ... s/\) *type=(MyISAM|innodb);/);/i;
my $suite=$3; s/\) *engine=(MyISAM|innodb);/);/i;
my $maxlength=0; $create_sql =~ s/,$//g; # strip last , inside create table
foreach my $enum (split(',',$enum_datafield{$enum_column})) { $create_sql .= $_;
$enum =~ s/[\"\']//g; &output_create;
if ($maxlength<length($enum)) { $maxlength=length($enum); } &reset_vars();
} next;
$enum_datafield{$enum_column} =~ s/\"/\'/g; }
$_ = 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) {
$seq = qq~${table}_${1}_seq~;
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;
$size =~ tr [A-Z] [a-z];
if ($size eq "tiny" || $size eq "small") {
$out = "int2";
} elsif ($size eq "big") {
$out = "int8";
} else {
$out = "int4";
}
s/\w*int\(\d+\)/$out/g;
}
# tinyint -> smallint
elsif (/tinyint/i) {
s/tinyint/smallint/g;
}
# nuke unsigned # enum -> check
s/(int\w+|smallint)\s+unsigned/$1/gi; 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);
}
}
$enum_datafield{$enum_column} =~ s/\"/\'/g;
$_ =
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) {
$seq = qq~${table}_${1}_seq~;
s/[\s\t]*([a-zA-Z_0-9]*)\s*.*int.*auto_increment[^,]*/ $1 SERIAL PRIMARY KEY/ig;
$create_sql .= $_;
next;
# blob -> text # int type conversion
s/\w*blob/text/gi; }
elsif (/(\w*)int\(\d+\)/i) {
$size = $1;
$size =~ tr [A-Z] [a-z];
if ( $size eq "tiny" || $size eq "small" ) {
$out = "int2";
}
elsif ( $size eq "big" ) {
$out = "int8";
}
else {
$out = "int4";
}
s/\w*int\(\d+\)/$out/g;
}
# tinytext/mediumtext -> text # tinyint -> smallint
s/tinytext/text/gi; elsif (/tinyint/i) {
s/mediumtext/text/gi; s/tinyint/smallint/g;
}
# char -> varchar # nuke unsigned
# PostgreSQL would otherwise pad with spaces as opposed s/(int\w+|smallint)\s+unsigned/$1/gi;
# to MySQL! Your user interface may depend on this!
s/(\s+)char/${1}varchar/gi;
# nuke date representation (not supported in PostgreSQL) # blob -> text
s/datetime default '[^']+'/datetime/i; s/\w*blob/text/gi;
s/date default '[^']+'/datetime/i;
s/time default '[^']+'/datetime/i;
# change not null datetime field to null valid ones # tinytext/mediumtext -> text
# (to support remapping of "zero time" to null s/tinytext/text/gi;
s/datetime not null/datetime/i; s/mediumtext/text/gi;
s/datetime/timestamp/i;
# nuke size of timestamp # char -> varchar
s/timestamp\([^)]*\)/timestamp/i; # PostgreSQL would otherwise pad with spaces as opposed
# to MySQL! Your user interface may depend on this!
s/(\s+)char/${1}varchar/gi;
# double -> numeric # nuke date representation (not supported in PostgreSQL)
s/^double/numeric/i; s/datetime default '[^']+'/datetime/i;
s/(\s*)double/${1}numeric/i; s/date default '[^']+'/datetime/i;
s/time default '[^']+'/datetime/i;
# float -> numeric # change not null datetime field to null valid ones
s/^float/numeric/i; # (to support remapping of "zero time" to null
s/(\s*)float/${1}numeric/i; s/datetime not null/datetime/i;
s/datetime/timestamp/i;
# unique key(field1,field2) # nuke size of timestamp
if (/unique key\s*\((\w+\s*,\s*\w+)\)/i) { s/timestamp\([^)]*\)/timestamp/i;
s/unique key\s*\((\w+\s*,\s*\w+)\)/UNIQUE\($1\)/i;
$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.=$_;
next;
}
# unique key [name] (field) # double -> numeric
if (/unique key\s*(\w*)\s*\((\w+)\)/i) { s/^double/numeric/i;
s/unique key\s*(\w*)\s*\((\w+)\)/UNIQUE\($2\)/i; s/(\s*)double/${1}numeric/i;
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.=$_;
$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";
next;
}
# index(field) # float -> numeric
if (/index\s*(\w*)\s*\((\w+)\)/i) { s/^float/numeric/i;
my $idxname=($1?"$1":"idx_${table}_$2"); s/(\s*)float/${1}numeric/i;
$create_index .= "CREATE INDEX $idxname ON $table ($2);\n";
next;
}
# primary key # unique key(field1,field2)
if (/\bkey\b/i && !/^\s+primary key\s+/i) { if (/unique key\s*\((\w+\s*,\s*\w+)\)/i) {
s/KEY(\s+)[^(]*(\s+)/$1 UNIQUE $2/i; # hack off name of the non-primary key s/unique key\s*\((\w+\s*,\s*\w+)\)/UNIQUE\($1\)/i;
} $create_sql .= $_;
next;
}
# key(xxx) # unique index(field1,field2)
if (/key\s*\((\w+)\)/i) { if (/unique index\s*\((\w+\s*,\s*\w+)\)/i) {
my $idxname="idx_${table}_$1"; s/unique index\s*\((\w+\s*,\s*\w+)\)/UNIQUE\($1\)/i;
$create_index .= "CREATE INDEX $idxname ON $table ($1);\n"; $create_sql .= $_;
next; next;
} }
# Quote column names # unique key [name] (field)
s/(^\s*)([^\s\-\(]+)(\s*)/$1"$2"$3/gi if (!/\bkey\b/i); 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 .= $_;
$create_index .= "CREATE INDEX $idxname ON $table ($2);\n";
next;
}
# Remap columns with names of existing system attribute # unique index [name] (field)
if (/"oid"/i) { if (/unique index\s*(\w*)\s*\((\w+)\)/i) {
s/"oid"/"_oid"/g; s/unique index\s*(\w*)\s*\((\w+)\)/UNIQUE\($2\)/i;
print STDERR "WARNING: table $table uses column \"oid\" which is renamed to \"_oid\"\nYou should fix application manually! Press return to continue."; my $idxname = ( $1 ? "$1" : "idx_${table}_$2" );
my $wait=<STDIN>; $create_sql .= $_;
} $create_index .= "CREATE INDEX $idxname ON $table ($2);\n";
s/oid/_oid/i if (/key/i && /oid/i); # fix oid in key next;
$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) {
s!\x96!-!g; # --
s!\x93!"!g; # ``
s!\x94!"!g; # ''
s!\x85!... !g; # \ldots
s!\x92!`!g;
}
# fix dates '0000-00-00 00:00:00' (should be null) # unique (field) et unique (field1, field2 ...)
s/'0000-00-00 00:00:00'/null/gi; if (/unique\s*\(([\w,\s]+)\)/i) {
s/'0000-00-00'/null/gi; s/unique\s*\(([\w,\s]+)\)/UNIQUE\($1\)/i;
s/'00:00:00'/null/gi; my $fieldlist = "$1";
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'/; my $idxname = "idx_${table}_${fieldlist}";
$idxname =~ s/\W/_/g;
$idxname =~ tr/_/_/s;
$create_sql .= $_;
$create_index .=
"CREATE INDEX $idxname ON $table ($fieldlist);\n";
next;
}
if (/create\s+table\s+(\w+)/i) { # index(field)
$create_sql = $_; if (/index\s*(\w*)\s*\((\w+)\)/i) {
/create\s*table\s*(\w+)/i; my $idxname = ( $1 ? "$1" : "idx_${table}_$2" );
$table=$1 if (defined($1)); $create_index .= "CREATE INDEX $idxname ON $table ($2);\n";
} else { next;
print OUT $_; }
}
} # end of if inside create_table
} # END while(<IN>)
close IN; # primary key
close OUT; 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";
$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 );
# 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>;
}
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 ) {
s!\x96!-!g; # --
s!\x93!"!g; # ``
s!\x94!"!g; # ''
s!\x85!... !g; # \ldots
s!\x92!`!g;
}
# fix dates '0000-00-00 00:00:00' (should be null)
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'/;
if (/create\s+table\s+(\w+)/i) {
$create_sql = $_;
/create\s*table\s*(\w+)/i;
$table = $1 if ( defined($1) );
}
else {
print $out $_;
}
} # end of if inside create_table
} # END while(<IN>)
close $in;
close $out;
} }
print "\n"; print "\n";
print "Build ".(scalar keys %filelist)." file(s).\n"; print "Build " . ( scalar keys %filelist ) . " file(s).\n";
print "\n"; print "\n";
print "Press a key to finish...\n"; print "Press a key to finish...\n";
$stop=<STDIN>; $stop = <STDIN>;
0; 0;