makepack-dolibarrtheme.pl 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #!/usr/bin/perl
  2. #-----------------------------------------------------------------------------
  3. # \file build/makepack-dolibarrtheme.pl
  4. # \brief Script to build a theme Package for Dolibarr
  5. # \author (c)2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  6. #-----------------------------------------------------------------------------
  7. use Cwd;
  8. $PROJECT="dolibarr";
  9. @LISTETARGET=("TGZ"); # Possible packages
  10. %REQUIREMENTTARGET=( # Tool requirement for each package
  11. "TGZ"=>"tar",
  12. "ZIP"=>"7z",
  13. "RPM"=>"rpmbuild",
  14. "DEB"=>"dpkg-buildpackage",
  15. "EXE"=>"makensis.exe"
  16. );
  17. %ALTERNATEPATH=(
  18. "7z"=>"7-ZIP",
  19. "makensis.exe"=>"NSIS"
  20. );
  21. use vars qw/ $REVISION $VERSION /;
  22. $REVISION='1.11';
  23. $VERSION="1.0 (build $REVISION)";
  24. #------------------------------------------------------------------------------
  25. # MAIN
  26. #------------------------------------------------------------------------------
  27. ($DIR=$0) =~ s/([^\/\\]+)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1;
  28. $DIR||='.'; $DIR =~ s/([^\/\\])[\\\/]+$/$1/;
  29. # Detect OS type
  30. # --------------
  31. if ("$^O" =~ /linux/i || (-d "/etc" && -d "/var" && "$^O" !~ /cygwin/i)) { $OS='linux'; $CR=''; }
  32. elsif (-d "/etc" && -d "/Users") { $OS='macosx'; $CR=''; }
  33. elsif ("$^O" =~ /cygwin/i || "$^O" =~ /win32/i) { $OS='windows'; $CR="\r"; }
  34. if (! $OS) {
  35. print "$PROG.$Extension was not able to detect your OS.\n";
  36. print "Can't continue.\n";
  37. print "$PROG.$Extension aborted.\n";
  38. sleep 2;
  39. exit 1;
  40. }
  41. # Define buildroot
  42. # ----------------
  43. if ($OS =~ /linux/) {
  44. $TEMP=$ENV{"TEMP"}||$ENV{"TMP"}||"/tmp";
  45. }
  46. if ($OS =~ /macos/) {
  47. $TEMP=$ENV{"TEMP"}||$ENV{"TMP"}||"/tmp";
  48. }
  49. if ($OS =~ /windows/) {
  50. $TEMP=$ENV{"TEMP"}||$ENV{"TMP"}||"c:/temp";
  51. $PROGPATH=$ENV{"ProgramFiles"};
  52. }
  53. if (! $TEMP || ! -d $TEMP) {
  54. print "Error: A temporary directory can not be find.\n";
  55. print "Check that TEMP or TMP environment variable is set correctly.\n";
  56. print "makepack-dolibarrtheme.pl aborted.\n";
  57. sleep 2;
  58. exit 2;
  59. }
  60. $BUILDROOT="$TEMP/dolibarr-buildroot";
  61. my $copyalreadydone=0;
  62. my $batch=0;
  63. print "Makepack theme version $VERSION\n";
  64. print "Enter name of theme(s) to package (separated with space): ";
  65. $PROJECT=<STDIN>;
  66. chomp($PROJECT);
  67. @PROJECTLIST=split(/ /,$PROJECT);
  68. $PROJECT=join('',@PROJECTLIST);
  69. # Ask and set version $MAJOR and $MINOR
  70. print "Enter value for version: ";
  71. $PROJVERSION=<STDIN>;
  72. chomp($PROJVERSION);
  73. ($MAJOR,$MINOR)=split(/\./,$PROJVERSION,2);
  74. if ($MINOR eq '')
  75. {
  76. print "Enter value for minor version: ";
  77. $MINOR=<STDIN>;
  78. chomp($MINOR);
  79. }
  80. $FILENAME="$PROJECT";
  81. $FILENAMETGZ="theme_$PROJECT-$MAJOR.$MINOR";
  82. $FILENAMEZIP="theme_$PROJECT-$MAJOR.$MINOR";
  83. if (-d "/usr/src/redhat") {
  84. # redhat
  85. $RPMDIR="/usr/src/redhat";
  86. }
  87. if (-d "/usr/src/RPM") {
  88. # mandrake
  89. $RPMDIR="/usr/src/RPM";
  90. }
  91. $SOURCE="$DIR/..";
  92. $DESTI="$SOURCE/build";
  93. # Choose package targets
  94. #-----------------------
  95. $target="ZIP"; # Packages uses this format
  96. if ($target) {
  97. $CHOOSEDTARGET{uc($target)}=1;
  98. }
  99. else {
  100. my $found=0;
  101. my $NUM_SCRIPT;
  102. while (! $found) {
  103. my $cpt=0;
  104. printf(" %d - %3s (%s)\n",$cpt,"All","Need ".join(",",values %REQUIREMENTTARGET));
  105. foreach my $target (@LISTETARGET) {
  106. $cpt++;
  107. printf(" %d - %3s (%s)\n",$cpt,$target,"Need ".$REQUIREMENTTARGET{$target});
  108. }
  109. # Are asked to select the file to move
  110. print "Choose one package number or several separated with space: ";
  111. $NUM_SCRIPT=<STDIN>;
  112. chomp($NUM_SCRIPT);
  113. if ($NUM_SCRIPT =~ s/-//g) {
  114. # Do not do copy
  115. $copyalreadydone=1;
  116. }
  117. if ($NUM_SCRIPT !~ /^[0-$cpt\s]+$/)
  118. {
  119. print "This is not a valid package number list.\n";
  120. $found = 0;
  121. }
  122. else
  123. {
  124. $found = 1;
  125. }
  126. }
  127. print "\n";
  128. if ($NUM_SCRIPT) {
  129. foreach my $num (split(/\s+/,$NUM_SCRIPT)) {
  130. $CHOOSEDTARGET{$LISTETARGET[$num-1]}=1;
  131. }
  132. }
  133. else {
  134. foreach my $key (@LISTETARGET) {
  135. $CHOOSEDTARGET{$key}=1;
  136. }
  137. }
  138. }
  139. # Test if requirement is ok
  140. #--------------------------
  141. foreach my $target (keys %CHOOSEDTARGET) {
  142. foreach my $req (split(/[,\s]/,$REQUIREMENTTARGET{$target})) {
  143. # Test
  144. print "Test requirement for target $target: Search '$req'... ";
  145. $ret=`"$req" 2>&1`;
  146. $coderetour=$?; $coderetour2=$coderetour>>8;
  147. if ($coderetour != 0 && (($coderetour2 == 1 && $OS =~ /windows/ && $ret !~ /Usage/i) || ($coderetour2 == 127 && $OS !~ /windows/)) && $PROGPATH) {
  148. # Not found error, we try in PROGPATH
  149. $ret=`"$PROGPATH/$ALTERNATEPATH{$req}/$req\" 2>&1`;
  150. $coderetour=$?; $coderetour2=$coderetour>>8;
  151. $REQUIREMENTTARGET{$target}="$PROGPATH/$ALTERNATEPATH{$req}/$req";
  152. }
  153. if ($coderetour != 0 && (($coderetour2 == 1 && $OS =~ /windows/ && $ret !~ /Usage/i) || ($coderetour2 == 127 && $OS !~ /windows/))) {
  154. # Not found error
  155. print "Not found\nCan't build target $target. Requirement '$req' not found in PATH\n";
  156. $CHOOSEDTARGET{$target}=-1;
  157. last;
  158. } else {
  159. # Pas erreur ou erreur autre que programme absent
  160. print " Found ".$REQUIREMENTTARGET{$target}."\n";
  161. }
  162. }
  163. }
  164. print "\n";
  165. # Check if there is at least on target to build
  166. #----------------------------------------------
  167. $nboftargetok=0;
  168. foreach my $target (keys %CHOOSEDTARGET) {
  169. if ($CHOOSEDTARGET{$target} < 0) { next; }
  170. $nboftargetok++;
  171. }
  172. if ($nboftargetok) {
  173. # Update buildroot
  174. #-----------------
  175. if (! $copyalreadydone) {
  176. print "Delete directory $BUILDROOT\n";
  177. $ret=`rm -fr "$BUILDROOT"`;
  178. mkdir "$BUILDROOT";
  179. mkdir "$BUILDROOT/htdocs";
  180. mkdir "$BUILDROOT/htdocs/theme";
  181. print "Copy $SOURCE into $BUILDROOT\n";
  182. mkdir "$BUILDROOT";
  183. foreach my $tmp (@PROJECTLIST)
  184. {
  185. $ret=`cp -pr "$SOURCE/htdocs/theme/$tmp" "$BUILDROOT/htdocs/theme"`;
  186. }
  187. }
  188. print "Clean $BUILDROOT\n";
  189. $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`;
  190. $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*`;
  191. # Build package for each target
  192. #------------------------------
  193. foreach my $target (keys %CHOOSEDTARGET) {
  194. if ($CHOOSEDTARGET{$target} < 0) { next; }
  195. print "\nBuild package for target $target\n";
  196. if ($target eq 'TGZ') {
  197. unlink $FILENAMETGZ.tgz;
  198. print "Compress $BUILDROOT/htdocs into $FILENAMETGZ.tgz...\n";
  199. $cmd="tar --exclude-vcs --exclude-from \"$DESTI/tgz/tar_exclude.txt\" --directory \"$BUILDROOT\" --mode=go-w --group=500 --owner=500 -czvf \"$FILENAMETGZ.tgz\" htdocs";
  200. $ret=`$cmd`;
  201. if ($OS =~ /windows/i) {
  202. print "Move $FILENAMETGZ.tgz to $DESTI/$FILENAMETGZ.tgz\n";
  203. $ret=`mv "$FILENAMETGZ.tgz" "$DESTI/$FILENAMETGZ.tgz"`;
  204. }
  205. next;
  206. }
  207. if ($target eq 'ZIP') {
  208. unlink $FILENAMEZIP.zip;
  209. print "Compress $FILENAMETGZ into $FILENAMEZIP.zip...\n";
  210. chdir("$BUILDROOT");
  211. $ret=`7z a -r -tzip -mx $BUILDROOT/$FILENAMEZIP.zip htdocs`;
  212. print "Move $FILENAMEZIP.zip to $DESTI\n";
  213. $ret=`mv "$FILENAMEZIP.zip" "$DESTI/$FILENAMEZIP.zip"`;
  214. next;
  215. }
  216. }
  217. }
  218. print "\n----- Summary -----\n";
  219. foreach my $target (keys %CHOOSEDTARGET) {
  220. if ($CHOOSEDTARGET{$target} < 0) {
  221. print "Package $target not built (bad requirement).\n";
  222. } else {
  223. print "Package $target built succeessfully in $DESTI\n";
  224. }
  225. }
  226. if (! $btach) {
  227. print "\nPress key to finish...";
  228. my $WAITKEY=<STDIN>;
  229. }
  230. 0;