/
makepack-dolibarrmodule.pl
365 lines (308 loc) · 11.5 KB
/
makepack-dolibarrmodule.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#!/usr/bin/perl
#----------------------------------------------------------------------------
# \file build/makepack-dolibarrmodule.pl
# \brief Package builder (tgz, zip, rpm, deb, exe)
# \author (c)2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
#----------------------------------------------------------------------------
use Cwd;
@LISTETARGET=("TGZ"); # Possible packages
%REQUIREMENTTARGET=( # Tool requirement for each package
"TGZ"=>"tar",
"ZIP"=>"7z"
);
%ALTERNATEPATH=(
);
use vars qw/ $REVISION $VERSION /;
$REVISION='1.20';
$VERSION="1.0 (build $REVISION)";
#------------------------------------------------------------------------------
# MAIN
#------------------------------------------------------------------------------
($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) {
print "makepack-dolbarrmodule.pl was not able to detect your OS.\n";
print "Can't continue.\n";
print "makepack-dolibarrmodule.pl aborted.\n";
sleep 2;
exit 1;
}
# Define buildroot
# ----------------
if ($OS =~ /linux/) {
$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 (! $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-dolibarrmodule.pl aborted.\n";
sleep 2;
exit 2;
}
$BUILDROOT="$TEMP/dolibarr-buildroot";
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;
}
}
$SOURCE="$DIR/..";
$DESTI="$SOURCE/build";
if ($ENV{"DESTI"}) { $DESTI = $ENV{"DESTI"}; } # Force output dir if env DESTI is defined
print "Makepack for modules version $VERSION\n";
print "Source directory: $SOURCE\n";
print "Target directory: $DESTI\n";
# Ask and set version $MAJOR and $MINOR
print "Enter value for version: ";
$PROJVERSION=<STDIN>;
chomp($PROJVERSION);
($MAJOR,$MINOR,$BUILD)=split(/\./,$PROJVERSION,3);
if ($MINOR eq '')
{
print "Enter value for minor version: ";
$MINOR=<STDIN>;
chomp($MINOR);
}
# Ask module
print "Enter name for your module (mymodule, mywonderfulmondule, ... or 'all') : ";
$PROJECTINPUT=<STDIN>;
chomp($PROJECTINPUT);
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;
}
}
}
else
{
@PROJECTLIST=($PROJECTINPUT);
}
# Loop on each projects
foreach my $PROJECT (@PROJECTLIST) {
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 "makepack-dolibarrmodule.pl aborted.\n";
sleep 2;
exit 2;
}
$FILENAME="$PROJECT";
$FILENAMETGZ="module_$PROJECT-$MAJOR.$MINOR";
$FILENAMEZIP="module_$PROJECT-$MAJOR.$MINOR";
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;
# Test if requirement is ok
#--------------------------
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) {
# 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";
# Check if there is at least on 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')
{
$nboftargetneedbuildroot++;
}
if ($target eq 'SNAPSHOT')
{
$nboftargetneedcvs++;
}
$nboftargetok++;
}
if ($nboftargetok) {
# Update CVS if required
#-----------------------
if ($nboftargetneedcvs)
{
print "Go to directory $SOURCE\n";
$olddir=getcwd();
chdir("$SOURCE");
print "Run cvs update -P -d\n";
$ret=`cvs update -P -d 2>&1`;
chdir("$olddir");
}
# Update buildroot if required
#-----------------------------
if ($nboftargetneedbuildroot)
{
if (! $copyalreadydone) {
print "Delete directory $BUILDROOT\n";
$ret=`rm -fr "$BUILDROOT"`;
mkdir "$BUILDROOT";
mkdir "$BUILDROOT/$PROJECT";
$result=open(IN,"<makepack-".$PROJECT.".conf");
if (! $result) { die "Error: Can't open conf file makepack-".$PROJECT.".conf for reading.\n"; }
while(<IN>)
{
if ($_ =~ /^#/) { next; } # Do not process comments
$_ =~ s/\n//;
$_ =~ /^(.*)\/[^\/]+/;
print "Create directory $BUILDROOT/$PROJECT/$1\n";
$ret=`mkdir -p "$BUILDROOT/$PROJECT/$1"`;
if ($_ !~ /version\-/)
{
print "Copy $SOURCE/$_ into $BUILDROOT/$PROJECT/$_\n";
$ret=`cp -pr "$SOURCE/$_" "$BUILDROOT/$PROJECT/$_"`;
}
}
close IN;
@timearray=localtime(time());
$fulldate=($timearray[5]+1900).'-'.($timearray[4]+1).'-'.$timearray[3].' '.$timearray[2].':'.$timearray[1];
open(VF,">$BUILDROOT/$PROJECT/build/version-".$PROJECT.".txt");
print "Create version file $BUILDROOT/$PROJECT/build/version-".$PROJECT.".txt with date ".$fulldate."\n";
$ret=`mkdir -p "$BUILDROOT/$PROJECT/build"`;
print VF "Version: ".$MAJOR.".".$MINOR."\n";
print VF "Build : ".$fulldate."\n";
close VF;
}
print "Clean $BUILDROOT\n";
$ret=`rm -fr $BUILDROOT/$PROJECT/.cache`;
$ret=`rm -fr $BUILDROOT/$PROJECT/.project`;
$ret=`rm -fr $BUILDROOT/$PROJECT/.settings`;
$ret=`rm -fr $BUILDROOT/$PROJECT/index.php`;
$ret=`rm -fr $BUILDROOT/$PROJECT/build/html`;
$ret=`rm -fr $BUILDROOT/$PROJECT/documents`;
$ret=`rm -fr $BUILDROOT/$PROJECT/document`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/conf/conf.php.mysql`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/conf/conf.php.old`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/conf/conf.php.postgres`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/conf/conf*sav*`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/custom`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/custom2`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/theme/bureau2crea`;
$ret=`rm -fr $BUILDROOT/$PROJECT/test`;
$ret=`rm -fr $BUILDROOT/$PROJECT/Thumbs.db $BUILDROOT/$PROJECT/*/Thumbs.db $BUILDROOT/$PROJECT/*/*/Thumbs.db $BUILDROOT/$PROJECT/*/*/*/Thumbs.db $BUILDROOT/$PROJECT/*/*/*/*/Thumbs.db`;
$ret=`rm -fr $BUILDROOT/$PROJECT/CVS* $BUILDROOT/$PROJECT/*/CVS* $BUILDROOT/$PROJECT/*/*/CVS* $BUILDROOT/$PROJECT/*/*/*/CVS* $BUILDROOT/$PROJECT/*/*/*/*/CVS* $BUILDROOT/$PROJECT/*/*/*/*/*/CVS*`;
}
# Build package for each target
#------------------------------
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'; }
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"`;
}
else
{
$ret=`mv "$FILENAMETGZ.tgz" "$NEWDESTI/$FILENAMETGZ.tgz"`;
}
next;
}
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/$PROJECT\n";
$olddir=getcwd();
chdir("$BUILDROOT/$PROJECT");
$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"`;
next;
}
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\\build\\exe\\$FILENAME.nsi\"";
print "$command\n";
$ret=`$command`;
print "Move $FILENAMEEXE.exe to $NEWDESTI\n";
rename("$SOURCE\\build\\exe\\$FILENAMEEXE.exe","$NEWDESTI/$FILENAMEEXE.exe");
next;
}
}
}
print "\n----- Summary -----\n";
foreach my $target (keys %CHOOSEDTARGET) {
if ($CHOOSEDTARGET{$target} < 0) {
print "Package $target not built (bad requirement).\n";
} else {
print "Package $target built successfully in $NEWDESTI\n";
}
}
}
if (! $batch) {
print "\nPress key to finish...";
my $WAITKEY=<STDIN>;
}
0;