1
0

check.pl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. #!/usr/bin/perl
  2. ################################################################################
  3. # $Id: check.pl 2823 2007-04-07 08:37:43Z warion $
  4. # $Date: 2007-04-07 03:37:43 -0500 (Sat, 07 Apr 2007) $
  5. # $Revision: 2823 $
  6. ################################################################################
  7. # #
  8. # LICENSE #
  9. # #
  10. # This program is free software; you can redistribute it and/or #
  11. # modify it under the terms of the GNU General Public License (GPL) #
  12. # as published by the Free Software Foundation; either version 2 #
  13. # of the License, or (at your option) any later version. #
  14. # #
  15. # This program is distributed in the hope that it will be useful, #
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of #
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  18. # GNU General Public License for more details. #
  19. # #
  20. # To read the license please visit http://www.gnu.org/copyleft/gpl.html #
  21. # #
  22. # #
  23. ################################################################################
  24. # #
  25. # check.pl is a simple script to check Perl-Module-Requirements. #
  26. # #
  27. ################################################################################
  28. use strict;
  29. ################################################################################
  30. # Internal Vars
  31. my ($VERSION, $DIR, $PROG, $EXTENSION, $USAGE);
  32. #-------------------------------------------------------------------------------
  33. # Main
  34. #-------------------------------------------------------------------------------
  35. # init some vars
  36. $VERSION =
  37. do { my @r = (q$Revision: 2823 $ =~ /\d+/g); sprintf "%d"."%02d" x $#r, @r };
  38. ($DIR=$0) =~ s/([^\/\\]*)$//;
  39. ($PROG=$1) =~ s/\.([^\.]*)$//;
  40. $EXTENSION=$1;
  41. # check args
  42. my $argCount = scalar(@ARGV);
  43. if ($argCount != 1) {
  44. printUsage();
  45. exit;
  46. }
  47. # ops
  48. if ($argCount == 1) {
  49. SWITCH: {
  50. $_ = shift @ARGV;
  51. /all/ && do { # --- all ---
  52. checkAll();
  53. exit;
  54. };
  55. /fluxd/ && do { # --- fluxd ---
  56. checkFluxd();
  57. exit;
  58. };
  59. /nzbperl/ && do { # --- nzbperl ---
  60. checkNzbperl();
  61. exit;
  62. };
  63. /ttools/ && do { # --- ttools ---
  64. checkTtools();
  65. exit;
  66. };
  67. /.*(version|-v).*/ && do { # --- version ---
  68. printVersion();
  69. exit;
  70. };
  71. /.*(help|-h).*/ && do { # --- help ---
  72. printUsage();
  73. exit;
  74. };
  75. printUsage();
  76. exit;
  77. }
  78. }
  79. # exit
  80. exit;
  81. #===============================================================================
  82. # Subs
  83. #===============================================================================
  84. #------------------------------------------------------------------------------#
  85. # Sub: checkAll #
  86. # Arguments: Null #
  87. # Returns: info on system requirements #
  88. #------------------------------------------------------------------------------#
  89. sub checkAll {
  90. # print
  91. print "checking all requirements...\n";
  92. # 1. fluxd
  93. checkFluxd();
  94. # 2. nzbperl
  95. checkNzbperl();
  96. # 3. ttools
  97. checkTtools();
  98. # done
  99. print "done checking all requirements.\n";
  100. }
  101. #------------------------------------------------------------------------------#
  102. # Sub: checkFluxd #
  103. # Arguments: Null #
  104. # Returns: info on system requirements #
  105. #------------------------------------------------------------------------------#
  106. sub checkFluxd {
  107. # print
  108. print "checking fluxd requirements...\n";
  109. my $errors = 0;
  110. my $warnings = 0;
  111. my @errorMessages = ();
  112. my @warningMessages = ();
  113. # 1. CORE-Perl-modules
  114. print "1. CORE-Perl-modules\n";
  115. my @mods = (
  116. 'IO::Select',
  117. 'IO::Socket::UNIX',
  118. 'IO::Socket::INET',
  119. 'POSIX'
  120. );
  121. foreach my $mod (@mods) {
  122. if (eval "require $mod") {
  123. print " - OK : ".$mod."\n";
  124. next;
  125. } else {
  126. $errors++;
  127. push(@errorMessages, "Loading of CORE-Perl-module ".$mod." failed.\n");
  128. print " - FAILED : ".$mod."\n";
  129. }
  130. }
  131. # 2. FluxDB-Perl-modules
  132. print "2. Database-Perl-modules\n";
  133. if (eval "require DBI") {
  134. print " - OK : DBI\n";
  135. } else {
  136. $warnings++;
  137. push(@warningMessages, "Loading of FluxDB-Perl-module DBI failed. fluxd cannot work in DBI/DBD-mode but only in PHP-mode.\n");
  138. print " - FAILED : DBI\n";
  139. }
  140. my $dbdwarnings = 0;
  141. @mods = (
  142. 'DBD::mysql',
  143. 'DBD::SQLite',
  144. 'DBD::Pg'
  145. );
  146. foreach my $mod (@mods) {
  147. if (eval "require $mod") {
  148. print " - OK : ".$mod."\n";
  149. next;
  150. } else {
  151. $dbdwarnings++;
  152. print " - FAILED : ".$mod."\n";
  153. }
  154. }
  155. if ($dbdwarnings == 3) {
  156. $warnings++;
  157. push(@warningMessages, "No DBD-Module could be loaded. fluxd cannot work in DBI/DBD-mode but only in PHP-mode.\n");
  158. }
  159. # 3. Result
  160. print "3. Result : ".(($errors == 0) ? "PASSED" : "FAILED")."\n";
  161. # failures
  162. if ($errors > 0) {
  163. print "Errors:\n";
  164. foreach my $msg (@errorMessages) {
  165. print $msg;
  166. }
  167. }
  168. # warnings
  169. if ($warnings > 0) {
  170. print "Warnings:\n";
  171. foreach my $msg (@warningMessages) {
  172. print $msg;
  173. }
  174. }
  175. # done
  176. print "done checking fluxd requirements.\n";
  177. }
  178. #------------------------------------------------------------------------------#
  179. # Sub: checkNzbperl #
  180. # Arguments: Null #
  181. # Returns: info on system requirements #
  182. #------------------------------------------------------------------------------#
  183. sub checkNzbperl {
  184. # print
  185. print "checking nzbperl requirements...\n";
  186. my $errors = 0;
  187. my $warnings = 0;
  188. my @errorMessages = ();
  189. my @warningMessages = ();
  190. # 1. CORE-Perl-modules
  191. print "1. CORE-Perl-modules\n";
  192. my @mods = (
  193. 'IO::File',
  194. 'IO::Select',
  195. 'IO::Socket::INET',
  196. 'File::Basename',
  197. 'Getopt::Long',
  198. 'Time::HiRes',
  199. 'Cwd',
  200. 'XML::Simple',
  201. 'XML::DOM'
  202. );
  203. foreach my $mod (@mods) {
  204. if (eval "require $mod") {
  205. print " - OK : ".$mod."\n";
  206. next;
  207. } else {
  208. $errors++;
  209. push(@errorMessages, "Loading of CORE-Perl-module ".$mod." failed.\n");
  210. print " - FAILED : ".$mod."\n";
  211. }
  212. }
  213. # 2. Perl-Threads
  214. my $threadproblems = 0;
  215. print "2. Perl-Threads\n";
  216. eval "use threads;";
  217. if ($@) {
  218. $warnings++;
  219. print " - FAILED : threads\n";
  220. $threadproblems++;
  221. } else {
  222. print " - OK : threads\n";
  223. }
  224. @mods = ('Thread::Queue');
  225. foreach my $mod (@mods) {
  226. if (eval "require $mod") {
  227. print " - OK : ".$mod."\n";
  228. next;
  229. } else {
  230. $warnings++;
  231. $threadproblems++;
  232. print " - FAILED : ".$mod."\n";
  233. }
  234. }
  235. if ($threadproblems != 0) {
  236. $warnings++;
  237. push(@warningMessages, "Could not use Perl thread modules.\n");
  238. }
  239. # 3. Result
  240. print "3. Result : ".(($errors == 0) ? "PASSED" : "FAILED")."\n";
  241. # failures
  242. if ($errors > 0) {
  243. print "Errors:\n";
  244. foreach my $msg (@errorMessages) {
  245. print $msg;
  246. }
  247. }
  248. # warnings
  249. if ($warnings > 0) {
  250. print "Warnings:\n";
  251. foreach my $msg (@warningMessages) {
  252. print $msg;
  253. }
  254. }
  255. # done
  256. print "done checking nzbperl requirements.\n";
  257. }
  258. #------------------------------------------------------------------------------#
  259. # Sub: checkTtools #
  260. # Arguments: Null #
  261. # Returns: info on system requirements #
  262. #------------------------------------------------------------------------------#
  263. sub checkTtools {
  264. # print
  265. print "checking ttools requirements...\n";
  266. my $errors = 0;
  267. my $warnings = 0;
  268. my @errorMessages = ();
  269. my @warningMessages = ();
  270. # 1. CORE-Perl-modules
  271. print "1. CORE-Perl-modules\n";
  272. my @mods = ('Digest::SHA1', 'LWP::UserAgent');
  273. foreach my $mod (@mods) {
  274. if (eval "require $mod") {
  275. print " - OK : ".$mod."\n";
  276. next;
  277. } else {
  278. $errors++;
  279. push(@errorMessages, "Loading of CORE-Perl-module ".$mod." failed.\n");
  280. print " - FAILED : ".$mod."\n";
  281. }
  282. }
  283. # 2. Result
  284. print "2. Result : ".(($errors == 0) ? "PASSED" : "FAILED")."\n";
  285. # failures
  286. if ($errors > 0) {
  287. print "Errors:\n";
  288. foreach my $msg (@errorMessages) {
  289. print $msg;
  290. }
  291. }
  292. # warnings
  293. if ($warnings > 0) {
  294. print "Warnings:\n";
  295. foreach my $msg (@warningMessages) {
  296. print $msg;
  297. }
  298. }
  299. # done
  300. print "done checking ttools requirements.\n";
  301. }
  302. #------------------------------------------------------------------------------#
  303. # Sub: printVersion #
  304. # Arguments: Null #
  305. # Returns: Null #
  306. #------------------------------------------------------------------------------#
  307. sub printVersion {
  308. print $PROG.".".$EXTENSION." Version ".$VERSION."\n";
  309. }
  310. #------------------------------------------------------------------------------#
  311. # Sub: printUsage #
  312. # Parameters: null #
  313. # Return: null #
  314. #------------------------------------------------------------------------------#
  315. sub printUsage {
  316. print <<"USAGE";
  317. $PROG.$EXTENSION (Revision $VERSION)
  318. Usage: $PROG.$EXTENSION type
  319. type may be : all/fluxd/nzbperl/ttools
  320. Examples:
  321. $PROG.$EXTENSION fluxd
  322. $PROG.$EXTENSION all
  323. USAGE
  324. }
  325. # EOF