Main Koha release repository https://koha-community.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1831 lines
67 KiB

  1. # Copyright 2007 MJ Ray
  2. # Copyright 2016 PTFS Europe
  3. #
  4. # This file is part of Koha.
  5. #
  6. # Koha is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Koha is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Koha; if not, see <http://www.gnu.org/licenses>.
  18. #
  19. # Current maintainer MJR http://mjr.towers.org.uk/
  20. #
  21. use strict;
  22. use warnings;
  23. use ExtUtils::MakeMaker;
  24. use POSIX;
  25. use File::Spec;
  26. use Getopt::Long qw/HelpMessage/;
  27. use FindBin; # we need to enforce which C4::Installer::PerlModule is used in case more than one is installed
  28. use lib $FindBin::Bin;
  29. use C4::Installer::PerlModules;
  30. my $koha_pm = C4::Installer::PerlModules->new;
  31. my $DEBUG = 0;
  32. die "perl 5.10 or later required" unless ($] >= 5.010000);
  33. # Hash up directory structure & files beginning with the directory we were called from (should be the base of koha)...
  34. my $dirtree = hashdir('.');
  35. my %result = ();
  36. =head1 NAME
  37. Makefile.PL - Koha packager and installer
  38. =head1 SYNOPSIS
  39. =head2 BASIC INSTALLATION
  40. perl Makefile.PL
  41. make
  42. make test
  43. sudo make install
  44. =head2 UPGRADE INSTALLATION
  45. NOTE: This option is only available if koha-install-log exists.
  46. perl Makefile.PL --prev-install-log /path/to/koha-install-log
  47. make
  48. make test
  49. sudo make upgrade
  50. =head2 PACKAGING RELEASE TARBALLS
  51. make manifest tardist
  52. make manifest zipdist
  53. =head2 CLEANING UP
  54. make clean
  55. =head2 CLI PARAMETERS
  56. --prev-install-log Read configuration from previous installation
  57. --install_mode Installation mode (dev, standard, single)
  58. --db_type Database (mysql, Pg)
  59. --db_host Database host (e.g. localhost)
  60. --db_port Database port (e.g. 3306)
  61. --db_name Database name (e.g. koha)
  62. --db_user Database user (e.g. kohaadmin)
  63. --db_pass Database password (e.g. katikoan)
  64. --zebra_marc_format Zebra MARC format (marc21, normarc, unimarc)
  65. --zebra_language Zebra language (e.g. en)
  66. --zebra_tokenizer Zebra tokenizer (chr, icu)
  67. --zebra_user Zebra user (e.g. kohauser)
  68. --zebra_pass Zebra password (e.g. zebrastripes)
  69. --zebra_sru_host Zebra SRU servername (e.g. localhost)
  70. --zebra_sru_biblios_port Zebra SRU biblios port (e.g. 9998)
  71. --zebra_sru_authorities_port Zebra SRU biblios port (e.g. 9999)
  72. --koha_user Koha Unix user (e.g. koha)
  73. --koha_group Koha Unix group (e.g. koha)
  74. --install_sru Install the SRU server (yes, no)
  75. --use_memcached Use Memcached (yes, no)
  76. --font_dir Location of fonts (e.g. /usr/share/fonts/truetype/dejavu)
  77. --run_database_tests Run database dependent tests (yes, no)
  78. --install_base Base directory of installation (e.g. /usr/share/koha)
  79. --template-cache-dir Specify a template cache directory (e.g. /var/cache/koha)
  80. --help Display this help message
  81. =head1 DESCRIPTION
  82. This is a packager and installer that uses
  83. ExtUtils::MakeMaker, which is fairly common
  84. on perl systems.
  85. As well as building tar or zip files
  86. and installing with the above commands,
  87. it allows us to check pre-requisites
  88. and generate configuration files.
  89. =head1 VARIABLES
  90. =head2 NAME, VERSION_FROM, ABSTRACT, AUTHOR
  91. Basic metadata about this software.
  92. =head2 NO_META
  93. Suppress generation of META.yml file.
  94. =head2 PREREQ_PM
  95. Hash of perl modules and versions required.
  96. =head2 PM
  97. Hash of file mappings
  98. =head2 PL_FILES
  99. This is a hash of PL scripts to run after installation and
  100. the files to ask them to generate.
  101. Maybe use the values from CONFIGURE
  102. to generate initial configuration files in future.
  103. =cut
  104. =head2 target_map
  105. This is a hash mapping directories and files in the
  106. source tree to installation target directories. The rules
  107. for this mapping are:
  108. =over 4
  109. =item If a directory or file is specified, it and its
  110. contents will be copied to the installation target directory.
  111. =item If a subdirectory of a mapped directory is specified,
  112. its target overrides the parent's target for that subdirectory.
  113. =item The value of each map entry may either be a scalar containing
  114. one target or a reference to a hash containing 'target' and 'trimdir'
  115. keys.
  116. =item Any files at the top level of the source tree that are
  117. not included in the map will not be installed.
  118. =item Any directories at the top level of the source tree
  119. that are not included in the map will be installed in
  120. INTRANET_CGI_DIR. This is a sensible default given the
  121. current organization of the source tree, but (FIXME) it
  122. would be better to reorganize the source tree to better
  123. match the installation system, to allow adding new directories
  124. without having to adjust Makefile.PL each time. The idea
  125. is to make the C<$target_map> hash as minimal as possible.
  126. =back
  127. The permitted installation targets are:
  128. =over 4
  129. =item INTRANET_CGI_DIR
  130. CGI scripts for intranet (staff) interface.
  131. =item INTRANET_TMPL_DIR
  132. HTML templates for the intranet interface.
  133. =item INTRANET_WWW_DIR
  134. HTML files, images, etc. for DocumentRoot for the intranet interface.
  135. =item OPAC_CGI_DIR
  136. CGI scripts for OPAC (public) interface.
  137. =item OPAC_TMPL_DIR
  138. HTML templates for the OPAC interface.
  139. =item OPAC_WWW_DIR
  140. HTML files, images, etc. for DocumentRoot for the OPAC interface.
  141. =item PERL_MODULE_DIR
  142. Perl modules (at present just the C4 modules) that are intimately
  143. tied to Koha. Depending on the installation options, these
  144. may or may not be installed one of the standard directories
  145. in Perl's default @LIB.
  146. =item KOHA_CONF_DIR
  147. Directory for Koha configuration files.
  148. =item ZEBRA_CONF_DIR
  149. Directory for Zebra configuration files.
  150. =item ZEBRA_LOCK_DIR
  151. Directory for Zebra's lock files. This includes subdirs for authorities,
  152. biblios, and the zebra rebuild function. Any activity to reindex
  153. zebra from koha should interlock here with rebuild_zebra.pl.
  154. =item ZEBRA_DATA_DIR
  155. Directory for Zebra's data files.
  156. =item ZEBRA_RUN_DIR
  157. Directory for Zebra's UNIX-domain sockets.
  158. =item ELASTICSEARCH_SERVERS
  159. Server:port of the Elasticsearch server to use, as a comma separated list:
  160. eg. 192.168.0.100:9200, localhost:9200
  161. =item ELASTICSEARCH_INDEX
  162. Unique index in Elasticsearch, for this Koha-instance
  163. eg. koha-mykoha or just koha
  164. =item MISC_DIR
  165. Directory for for miscellaenous scripts, among other
  166. things the translation toolkit and RSS feed tools.
  167. =item SCRIPT_DIR
  168. Directory for command-line scripts and daemons to
  169. be set up all for installation modes.
  170. =item SCRIPT_NONDEV_DIR
  171. Directory for command-line scripts that should
  172. be installed in the same directory as the
  173. SCRIPT_DIR target except 'dev' installs.
  174. =item MAN_DIR
  175. Directory for man pages created from POD -- will mostly
  176. contain information of interest to Koha developers.
  177. =item DOC_DIR
  178. Directory for Koha documentation accessed from the
  179. command-line, e.g., READMEs.
  180. =item LOCK_DIR
  181. Directory for Koha scripts to put their locks.
  182. =item LOG_DIR
  183. Directory for Apache and Zebra logs produced by Koha.
  184. =item BACKUP_DIR
  185. Directory for backup files produced by Koha.
  186. =item PLUGINS_DIR
  187. Directory for external Koha plugins.
  188. =item FONT_DIR
  189. Directory where DejaVu fonts are installed.
  190. =item NONE
  191. This is a dummy target used to explicitly state
  192. that a given file or directory is not to be installed.
  193. This is used either for parts of the installer itself
  194. or for development tools that are not applicable to a
  195. production installation.
  196. =back
  197. =cut
  198. my $target_map = {
  199. './about.pl' => 'INTRANET_CGI_DIR',
  200. './acqui' => 'INTRANET_CGI_DIR',
  201. './admin' => 'INTRANET_CGI_DIR',
  202. './api' => { target => 'API_CGI_DIR', trimdir => -1 },
  203. './app.psgi' => 'SCRIPT_DIR',
  204. './authorities' => 'INTRANET_CGI_DIR',
  205. './basket' => 'INTRANET_CGI_DIR',
  206. './bin' => { target => 'SCRIPT_DIR', trimdir => -1 },
  207. './C4' => 'PERL_MODULE_DIR',
  208. './C4/SIP/t' => 'NONE',
  209. './C4/SIP/koha_test' => 'NONE',
  210. './C4/tests' => 'NONE',
  211. './catalogue' => 'INTRANET_CGI_DIR',
  212. './cataloguing' => 'INTRANET_CGI_DIR',
  213. './changelanguage.pl' => 'INTRANET_CGI_DIR',
  214. './check_sysprefs.pl' => 'NONE',
  215. './circ' => 'INTRANET_CGI_DIR',
  216. './clubs' => 'INTRANET_CGI_DIR',
  217. './course_reserves' => 'INTRANET_CGI_DIR',
  218. './cpanfile' => 'PERL_MODULE_DIR',
  219. './docs/history.txt' => { target => 'DOC_DIR', trimdir => -1 },
  220. './docs/contributors.yaml' => { target => 'DOC_DIR', trimdir => -1 },
  221. './docs/teams.yaml' => { target => 'DOC_DIR', trimdir => -1 },
  222. './offline_circ' => 'INTRANET_CGI_DIR',
  223. './etc' => { target => 'KOHA_CONF_DIR', trimdir => -1 },
  224. './etc/zebradb' => { target => 'ZEBRA_CONF_DIR', trimdir => -1 },
  225. './etc/z3950' => { target => 'Z3950_CONF_DIR', trimdir => -1 },
  226. './help.pl' => 'INTRANET_CGI_DIR',
  227. './ill' => 'INTRANET_CGI_DIR',
  228. './installer-CPAN.pl' => 'NONE',
  229. './installer' => 'INTRANET_CGI_DIR',
  230. './errors' => {target => 'INTRANET_CGI_DIR'},
  231. './Koha' => 'PERL_MODULE_DIR',
  232. './Koha.pm' => 'PERL_MODULE_DIR',
  233. './koha-tmpl/intranet-tmpl' => {target => 'INTRANET_TMPL_DIR', trimdir => -1},
  234. './koha-tmpl/opac-tmpl' => {target => 'OPAC_TMPL_DIR', trimdir => -1},
  235. './kohaversion.pl' => 'INTRANET_CGI_DIR',
  236. './labels' => 'INTRANET_CGI_DIR',
  237. './lib' => {target => 'PERL_MODULE_LIB_DIR', trimdir => -1},
  238. './mainpage.pl' => 'INTRANET_CGI_DIR',
  239. './Makefile.PL' => 'NONE',
  240. './MANIFEST.SKIP' => 'NONE',
  241. './members' => 'INTRANET_CGI_DIR',
  242. './misc' => { target => 'SCRIPT_NONDEV_DIR', trimdir => -1 },
  243. './misc/bin' => { target => 'SCRIPT_DIR', trimdir => -1 },
  244. './misc/release_notes' => { target => 'DOC_DIR', trimdir => 2 },
  245. './misc/translator' => { target => 'MISC_DIR', trimdir => 2 },
  246. './misc/koha-install-log' => { target => 'MISC_DIR', trimdir => -1 },
  247. './misc/installer_devel_notes' => 'NONE',
  248. './opac' => 'OPAC_CGI_DIR',
  249. './OpenILS' => 'PERL_MODULE_DIR',
  250. './README.txt' => 'NONE',
  251. './patroncards' => 'INTRANET_CGI_DIR',
  252. './patron_lists' => 'INTRANET_CGI_DIR',
  253. './plugins' => 'INTRANET_CGI_DIR',
  254. './pos' => 'INTRANET_CGI_DIR',
  255. './reports' => 'INTRANET_CGI_DIR',
  256. './reserve' => 'INTRANET_CGI_DIR',
  257. './reviews' => 'INTRANET_CGI_DIR',
  258. './rewrite-config.PL' => 'NONE',
  259. './reviews' => 'INTRANET_CGI_DIR',
  260. './rotating_collections' => 'INTRANET_CGI_DIR',
  261. './serials' => 'INTRANET_CGI_DIR',
  262. './services' => 'INTRANET_CGI_DIR',
  263. './skel' => 'NONE',
  264. './skel/var/lock/koha' => { target => 'LOCK_DIR', trimdir => -1 },
  265. './skel/var/log/koha' => { target => 'LOG_DIR', trimdir => -1 },
  266. './skel/var/spool/koha' => { target => 'BACKUP_DIR', trimdir => -1 },
  267. './skel/var/run/koha/zebradb' => { target => 'ZEBRA_RUN_DIR', trimdir => -1 },
  268. './skel/var/lock/koha/zebradb/authorities' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
  269. './skel/var/lib/koha/zebradb/authorities/key' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
  270. './skel/var/lib/koha/zebradb/authorities/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
  271. './skel/var/lib/koha/zebradb/authorities/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
  272. './skel/var/lib/koha/zebradb/authorities/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
  273. './skel/var/lock/koha/zebradb/biblios' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
  274. './skel/var/lib/koha/zebradb/biblios/key' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
  275. './skel/var/lib/koha/zebradb/biblios/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
  276. './skel/var/lib/koha/zebradb/biblios/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
  277. './skel/var/lib/koha/zebradb/biblios/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
  278. './skel/var/lock/koha/zebradb/rebuild' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
  279. './skel/var/lib/koha/plugins' => { target => 'PLUGINS_DIR', trimdir => 6 },
  280. './sms' => 'INTRANET_CGI_DIR',
  281. './suggestion' => 'INTRANET_CGI_DIR',
  282. './svc' => 'INTRANET_CGI_DIR',
  283. './t' => 'NONE',
  284. './xt' => 'NONE',
  285. './tags' => 'INTRANET_CGI_DIR',
  286. './tmp' => 'NONE', # FIXME need to determine whether
  287. # Koha generates any persistent temp files
  288. # that should go in /var/tmp/koha
  289. './tools' => 'INTRANET_CGI_DIR',
  290. './virtualshelves' => 'INTRANET_CGI_DIR',
  291. # ignore files and directories created by the install itself
  292. './pm_to_blib' => 'NONE',
  293. './blib' => 'NONE',
  294. '.sass-lint.yml' => 'NONE',
  295. '.scss-lint.yml' => 'NONE',
  296. '.eslintrc.json' => 'NONE',
  297. 'gulpfile.js' => 'NONE',
  298. 'package.json' => 'NONE',
  299. 'yarn.lock' => 'NONE',
  300. };
  301. =head1 CONFIGURATION OPTIONS
  302. The following configuration options are used by the installer.
  303. =over 4
  304. =item INSTALL_MODE
  305. Specifies whether installation will be FHS-compliant (default,
  306. assumes user has root), put everything under
  307. a single directory (for users installing on a web host
  308. that allows CGI scripts and a MySQL database but not root
  309. access), or development (for a developer who wants to run
  310. Koha from a git clone with no fuss).
  311. =item INSTALL_BASE
  312. Directory under which most components will go. Default
  313. value will vary depending on INSTALL_MODE.
  314. =item DB_TYPE
  315. Type of DBMS (e.g., mysql or Pg).
  316. =item DB_HOST
  317. Name of DBMS server.
  318. =item DB_PORT
  319. Port that DBMS server is listening on.
  320. =item DB_NAME
  321. Name of the DBMS database for Koha.
  322. =item DB_USER
  323. Name of DBMS user account for Koha's database.
  324. =item DB_PASS
  325. Pasword of DMBS user account for Koha's database.
  326. =item ZEBRA_MARC_FORMAT
  327. Specifies format of MARC records to be indexed by Zebra.
  328. =item ZEBRA_LANGUAGE
  329. Specifies primary language of records that will be
  330. indexed by Zebra.
  331. =item ZEBRA_USER
  332. Internal Zebra user account for the index.
  333. =item ZEBRA_PASS
  334. Internal Zebra user account's password.
  335. =item KOHA_USER
  336. System user account that will own Koha's files.
  337. =item KOHA_GROUP
  338. System group that will own Koha's files.
  339. =item SMTP_HOST
  340. SMTP server host name (default: localhost)
  341. =item SMTP_PORT
  342. SMTP server port (default: 25)
  343. =item SMTP_TIMEOUT
  344. Connection timeour in seconds (default: 120)
  345. =item SMTP_SSL_MODE
  346. SSL mode. Options are 'disabled' (default), 'ssl' and 'starttls'
  347. =item SMTP_USER_NAME
  348. SMTP authentication user name
  349. =item SMTP_PASSWORD
  350. SMTP authentication password
  351. =item SMTP_DEBUG
  352. Enable debug mode for SMTP (default: no)
  353. =back
  354. =cut
  355. # default configuration options
  356. my %config_defaults = (
  357. 'DB_TYPE' => 'mysql',
  358. 'DB_HOST' => 'localhost',
  359. 'DB_NAME' => 'koha',
  360. 'DB_USER' => 'kohaadmin',
  361. 'DB_PASS' => 'katikoan',
  362. 'DB_USE_TLS' => 'no',
  363. 'DB_TLS_CA_CERTIFICATE' => '/etc/mysql-ssl/server-ca.pem',
  364. 'DB_TLS_CLIENT_CERTIFICATE' => '/etc/mysql-ssl/client-cert.pem',
  365. 'DB_TLS_CLIENT_KEY' => '/etc/mysql-ssl/client-key.pem',
  366. 'INSTALL_SRU' => 'yes',
  367. 'ZEBRA_MARC_FORMAT' => 'marc21',
  368. 'ZEBRA_LANGUAGE' => 'en',
  369. 'ZEBRA_TOKENIZER' => 'chr',
  370. 'ZEBRA_USER' => 'kohauser',
  371. 'ZEBRA_PASS' => 'zebrastripes',
  372. 'ZEBRA_SRU_HOST' => 'localhost',
  373. 'ZEBRA_SRU_BIBLIOS_PORT' => '9998',
  374. 'ZEBRA_SRU_AUTHORITIES_PORT' => '9999',
  375. 'KOHA_USER' => 'koha',
  376. 'KOHA_GROUP' => 'koha',
  377. 'MERGE_SERVER_HOST' => 'localhost',
  378. 'MERGE_SERVER_PORT' => '11001',
  379. 'RUN_DATABASE_TESTS' => 'no',
  380. 'PATH_TO_ZEBRA' => '',
  381. 'USE_MEMCACHED' => 'yes',
  382. 'MEMCACHED_SERVERS' => '127.0.0.1:11211',
  383. 'MEMCACHED_NAMESPACE' => 'KOHA',
  384. 'TEMPLATE_CACHE_DIR' => '/tmp/koha',
  385. 'USE_ELASTICSEARCH' => 'no',
  386. 'ELASTICSEARCH_SERVERS' => 'localhost:9200',
  387. 'ELASTICSEARCH_INDEX' => 'koha',
  388. 'FONT_DIR' => '/usr/share/fonts/truetype/dejavu',
  389. 'SMTP_HOST' => 'localhost',
  390. 'SMTP_PORT' => '25',
  391. 'SMTP_TIMEOUT' => '120',
  392. 'SMTP_SSL_MODE' => 'disabled',
  393. 'SMTP_USER_NAME' => '',
  394. 'SMTP_PASSWORD' => '',
  395. 'SMTP_DEBUG' => 'no',
  396. );
  397. # set some default configuration options based on OS
  398. # more conditions need to be added for other OS's
  399. warn "Your platform appears to be $^O.\n" if $DEBUG;
  400. if ( $^O eq 'cygwin' ) {
  401. # Most Unix2Win32 ports seem to poke everything into the Program Files directory
  402. # this could be changed to put some files (ie. libraries) into system32, etc.
  403. $config_defaults{'INSTALL_MODE'} = 'single';
  404. $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha'; # Use 8.3 names to be safe...
  405. }
  406. else {
  407. $config_defaults{'INSTALL_MODE'} = 'standard';
  408. $config_defaults{'INSTALL_BASE'} = '/usr/share/koha';
  409. }
  410. # valid values for certain configuration options
  411. my %valid_config_values = (
  412. 'INSTALL_MODE' => { 'standard' => 1, 'single' => 1, 'dev' => 1 },
  413. 'DB_TYPE' => { 'mysql' => 1, 'Pg' => 1 },
  414. 'DB_USE_TLS' => {'yes', 'no'},
  415. 'INSTALL_SRU' => { 'yes' => 1, 'no' => 1 },
  416. 'ZEBRA_MARC_FORMAT' => { 'marc21' => 1, 'normarc' => 1, 'unimarc' => 1 }, # FIXME should generate from contents of distributation
  417. 'ZEBRA_LANGUAGE' => { 'cs' => 1, 'el' => 1, 'en' => 1, 'es' => 1, 'fr' => 1, 'nb' => 1, 'ru' => 1, 'uk' => 1 }, # FIXME should generate from contents of distribution
  418. 'ZEBRA_TOKENIZER' => { chr => 1, icu => 1 },
  419. 'RUN_DATABASE_TESTS' => { 'yes' => 1, 'no' => 1 },
  420. 'USE_MEMCACHED' => { 'yes' => 1, 'no' => 1 },
  421. 'USE_ELASTICSEARCH' => { 'yes' => 1, 'no' => 1 },
  422. 'SMTP_SSL_MODE' => { 'disabled' => 1, 'ssl' => 1, 'starttls' => 1 },
  423. 'SMTP_DEBUG' => { 'yes' => 1, 'no' => 1 },
  424. );
  425. # get settings from command-line
  426. my $koha_install_log = "";
  427. my $cli_koha_install_mode = "";
  428. my $cli_koha_db_type = "";
  429. my $cli_koha_db_host = "";
  430. my $cli_koha_db_port = "";
  431. my $cli_koha_db_name = "";
  432. my $cli_koha_db_user = "";
  433. my $cli_koha_db_pass = "";
  434. my $cli_zebra_marc_format = "";
  435. my $cli_zebra_language = "",
  436. my $cli_zebra_tokenizer = "";
  437. my $cli_zebra_user = "";
  438. my $cli_zebra_pass = "";
  439. my $cli_zebra_sru_host = "";
  440. my $cli_zebra_sru_bib_port = "";
  441. my $cli_zebra_sru_auth_port = "";
  442. my $cli_koha_user = "";
  443. my $cli_koha_group = "";
  444. my $cli_koha_install_sru = "";
  445. my $cli_koha_use_memcached = "";
  446. my $cli_koha_font_dir = "";
  447. my $cli_koha_run_database_tests = "";
  448. my $cli_koha_install_base = "";
  449. my $cli_koha_template_cache_dir = "";
  450. my $cli_smtp_host = "";
  451. my $cli_smtp_port = "";
  452. my $cli_smtp_timeout = "";
  453. my $cli_smtp_ssl_mode = "";
  454. my $cli_smtp_user_name = "";
  455. my $cli_smtp_password = "";
  456. my $cli_smtp_debug = "";
  457. Getopt::Long::Configure('pass_through');
  458. my $results = GetOptions(
  459. "prev-install-log=s" => \$koha_install_log,
  460. "install_mode=s" => \$cli_koha_install_mode,
  461. "db_type=s" => \$cli_koha_db_type,
  462. "db_host=s" => \$cli_koha_db_host,
  463. "db_port=s" => \$cli_koha_db_port,
  464. "db_name=s" => \$cli_koha_db_name,
  465. "db_user=s" => \$cli_koha_db_user,
  466. "db_pass=s" => \$cli_koha_db_pass,
  467. "zebra_marc_format=s" => \$cli_zebra_marc_format,
  468. "zebra_language=s" => \$cli_zebra_language,
  469. "zebra_tokenizer=s" => \$cli_zebra_tokenizer,
  470. "zebra_user=s" => \$cli_zebra_user,
  471. "zebra_pass=s" => \$cli_zebra_pass,
  472. "zebra_sru_host=s" => \$cli_zebra_sru_host,
  473. "zebra_sru_biblios_port=s" => \$cli_zebra_sru_bib_port,
  474. "zebra_sru_authorities_port=s" => \$cli_zebra_sru_auth_port,
  475. "koha_user=s" => \$cli_koha_user,
  476. "koha_group=s" => \$cli_koha_group,
  477. "install_sru=s" => \$cli_koha_install_sru,
  478. "use_memcached=s" => \$cli_koha_use_memcached,
  479. "font_dir=s" => \$cli_koha_font_dir,
  480. "run_database_tests=s" => \$cli_koha_run_database_tests,
  481. "install_base=s" => \$cli_koha_install_base,
  482. "template-cache-dir=s" => \$cli_koha_template_cache_dir,
  483. "smtp-host=s" => \$cli_smtp_host,
  484. "smtp-port=s" => \$cli_smtp_port,
  485. "smtp-timeout=s" => \$cli_smtp_timeout,
  486. "smtp-ssl-mode=s" => \$cli_smtp_ssl_mode,
  487. "smtp-user-name=s" => \$cli_smtp_user_name,
  488. "smtp-password=s" => \$cli_smtp_password,
  489. "smtp-debug" => \$cli_smtp_debug,
  490. "help" => sub { HelpMessage(0) },
  491. ) or HelpMessage(1);
  492. my %install_log_values = ();
  493. if ($koha_install_log ne "") {
  494. get_install_log_values($koha_install_log, \%install_log_values);
  495. } else {
  496. # Try to set install_log_values for provided values;
  497. get_cli_values(\%install_log_values);
  498. }
  499. my %config = get_configuration(\%config_defaults, \%valid_config_values, \%install_log_values);
  500. my ($target_directories, $skip_directories) = get_target_directories(\%config);
  501. display_configuration(\%config, $target_directories);
  502. my $file_map = {};
  503. get_file_map($target_map, $dirtree, $file_map);
  504. my $pl_files = {
  505. 'rewrite-config.PL' => [
  506. 'blib/KOHA_CONF_DIR/koha-conf.xml',
  507. 'blib/KOHA_CONF_DIR/koha-httpd.conf',
  508. 'blib/KOHA_CONF_DIR/log4perl.conf',
  509. 'blib/KOHA_CONF_DIR/koha-worker.service',
  510. 'blib/ZEBRA_CONF_DIR/etc/default.idx',
  511. 'blib/MISC_DIR/koha-install-log'
  512. ],
  513. 'fix-perl-path.PL' => [ # this script ensures the correct shebang line for the platform installed on...
  514. 'blib'
  515. ],
  516. };
  517. push @{ $pl_files->{'rewrite-config.PL'} }, (
  518. 'blib/ZEBRA_CONF_DIR/etc/passwd',
  519. 'blib/ZEBRA_CONF_DIR/zebra-biblios-dom.cfg',
  520. 'blib/ZEBRA_CONF_DIR/zebra-authorities-dom.cfg',
  521. 'blib/ZEBRA_CONF_DIR/explain-authorities.xml',
  522. 'blib/ZEBRA_CONF_DIR/explain-biblios.xml',
  523. 'blib/ZEBRA_CONF_DIR/retrieval-info-auth-dom.xml',
  524. 'blib/ZEBRA_CONF_DIR/retrieval-info-bib-dom.xml',
  525. );
  526. push @{ $pl_files->{'rewrite-config.PL'} }, (
  527. 'blib/SCRIPT_DIR/koha-zebra-ctl.sh',
  528. 'blib/SCRIPT_DIR/koha-index-daemon-ctl.sh',
  529. );
  530. $config{'ZEBRA_AUTH_CFG'} = 'zebra-authorities-dom.cfg';
  531. $config{'ZEBRA_BIB_CFG'} = 'zebra-biblios-dom.cfg';
  532. $config{'AUTH_RETRIEVAL_CFG'} = 'retrieval-info-auth-dom.xml';
  533. $config{'BIB_RETRIEVAL_CFG'} = 'retrieval-info-bib-dom.xml';
  534. if ($config{'INSTALL_MODE'} ne "dev") {
  535. push @{ $pl_files->{'rewrite-config.PL'} }, (
  536. 'blib/PERL_MODULE_DIR/C4/Context.pm',
  537. 'blib/SCRIPT_NONDEV_DIR/kohalib.pl'
  538. );
  539. }
  540. $config{ZEBRA_TOKENIZER_STMT} = $config{ZEBRA_TOKENIZER} eq 'icu'
  541. ? 'icuchain words-icu.xml'
  542. : 'charmap word-phrase-utf.chr';
  543. $config{ZEBRA_PTOKENIZER_STMT} = $config{ZEBRA_TOKENIZER} eq 'icu'
  544. ? 'icuchain phrases-icu.xml'
  545. : 'charmap word-phrase-utf.chr';
  546. my %test_suite_override_dirs = (
  547. KOHA_CONF_DIR => ['etc'],
  548. ZEBRA_CONF_DIR => ['etc', 'zebradb'],
  549. Z3950_CONF_DIR => ['etc', 'z3950'],
  550. LOCK_DIR => ['var', 'lock'],
  551. LOG_DIR => ['var', 'log'],
  552. BACKUP_DIR => ['var', 'spool'],
  553. SCRIPT_DIR => ['bin'],
  554. ZEBRA_LOCK_DIR => ['var', 'lock', 'zebradb'],
  555. ZEBRA_DATA_DIR => ['var', 'lib', 'zebradb'],
  556. ZEBRA_RUN_DIR => ['var', 'run', 'zebradb'],
  557. );
  558. WriteMakefile(
  559. NAME => 'koha',
  560. #VERSION => strftime('2.9.%Y%m%d%H',gmtime),
  561. VERSION_FROM => 'kohaversion.pl',
  562. ABSTRACT => 'Award-winning integrated library system (ILS) and Web OPAC',
  563. AUTHOR => 'Koha Contributors <https://koha-community.org/>',
  564. NO_META => 1,
  565. PREREQ_PM => $koha_pm->prereq_pm,
  566. # File tree mapping
  567. PM => $file_map,
  568. # Man pages generated from POD
  569. # ExtUtils::MakeMaker already manage $(DESTDIR)
  570. INSTALLMAN1DIR => File::Spec->catdir(_strip_destdir($target_directories->{'MAN_DIR'}), 'man1'),
  571. INSTALLMAN3DIR => File::Spec->catdir(_strip_destdir($target_directories->{'MAN_DIR'}), 'man3'),
  572. PL_FILES => $pl_files,
  573. );
  574. =head1 FUNCTIONS
  575. =head2 hashdir
  576. This function recurses through the directory structure and builds
  577. a hash of hashes containing the structure with arrays holding filenames.
  578. This directory hashing routine was taken from BrowserUK @ http://www.perlmonks.org/?node_id=219919
  579. =cut
  580. sub hashdir{
  581. my $dir = shift;
  582. opendir my $dh, $dir or die $!;
  583. my $tree = {}->{$dir} = {};
  584. while( my $file = readdir($dh) ) {
  585. next if $file =~ m/^\.{1,2}/ and $file !~ /^\.htaccess/; # .htaccess is a special case
  586. my $path = $dir .'/' . $file;
  587. $tree->{$file} = hashdir($path), next if -d $path;
  588. push @{$tree->{'.'}}, $file;
  589. }
  590. return $tree;
  591. }
  592. =head2 get_file_map
  593. This function combines the target_map and file hash to
  594. map each source file to its destination relative to
  595. the set of installation targets.
  596. Output will be a hash mapping from each source file
  597. to its destination value, like this:
  598. 'mainpage.pl' => '$(INTRANET_CGI_DIR)/mainpage.pl'
  599. =cut
  600. sub get_file_map {
  601. my $target_map = shift;
  602. my $dirtree = shift;
  603. my $file_map = shift;
  604. my $curr_path = @_ ? shift : ['.'];
  605. # Traverse the directory tree.
  606. # For each file or directory, identify the
  607. # most specific match in the target_map
  608. foreach my $dir (sort keys %{ $dirtree }) {
  609. if ($dir eq '.') {
  610. # deal with files in directory
  611. foreach my $file (sort @{ $dirtree->{$dir} }) {
  612. my $targetdir = undef;
  613. my $matchlevel = undef;
  614. # first, see if there is a match on this specific
  615. # file in the target map
  616. my $filepath = join("/", @$curr_path, $file);
  617. if (exists $target_map->{$filepath}) {
  618. $targetdir = $target_map->{$filepath};
  619. $matchlevel = scalar(@$curr_path) + 1;
  620. } else {
  621. # no match on the specific file; look for
  622. # a directory match
  623. for (my $i = scalar(@$curr_path) - 1; $i >= 0; $i--) {
  624. my $dirpath = join("/", @$curr_path[0..$i]);
  625. if (exists $target_map->{$dirpath}) {
  626. $targetdir = $target_map->{$dirpath};
  627. $matchlevel = $i + 1;
  628. last;
  629. }
  630. }
  631. }
  632. if (defined $targetdir) {
  633. _add_to_file_map($file_map, $targetdir, $curr_path, $file, $matchlevel);
  634. } else {
  635. my $path = join("/", @$curr_path);
  636. print "failed to map: $path/$file\n" if $DEBUG;
  637. }
  638. }
  639. } else {
  640. # dealing with subdirectory
  641. push @$curr_path, $dir;
  642. get_file_map($target_map, $dirtree->{$dir}, $file_map, $curr_path);
  643. pop @$curr_path;
  644. }
  645. }
  646. }
  647. sub _add_to_file_map {
  648. my $file_map = shift;
  649. my $targetdir = shift;
  650. my $curr_path = shift;
  651. my $file = shift;
  652. my $matchlevel = shift;
  653. my $dest_path = @_ ? shift : $curr_path;
  654. # The target can be one of the following:
  655. # 1. scalar representing target symbol
  656. # 2. hash ref containing target and trimdir keys
  657. #
  658. # Consequently, this routine traverses this structure,
  659. # calling itself recursively, until it deals with
  660. # all of the scalar target symbols.
  661. if (ref $targetdir eq 'HASH') {
  662. my $subtarget = $targetdir->{target};
  663. if (exists $targetdir->{trimdir}) {
  664. # if we get here, we've specified that
  665. # rather than installing the file to
  666. # $(TARGET)/matching/dirs/subdirs/file,
  667. # we want to install it to
  668. # $(TARGET)/subdirs/file
  669. #
  670. # Note that this the only place where
  671. # $matchlevel is used.
  672. my @new_dest_path = @$dest_path;
  673. if ($targetdir->{trimdir} == -1) {
  674. splice @new_dest_path, 0, $matchlevel;
  675. } else {
  676. splice @new_dest_path, 0, $targetdir->{trimdir};
  677. }
  678. _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, \@new_dest_path);
  679. } else {
  680. # actually getting here means that the
  681. # target was unnecessarily listed
  682. # as a hash, but we'll forgive that
  683. _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel);
  684. }
  685. } elsif ($targetdir ne 'NONE' and $targetdir ne '') {
  686. my $source = File::Spec->catfile(@$curr_path, $file);
  687. my $destination = File::Spec->catfile('blib', $targetdir, @$dest_path, $file);
  688. #print "$source => $destination\n"; # DEBUG
  689. # quote spaces in file names
  690. # FIXME: this is of questionable portability and
  691. # probably depends on user's make recognizing this
  692. # quoting syntax -- probably better to remove
  693. # spaces and shell metacharacters from all file names
  694. $source =~ s/ /\\ /g;
  695. $destination =~ s/ /\\ /g;
  696. $file_map->{$source} = $destination;
  697. }
  698. }
  699. =head2 get_cli_values
  700. Reads values provided on cli for configuration values
  701. =cut
  702. sub get_cli_values {
  703. my $values = shift;
  704. my $map = {
  705. INSTALL_MODE => $cli_koha_install_mode,
  706. DB_TYPE => $cli_koha_db_type,
  707. DB_HOST => $cli_koha_db_host,
  708. DB_PORT => $cli_koha_db_port,
  709. DB_NAME => $cli_koha_db_name,
  710. DB_USER => $cli_koha_db_user,
  711. DB_PASS => $cli_koha_db_pass,
  712. ZEBRA_MARC_FORMAT => $cli_zebra_marc_format,
  713. ZEBRA_LANGUAGE => $cli_zebra_language,
  714. ZEBRA_TOKENIZER => $cli_zebra_tokenizer,
  715. ZEBRA_USER => $cli_zebra_user,
  716. ZEBRA_PASS => $cli_zebra_pass,
  717. ZEBRA_SRU_HOST => $cli_zebra_sru_host,
  718. ZEBRA_SRU_BIBLIOS_PORT => $cli_zebra_sru_bib_port,
  719. ZEBRA_SRU_AUTHORITIES_PORT => $cli_zebra_sru_auth_port,
  720. KOHA_USER => $cli_koha_user,
  721. KOHA_GROUP => $cli_koha_group,
  722. INSTALL_SRU => $cli_koha_install_sru,
  723. USE_MEMCACHED => $cli_koha_use_memcached,
  724. FONT_DIR => $cli_koha_font_dir,
  725. RUN_DATABASE_TESTS => $cli_koha_run_database_tests,
  726. INSTALL_BASE => $cli_koha_install_base,
  727. TEMPLATE_CACHE_DIR => $cli_koha_template_cache_dir,
  728. SMTP_HOST => $cli_smtp_host,
  729. SMTP_PORT => $cli_smtp_port,
  730. SMTP_TIMEOUT => $cli_smtp_timeout,
  731. SMTP_SSL_MODE => $cli_smtp_ssl_mode,
  732. SMTP_USER_NAME => $cli_smtp_user_name,
  733. SMTP_PASSWORD => $cli_smtp_password,
  734. SMTP_DEBUG => (defined $cli_smtp_debug) ? ( $cli_smtp_debug ? 'yes' : 'no' ) : $values->{SMTP_DEBUG},
  735. };
  736. foreach my $key (keys %{$map}) {
  737. $values->{$key} = $map->{$key} if ($map->{$key});
  738. }
  739. }
  740. =head2 get_install_log_values
  741. Reads value from the Koha install log specified by
  742. --prev-install-log
  743. =cut
  744. sub get_install_log_values {
  745. my $install_log = shift;
  746. my $values = shift;
  747. open my $log, '<', $install_log or die "Cannot open install log $install_log: $!\n";
  748. while (<$log>) {
  749. chomp;
  750. next if /^#/ or /^\s*$/;
  751. next if /^=/;
  752. next unless m/=/;
  753. s/\s+$//g;
  754. my ($key, $value) = split /=/, $_, 2;
  755. $values->{$key} = $value;
  756. }
  757. close $log;
  758. print <<_EXPLAIN_INSTALL_LOG_;
  759. Reading values from install log $install_log. You
  760. will be prompted only for settings that have been
  761. added since the last time you installed Koha. To
  762. be prompted for all settings, run 'perl Makefile.PL'
  763. without the --prev-install-log option.
  764. _EXPLAIN_INSTALL_LOG_
  765. }
  766. =head2 get_configuration
  767. This prompts the user for various configuration options.
  768. =cut
  769. sub get_configuration {
  770. my $defaults = shift;
  771. my $valid_values = shift;
  772. my $install_log_values = shift;
  773. my %config = ();
  774. my $msg = q(
  775. By default, Koha can be installed in one of three ways:
  776. standard: Install files in conformance with the Filesystem
  777. Hierarchy Standard (FHS). This is the default mode
  778. and should be used when installing a production
  779. Koha system. On Unix systems, root access is
  780. needed to complete a standard installation.
  781. single: Install files under a single directory. This option
  782. is useful for installing Koha without root access, e.g.,
  783. on a web host that allows CGI scripts and MySQL databases
  784. but requires the user to keep all files under the user's
  785. HOME directory.
  786. dev: Create a set of symbolic links and configuration files to
  787. allow Koha to run directly from the source distribution.
  788. This mode is useful for developers who want to run
  789. Koha from a git clone.
  790. Installation mode);
  791. $msg .= _add_valid_values_disp('INSTALL_MODE', $valid_values);
  792. $config{'INSTALL_MODE'} = _get_value('INSTALL_MODE', $msg, $defaults->{'INSTALL_MODE'}, $valid_values, $install_log_values);
  793. # set message and default value for INSTALL_BASE
  794. # depending on value of INSTALL_MODE
  795. my $install_base_default = $defaults->{'INSTALL_BASE'};
  796. if ($config{'INSTALL_MODE'} eq 'dev') {
  797. $msg = q(
  798. Please specify the directory in which to install Koha's
  799. active configuration files and (if applicable) the
  800. Zebra database. Koha's CGI scripts and templates will
  801. be run from the current directory.
  802. Configuration directory:);
  803. # FIXME - home directory portability consideration apply
  804. $install_base_default =
  805. $ENV{DESTDIR}
  806. || ( exists $ENV{HOME} ? "$ENV{HOME}/koha-dev" : "$defaults->{'INSTALL_BASE'}-dev" )
  807. ;
  808. } elsif ($config{'INSTALL_MODE'} eq 'single') {
  809. $msg = "\nPlease specify the directory in which to install Koha";
  810. # FIXME -- we're assuming under a 'single' mode install
  811. # that user will likely want to install under the home
  812. # directory. This is OK in and of itself, but we should
  813. # use File::HomeDir to locate the home directory portably.
  814. # This is deferred for now because File::HomeDir is not yet
  815. # core.
  816. # --we must also keep this portable to the major OS's -fbcit
  817. $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha" : $defaults->{'INSTALL_BASE'};
  818. } else {
  819. # must be standard
  820. $msg = q(
  821. Please specify the directory under which most Koha files
  822. will be installed.
  823. Note that if you are planning in installing more than
  824. one instance of Koha, you may want to modify the last
  825. component of the directory path, which will be used
  826. as the package name in the FHS layout.
  827. Base installation directory);
  828. }
  829. $config{'INSTALL_BASE'} = _get_value('INSTALL_BASE', $msg, $install_base_default, $valid_values, $install_log_values);
  830. $config{'INSTALL_BASE'} = File::Spec->rel2abs($config{'INSTALL_BASE'});
  831. print "INSTALL_BASE=$config{'INSTALL_BASE'}\r\n" if $DEBUG;
  832. if ($config{'INSTALL_MODE'} eq "standard") {
  833. $msg = q(
  834. Since you are using the 'standard' install
  835. mode, you should run 'make install' as root.
  836. However, it is recommended that a non-root
  837. user (on Unix and Linux platforms) have
  838. ownership of Koha's files, including the
  839. Zebra indexes if applicable.
  840. Please specify a user account. This
  841. user account does not need to exist
  842. right now, but it needs to exist
  843. before you run 'make install'. Please
  844. note that for security reasons, this
  845. user should not be the same as the user
  846. account Apache runs under.
  847. User account);
  848. $config{'KOHA_USER'} = _get_value('KOHA_USER', $msg, $defaults->{'KOHA_USER'}, $valid_values, $install_log_values);
  849. $msg = q(
  850. Please specify the group that should own
  851. Koha's files. As above, this group need
  852. not exist right now, but should be created
  853. before you run 'make install'.
  854. Group);
  855. $config{'KOHA_GROUP'} = _get_value('KOHA_GROUP', $msg, $defaults->{'KOHA_GROUP'}, $valid_values, $install_log_values);
  856. }
  857. $msg = q(
  858. Please specify which database engine you will use
  859. to store data in Koha. The choices are MySQL and
  860. PostgreSQL; please note that at the moment
  861. PostgreSQL support is highly experimental.
  862. DBMS to use);
  863. $msg .= _add_valid_values_disp('DB_TYPE', $valid_values);
  864. $config{'DB_TYPE'} = _get_value('DB_TYPE', $msg, $defaults->{'DB_TYPE'}, $valid_values, $install_log_values);
  865. $msg = q(
  866. Please specify the name or address of your
  867. database server. Note that the database
  868. does not have to exist at this point, it
  869. can be created after running 'make install'
  870. and before you try using Koha for the first time.
  871. Database server);
  872. $config{'DB_HOST'} = _get_value('DB_HOST', $msg, $defaults->{'DB_HOST'}, $valid_values, $install_log_values);
  873. $msg = q(
  874. Please specify the port used to connect to the
  875. DMBS);
  876. my $db_port_default = $config{'DB_TYPE'} eq 'mysql' ? '3306' : '5432';
  877. $config{'DB_PORT'} = _get_value('DB_PORT', $msg, $db_port_default, $valid_values, $install_log_values);
  878. $msg = q(
  879. Please specify the name of the database to be
  880. used by Koha);
  881. $config{'DB_NAME'} = _get_value('DB_NAME', $msg, $defaults->{'DB_NAME'}, $valid_values, $install_log_values);
  882. if ($config{'DB_TYPE'} eq 'mysql'){
  883. $msg = q(
  884. Please specify whether the connection to MySQL will use TLS
  885. );
  886. $config{'DB_USE_TLS'} = _get_value('DB_USE_TLS', $msg, $defaults->{'DB_USE_TLS'}, $valid_values, $install_log_values);
  887. }
  888. if ($config{'DB_USE_TLS'} eq 'yes'){
  889. $msg = q(
  890. Please enter the path to the CA certificate for TLS
  891. );
  892. $config{'DB_TLS_CA_CERTIFICATE'} = _get_value('DB_TLS_CA_CERTIFICATE', $msg, $defaults->{'DB_TLS_CA_CERTIFICATE'}, $valid_values, $install_log_values);
  893. $msg = q(
  894. Please enter the path to the client certificate for TLS
  895. );
  896. $config{'DB_TLS_CLIENT_CERTIFICATE'} = _get_value('DB_TLS_CLIENT_CERTIFICATE', $msg, $defaults->{'DB_TLS_CLIENT_CERTIFICATE'}, $valid_values, $install_log_values);
  897. $msg = q(
  898. Please enter the path to the client key for TLS
  899. );
  900. $config{'DB_TLS_CLIENT_KEY'} = _get_value('DB_TLS_CLIENT_KEY', $msg, $defaults->{'DB_TLS_CLIENT_KEY'}, $valid_values, $install_log_values);
  901. }
  902. $msg = q(
  903. Please specify the user that owns the database to be
  904. used by Koha);
  905. $config{'DB_USER'} = _get_value('DB_USER', $msg, $defaults->{'DB_USER'}, $valid_values, $install_log_values);
  906. $msg = q(
  907. Please specify the password of the user that owns the
  908. database to be used by Koha);
  909. $config{'DB_PASS'} = _get_value('DB_PASS', $msg, $defaults->{'DB_PASS'}, $valid_values, $install_log_values);
  910. print q(
  911. Koha uses the Zebra search engine for high-performance
  912. searching of bibliographic and authority records. Checking
  913. to see if you have installed the Zebra software...
  914. );
  915. if (defined(my $zebra_path = find_zebra())) {
  916. $config{'PATH_TO_ZEBRA'} = $zebra_path;
  917. print qq(
  918. Found 'zebrasrv' and 'zebraidx' in $zebra_path.
  919. );
  920. } else {
  921. print q(
  922. Unable to find the Zebra programs 'zebrasrv' and 'zebraidx'
  923. in your PATH or in some of the usual places. If you haven't
  924. installed Zebra yet, please do so and run Makefile.PL again.
  925. );
  926. }
  927. $msg = q(
  928. You must specify the primary MARC format of the
  929. records to be indexed by Zebra.
  930. Koha provides Zebra configuration files for MARC21,
  931. NORMARC and UNIMARC.
  932. MARC format for Zebra indexing);
  933. $msg .= _add_valid_values_disp('ZEBRA_MARC_FORMAT', $valid_values);
  934. $config{'ZEBRA_MARC_FORMAT'} = _get_value('ZEBRA_MARC_FORMAT', $msg, $defaults->{'ZEBRA_MARC_FORMAT'}, $valid_values, $install_log_values);
  935. $msg = q(
  936. Koha supplies Zebra configuration files tuned for
  937. searching either English (en) or French (fr) MARC
  938. records.
  939. Primary language for Zebra indexing);
  940. $msg .= _add_valid_values_disp('ZEBRA_LANGUAGE', $valid_values);
  941. $config{'ZEBRA_LANGUAGE'} = _get_value('ZEBRA_LANGUAGE', $msg, $defaults->{'ZEBRA_LANGUAGE'}, $valid_values, $install_log_values);
  942. $msg = q(
  943. Zebra has two methods to perform records tokenization
  944. and characters normalization: CHR and ICU. ICU is
  945. recommended for catalogs containing non-Latin
  946. characters.);
  947. $msg .= _add_valid_values_disp('ZEBRA_TOKENIZER', $valid_values);
  948. $config{'ZEBRA_TOKENIZER'} = _get_value('ZEBRA_TOKENIZER', $msg, $defaults->{'ZEBRA_TOKENIZER'}, $valid_values, $install_log_values);
  949. $msg = q(
  950. Please specify Zebra database user);
  951. $config{'ZEBRA_USER'} = _get_value('ZEBRA_USER', $msg, $defaults->{'ZEBRA_USER'}, $valid_values, $install_log_values);
  952. $msg = q(
  953. Please specify the Zebra database password);
  954. $config{'ZEBRA_PASS'} = _get_value('ZEBRA_PASS', $msg, $defaults->{'ZEBRA_PASS'}, $valid_values, $install_log_values);
  955. $msg = q(
  956. Since you've chosen to use Zebra, you can enable the SRU/
  957. Z39.50 Server if you so choose, but you must specify a
  958. few configuration options for it.
  959. Please note that if you choose *NOT* to configure SRU,
  960. koha-conf.xml will still contain some references to SRU
  961. settings. Those references will be ignored by Koha.
  962. Install the SRU configuration files?);
  963. $msg .= _add_valid_values_disp('INSTALL_SRU', $valid_values);
  964. $config{'INSTALL_SRU'} = _get_value('INSTALL_SRU', $msg, $defaults->{'INSTALL_SRU'}, $valid_values, $install_log_values);
  965. if ($config{'INSTALL_SRU'} eq 'yes') {
  966. $msg = q(
  967. Since you've chosen to configure SRU, you must
  968. specify the host and port(s) that the SRU
  969. Servers (bibliographic and authority) should run on.
  970. );
  971. $msg = q(
  972. SRU Database host?);
  973. $config{'ZEBRA_SRU_HOST'} = _get_value('ZEBRA_SRU_HOST', $msg, $defaults->{'ZEBRA_SRU_HOST'}, $valid_values, $install_log_values);
  974. $msg = q(
  975. SRU port for bibliographic data?);
  976. $config{'ZEBRA_SRU_BIBLIOS_PORT'} = _get_value('ZEBRA_SRU_BIBLIOS_PORT', $msg, $defaults->{'ZEBRA_SRU_BIBLIOS_PORT'}, $valid_values, $install_log_values);
  977. $msg = q(
  978. SRU port for authority data?);
  979. $config{'ZEBRA_SRU_AUTHORITIES_PORT'} = _get_value('ZEBRA_SRU_AUTHORITIES_PORT', $msg, $defaults->{'ZEBRA_SRU_AUTHORITIES_PORT'}, $valid_values, $install_log_values);
  980. }
  981. $msg = q(
  982. Use memcached to cache the results of some function calls?
  983. This provides a significant performance improvement.
  984. You will need a Memcached server running.);
  985. $msg .= _add_valid_values_disp('USE_MEMCACHED', $valid_values);
  986. $config{'USE_MEMCACHED'} = _get_value('USE_MEMCACHED', $msg, $defaults->{'USE_MEMCACHED'}, $valid_values, $install_log_values);
  987. if ($config{'USE_MEMCACHED'} eq 'yes'){
  988. $msg = q(
  989. Since you've chosen to use caching, you must specify the memcached servers and the namespace to use:
  990. );
  991. $msg = q(
  992. Memcached server address?);
  993. $config{'MEMCACHED_SERVERS'} = _get_value('MEMCACHED_SERVERS', $msg, $defaults->{'MEMCACHED_SERVERS'}, $valid_values, $install_log_values);
  994. $msg = q(
  995. Memcached namespace?);
  996. $config{'MEMCACHED_NAMESPACE'} = _get_value('MEMCACHED_NAMESPACE', $msg, $defaults->{'MEMCACHED_NAMESPACE'}, $valid_values, $install_log_values);
  997. }
  998. $msg = q(
  999. Use Elasticsearch to serve search results?
  1000. You will need a Elasticsearch server running.);
  1001. $msg .= _add_valid_values_disp('USE_ELASTICSEARCH', $valid_values);
  1002. $config{'USE_ELASTICSEARCH'} = _get_value('USE_ELASTICSEARCH', $msg, $defaults->{'USE_ELASTICSEARCH'}, $valid_values, $install_log_values);
  1003. if ($config{'USE_ELASTICSEARCH'} eq 'yes'){
  1004. $msg = q(
  1005. Define the ELASTICSEARCH_SERVERS with a comma-separated list. Eg
  1006. localhost:9200, 192.168.0.100:9200
  1007. );
  1008. $msg = q(
  1009. Elasticsearch server addresses?);
  1010. $config{'ELASTICSEARCH_SERVERS'} = _get_value('ELASTICSEARCH_SERVERS', $msg, $defaults->{'ELASTICSEARCH_SERVERS'}, $valid_values, $install_log_values);
  1011. $msg = q(
  1012. What index name to use for this Koha-instance? It must be unique for each Koha
  1013. sharing the same Elasticsearch-cluster
  1014. Elasticsearch index?);
  1015. $config{'ELASTICSEARCH_INDEX'} = _get_value('ELASTICSEARCH_INDEX', $msg, $defaults->{'ELASTICSEARCH_INDEX'}, $valid_values, $install_log_values);
  1016. }
  1017. $msg = q(
  1018. Template cache directory?);
  1019. $config{'TEMPLATE_CACHE_DIR'} = _get_value('TEMPLATE_CACHE_DIR', $msg, $defaults->{'TEMPLATE_CACHE_DIR'}, $valid_values, $install_log_values);
  1020. $msg = q(
  1021. Path to DejaVu fonts?);
  1022. $config{'FONT_DIR'} = _get_value('FONT_DIR', $msg, $defaults->{'FONT_DIR'}, $valid_values, $install_log_values);
  1023. $msg = q(
  1024. SMTP settings
  1025. You will be able to set your default SMTP configuration.);
  1026. $msg .= q{
  1027. SMTP host name?};
  1028. $config{'SMTP_HOST'} = _get_value('SMTP_HOST', $msg, $defaults->{'SMTP_HOST'}, $valid_values, $install_log_values);
  1029. $msg = q{
  1030. SMTP port?};
  1031. $config{'SMTP_PORT'} = _get_value('SMTP_PORT', $msg, $defaults->{'SMTP_PORT'}, $valid_values, $install_log_values);
  1032. $msg = q{
  1033. SMTP timeout (in seconds)?};
  1034. $config{'SMTP_TIMEOUT'} = _get_value('SMTP_TIMEOUT', $msg, $defaults->{'SMTP_TIMEOUT'}, $valid_values, $install_log_values);
  1035. $msg = q{
  1036. SMTP SSL mode?};
  1037. $msg .= _add_valid_values_disp('SMTP_SSL_MODE', $valid_values);
  1038. $config{'SMTP_SSL_MODE'} = _get_value('SMTP_SSL_MODE', $msg, $defaults->{'SMTP_SSL_MODE'}, $valid_values, $install_log_values);
  1039. $msg = q{
  1040. SMTP user name?};
  1041. $config{'SMTP_USER_NAME'} = _get_value('SMTP_USER_NAME', $msg, $defaults->{'SMTP_USER_NAME'}, $valid_values, $install_log_values);
  1042. $msg = q{
  1043. SMTP password?};
  1044. $config{'SMTP_PASSWORD'} = _get_value('SMTP_PASSWORD', $msg, $defaults->{'SMTP_PASSWORD'}, $valid_values, $install_log_values);
  1045. $msg = q{
  1046. SMTP debug mode?};
  1047. $msg .= _add_valid_values_disp('SMTP_DEBUG', $valid_values);
  1048. $config{'SMTP_DEBUG'} = _get_value('SMTP_DEBUG', $msg, $defaults->{'SMTP_DEBUG'}, $valid_values, $install_log_values);
  1049. $config{'SMTP_DEBUG'} = ( $config{'SMTP_DEBUG'} eq 'yes' ) ? 1 : 0;
  1050. $msg = q(
  1051. Would you like to run the database-dependent test suite?);
  1052. $msg .= _add_valid_values_disp( 'RUN_DATABASE_TESTS', $valid_values );
  1053. $config{'RUN_DATABASE_TESTS'} = _get_value( 'RUN_DATABASE_TESTS', $msg, $defaults->{'RUN_DATABASE_TESTS'}, $valid_values, $install_log_values );
  1054. if ( $config{'RUN_DATABASE_TESTS'} eq 'yes' ) {
  1055. $config{'TEST_DB_TYPE'} = $config{'DB_TYPE'};
  1056. $config{'TEST_DB_HOST'} = $config{'DB_HOST'};
  1057. $msg = q(TEST DATABASE
  1058. THE DATA IN THIS DATABASE WILL BE DESTROYED during the process of
  1059. testing. Please don't do this on your production database. It is not
  1060. reversible.
  1061. YOU WILL SUFFER DATA LOSS if you run this test suite on your test
  1062. database. You are better off not running this optional test suite than
  1063. doing it in a database that you don't want to lose.
  1064. Please specify the name of the test database to be
  1065. used by Koha);
  1066. $config{'TEST_DB_NAME'} = _get_value('TEST_DB_NAME', $msg, $defaults->{'TEST_DB_NAME'}, $valid_values, $install_log_values);
  1067. while ( $config{'TEST_DB_NAME'} eq $config{'DB_NAME'} ) {
  1068. $msg = q(Please do not use the same database for testing as you do for production. You run the severe risk of data loss.);
  1069. $config{'TEST_DB_NAME'} = _get_value('TEST_DB_NAME', $msg, $defaults->{'TEST_DB_NAME'}, $valid_values, $install_log_values);
  1070. }
  1071. $msg = q(
  1072. Please specify the user that owns the database to be
  1073. used by Koha);
  1074. $config{'TEST_DB_USER'} = _get_value('TEST_DB_USER', $msg, $defaults->{'TEST_DB_USER'}, $valid_values, $install_log_values);
  1075. $msg = q(
  1076. Please specify the password of the user that owns the
  1077. database to be used by Koha);
  1078. $config{'TEST_DB_PASS'} = _get_value('TEST_DB_PASS', $msg, $defaults->{'TEST_DB_PASS'}, $valid_values, $install_log_values);
  1079. }
  1080. print "\n\n";
  1081. # add version number
  1082. my $version = "no_version_found";
  1083. eval {
  1084. require 'kohaversion.pl';
  1085. $version = kohaversion();
  1086. };
  1087. $config{'KOHA_INSTALLED_VERSION'} = $version;
  1088. return %config;
  1089. }
  1090. sub _add_valid_values_disp {
  1091. my $key = shift;
  1092. my $valid_values = shift;
  1093. my $disp = "";
  1094. if (exists $valid_values->{$key}) {
  1095. $disp = " (" . join(", ", sort keys %{ $valid_values->{$key} }) . ")";
  1096. }
  1097. return $disp;
  1098. }
  1099. sub _get_value {
  1100. my $key = shift;
  1101. my $msg = shift;
  1102. my $default = shift;
  1103. my $valid_values = shift;
  1104. my $install_log_values = shift;
  1105. # take value from install log if present
  1106. if (exists $install_log_values{$key}) {
  1107. $install_log_values{$key} =~ s/\$/\$\$/g;
  1108. return $install_log_values{$key};
  1109. }
  1110. # override default value from environment
  1111. if (exists $ENV{$key}) {
  1112. $default = $ENV{$key};
  1113. $msg .= " (default from environment)";
  1114. }
  1115. my $val = prompt($msg, $default);
  1116. while (exists $valid_values->{$key} and
  1117. $val ne $default and
  1118. not exists $valid_values->{$key}->{$val}) {
  1119. my $retry_msg = "Value '$val' is not a valid option.\n";
  1120. $retry_msg .= "Please enter a value";
  1121. $retry_msg .= _add_valid_values_disp($key, $valid_values);
  1122. $val = prompt($retry_msg, $default);
  1123. }
  1124. $val =~ s/\$/\$\$/g;
  1125. return $val;
  1126. }
  1127. =head2 get_target_directories
  1128. Creates a hash mapping from symbols for installation target
  1129. directories to actual directory paths.
  1130. Also returns a hash indicating targets for which
  1131. files need not be copied -- this is used for the 'dev'
  1132. mode installation, where some files are installed in place.
  1133. =cut
  1134. sub get_target_directories {
  1135. my $config = shift;
  1136. my $base = $config->{'INSTALL_BASE'};
  1137. my $mode = $config->{'INSTALL_MODE'};
  1138. # get last component of install base directory
  1139. # to treat as package name
  1140. my ($volume, $directories, $file) = File::Spec->splitpath($base, 1);
  1141. my @basedir = File::Spec->splitdir($directories);
  1142. if ( $^O eq 'cygwin' ) { shift @basedir; unshift @basedir, 'c:'; } # in a cygwin environment, $volume is returned empty
  1143. my $package = pop @basedir;
  1144. my %dirmap = ();
  1145. my %skipdirs = ();
  1146. if ($mode eq 'single') {
  1147. $dirmap{'API_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'api');
  1148. $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
  1149. $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
  1150. $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
  1151. $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
  1152. $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
  1153. $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
  1154. $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
  1155. $dirmap{'PERL_MODULE_LIB_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
  1156. $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
  1157. $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
  1158. $dirmap{'Z3950_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'z3950');
  1159. $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
  1160. $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
  1161. $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
  1162. $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
  1163. $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
  1164. $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
  1165. $dirmap{'LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock');
  1166. $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
  1167. $dirmap{'BACKUP_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'spool');
  1168. $dirmap{'PLUGINS_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'koha', 'plugins');
  1169. $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
  1170. $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
  1171. } elsif ($mode eq 'dev') {
  1172. my $curdir = File::Spec->rel2abs(File::Spec->curdir());
  1173. $dirmap{'API_CGI_DIR'} = File::Spec->catdir($curdir, 'api');
  1174. $skipdirs{'API_CGI_DIR'} = 1;
  1175. $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir($curdir);
  1176. $skipdirs{'INTRANET_CGI_DIR'} = 1;
  1177. $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'intranet-tmpl');
  1178. $skipdirs{'INTRANET_TMPL_DIR'} = 1;
  1179. $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
  1180. $skipdirs{'INTRANET_WWW_DIR'} = 1;
  1181. $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir($curdir);
  1182. $skipdirs{'OPAC_CGI_DIR'} = 1;
  1183. $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'opac-tmpl');
  1184. $skipdirs{'OPAC_TMPL_DIR'} = 1;
  1185. $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
  1186. $skipdirs{'OPAC_WWW_DIR'} = 1;
  1187. #NOTE: We're hacking the dirmap here, so that PERL_MODULE_DIR tokens get rewritten correctly for git installs
  1188. $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir($curdir);
  1189. $skipdirs{'PERL_MODULE_DIR'} = 1;
  1190. $dirmap{'PERL_MODULE_LIB_DIR'} = File::Spec->catdir($curdir,'lib');
  1191. $skipdirs{'PERL_MODULE_LIB_DIR'} = 1;
  1192. $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
  1193. $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
  1194. $dirmap{'Z3950_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'z3950');
  1195. $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
  1196. $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
  1197. #For dev install, point NONDEV_DIR to misc in current dir (not base)
  1198. #Used by supportdir in koha-conf.xml (BZ 12031)
  1199. $dirmap{'SCRIPT_NONDEV_DIR'} = File::Spec->catdir($curdir, 'misc');
  1200. $skipdirs{'SCRIPT_NONDEV_DIR'} = 1;
  1201. $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
  1202. $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
  1203. $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
  1204. $dirmap{'LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock');
  1205. $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
  1206. $dirmap{'BACKUP_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'spool');
  1207. $dirmap{'PLUGINS_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'plugins');
  1208. $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
  1209. $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
  1210. } else {
  1211. # mode is standard, i.e., 'fhs'
  1212. $dirmap{'API_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'api');
  1213. $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
  1214. $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
  1215. $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
  1216. $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
  1217. $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
  1218. $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
  1219. $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
  1220. $dirmap{'PERL_MODULE_LIB_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
  1221. $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package);
  1222. $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'zebradb');
  1223. $dirmap{'Z3950_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'z3950');
  1224. $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
  1225. $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
  1226. $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
  1227. $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
  1228. $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
  1229. $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
  1230. $dirmap{'LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package);
  1231. $dirmap{'LOG_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
  1232. $dirmap{'BACKUP_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'spool', $package);
  1233. $dirmap{'PLUGINS_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'plugins');
  1234. $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
  1235. $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb');
  1236. }
  1237. _get_env_overrides(\%dirmap);
  1238. _get_argv_overrides(\%dirmap);
  1239. _add_destdir(\%dirmap);
  1240. return \%dirmap, \%skipdirs;
  1241. }
  1242. =head2 get_test_dir
  1243. Map a directory target to the corresponding path for
  1244. the test suite.
  1245. =cut
  1246. sub get_test_dir {
  1247. my ($dirname) = @_;
  1248. my @basedir = (File::Spec->rel2abs(File::Spec->curdir()), 't', 'run');
  1249. if (exists $test_suite_override_dirs{$dirname}) {
  1250. return File::Spec->catdir(@basedir, @{ $test_suite_override_dirs{$dirname} });
  1251. } else {
  1252. return;
  1253. }
  1254. }
  1255. sub _get_env_overrides {
  1256. my $dirmap = shift;
  1257. foreach my $key (keys %$dirmap) {
  1258. if (exists $ENV{$key}) {
  1259. $dirmap->{$key} = $ENV{$key};
  1260. print "Setting $key from environment\n";
  1261. }
  1262. }
  1263. }
  1264. sub _get_argv_overrides {
  1265. my $dirmap = shift;
  1266. my @new_argv = ();
  1267. for (my $i = 0; $i <= $#ARGV; $i++) {
  1268. if ($ARGV[$i] =~ /^([^=]+)=([^=]+)$/ and exists $dirmap->{$1}) {
  1269. $dirmap->{$1} = $2;
  1270. } else {
  1271. push @new_argv, $ARGV[$i];
  1272. }
  1273. }
  1274. @ARGV = @new_argv;
  1275. }
  1276. sub _strip_destdir {
  1277. my $dir = shift;
  1278. $dir =~ s/^\$\(DESTDIR\)//;
  1279. return $dir;
  1280. }
  1281. sub _add_destdir {
  1282. my $dirmap = shift;
  1283. foreach my $key (keys %$dirmap) {
  1284. $dirmap->{$key} = '$(DESTDIR)'.$dirmap->{$key};
  1285. }
  1286. }
  1287. sub display_configuration {
  1288. my $config = shift;
  1289. my $dirmap = shift;
  1290. my @version = grep /\/usr\/share\/perl\//, @INC;
  1291. push @version, ('/usr/share/perl/5.10') if !$version[0];
  1292. print "\n\nKoha will be installed with the following configuration parameters:\n\n";
  1293. foreach my $key (sort keys %$config) {
  1294. print sprintf("%-25.25s%s\n", $key, $config->{$key});
  1295. }
  1296. print "\nand in the following directories:\n\n";
  1297. foreach my $key (sort keys %$dirmap) {
  1298. print sprintf("%-25.25s%s\n", $key, $dirmap->{$key});
  1299. }
  1300. print "\n\nTo change any configuration setting, please run\n";
  1301. print "perl Makefile.PL again. To override one of the target\n";
  1302. print "directories, you can do so on the command line like this:\n";
  1303. print "\nperl Makefile.PL PERL_MODULE_DIR=$version[0]\n\n";
  1304. print "You can also set different default values for parameters\n";
  1305. print "or override directory locations by using environment variables.\n";
  1306. print "\nFor example:\n\n";
  1307. print "export DB_USER=my_koha\n";
  1308. print "perl Makefile.PL\n";
  1309. print "\nor\n\n";
  1310. print "DB_USER=my_koha DOC_DIR=/usr/local/info perl Makefile.PL\n\n";
  1311. }
  1312. =head2 find_zebra
  1313. Attempt to find Zebra - check user's PATH and
  1314. a few other directories for zebrasrv and zebraidx.
  1315. =cut
  1316. sub find_zebra {
  1317. my @search_dirs = map {
  1318. my $abs = File::Spec->rel2abs($_);
  1319. my ($toss, $directories);
  1320. ($toss, $directories, $toss) = File::Spec->splitpath($abs, 1);
  1321. $directories;
  1322. } split /:/, $ENV{PATH};
  1323. push @search_dirs, qw(/usr/local/bin /opt/local/bin /usr/bin);
  1324. my @zebrasrv_dirs = grep { -x File::Spec->catpath('', $_, 'zebrasrv') } @search_dirs;
  1325. return unless @zebrasrv_dirs;
  1326. # verify that directory that contains zebrasrv also contains zebraidx
  1327. foreach my $dir (@zebrasrv_dirs) {
  1328. return $dir if -x File::Spec->catpath('', $dir, 'zebraidx');
  1329. }
  1330. return;
  1331. }
  1332. package MY;
  1333. sub test {
  1334. my $self = shift;
  1335. my $test = $self->SUPER::test(@_);
  1336. $test =~ s!\$\(INST_LIB\)!blib/PERL_MODULE_DIR!g;
  1337. # set KOHA_CONF
  1338. $test =~ s!\$\(FULLPERLRUN\)!KOHA_CONF=blib/KOHA_CONF_DIR/koha-conf.xml \$(FULLPERLRUN)!g;
  1339. return $test;
  1340. }
  1341. sub install {
  1342. my $self = shift;
  1343. my $install = "";
  1344. # NOTE: we're *not* doing this: my $install = $self->SUPER::install(@_);
  1345. # This means that we're completely overriding EU::MM's default
  1346. # installation and uninstallation targets.
  1347. my $perl5lib_dirs = _build_perl5lib_string({ target_dirs => $target_directories });
  1348. # If installation is on Win32, we need to do permissions different from *nix
  1349. if ( $^O =~ /darwin|linux|cygwin|freebsd|solaris/ ) { # this value needs to be verified for each platform and modified accordingly
  1350. foreach my $key (sort keys %$target_directories) {
  1351. $install .= qq(
  1352. KOHA_INST_$key = blib/$key
  1353. KOHA_DEST_$key = $target_directories->{$key}
  1354. ) unless exists $skip_directories->{$key};
  1355. }
  1356. $install .= qq(
  1357. install :: all install_koha set_koha_ownership set_koha_permissions warn_koha_env_vars
  1358. \t\$(NOECHO) \$(NOOP)
  1359. );
  1360. $install .= "install_koha ::\n";
  1361. $install .= "\t\$(NOECHO) umask 022; \$(MOD_INSTALL) \\\n";
  1362. foreach my $key (sort keys %$target_directories) {
  1363. $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
  1364. unless exists $skip_directories->{$key};
  1365. }
  1366. $install .= "\t\t\$(INST_MAN1DIR) \$(DESTINSTALLMAN1DIR) \\\n";
  1367. $install .= "\t\t\$(INST_MAN3DIR) \$(DESTINSTALLMAN3DIR)\n";
  1368. $install .= "\n";
  1369. $install .= "set_koha_ownership ::\n";
  1370. # Do not try to change ownership if DESTDIR is set
  1371. if ($config{'INSTALL_MODE'} eq 'standard' and $config{'KOHA_USER'} ne "root") {
  1372. foreach my $key (sort keys %$target_directories) {
  1373. $install .= "\t\$(NOECHO) if test -z \"\$(DESTDIR)\"; then chown -R $config{'KOHA_USER'}:$config{'KOHA_GROUP'} \$(KOHA_DEST_$key); fi\n"
  1374. unless exists $skip_directories->{$key};
  1375. }
  1376. } else {
  1377. $install .= "\t\t\$(NOECHO) \$(NOOP)\n\n";
  1378. }
  1379. $install .= "\n";
  1380. $install .= "set_koha_permissions ::\n";
  1381. # This is necessary because EU::MM installs files
  1382. # as either 0444 or 0555, and we want the owner
  1383. # of Koha's files to have write permission by default.
  1384. foreach my $key (sort keys %$target_directories) {
  1385. $install .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_$key)\n"
  1386. unless exists $skip_directories->{$key};
  1387. }
  1388. }
  1389. $install .= "\n";
  1390. $install .= "warn_koha_env_vars ::\n";
  1391. $install .= "\t\$(NOECHO) \$(ECHO)\n";
  1392. $install .= "\t\$(NOECHO) \$(ECHO) Koha\\'s files have now been installed. \n";
  1393. $install .= "\t\$(NOECHO) \$(ECHO)\n";
  1394. $install .= "\t\$(NOECHO) \$(ECHO) In order to use Koha\\'s command-line batch jobs,\n";
  1395. $install .= "\t\$(NOECHO) \$(ECHO) you should set the following environment variables:\n";
  1396. $install .= "\t\$(NOECHO) \$(ECHO)\n";
  1397. $install .= "\t\$(NOECHO) \$(ECHO) export KOHA_CONF=\$(KOHA_DEST_KOHA_CONF_DIR)/koha-conf.xml\n";
  1398. $install .= "\t\$(NOECHO) \$(ECHO) export PERL5LIB=$perl5lib_dirs\n";
  1399. $install .= "\t\$(NOECHO) \$(ECHO)\n";
  1400. $install .= "\t\$(NOECHO) \$(ECHO) For other post-installation tasks, please consult the README.\n";
  1401. $install .= "\t\$(NOECHO) \$(ECHO)\n";
  1402. $install .= _update_zebra_conf_target();
  1403. $install .= upgrade();
  1404. return $install;
  1405. }
  1406. =head2 _update_zebra_conf_target
  1407. Add an installation target for updating
  1408. Zebra's configuration files.
  1409. =cut
  1410. sub _update_zebra_conf_target {
  1411. my $target = "\nupdate_zebra_conf ::\n";
  1412. $target .= "\tumask 022; \$(MOD_INSTALL) \\\n";
  1413. $target .= "\t\t\$(KOHA_INST_ZEBRA_CONF_DIR) \$(KOHA_DEST_ZEBRA_CONF_DIR) \n";
  1414. $target .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_ZEBRA_CONF_DIR)\n";
  1415. $target .= "\tumask 022; \$(MOD_INSTALL) \\\n";
  1416. return $target;
  1417. }
  1418. sub upgrade {
  1419. my $upgrade = "";
  1420. my $backup_suffix;
  1421. if (exists $install_log_values{'KOHA_INSTALLED_VERSION'}) {
  1422. my $version = $install_log_values{'KOHA_INSTALLED_VERSION'};
  1423. $version =~ s/\./_/g;
  1424. $backup_suffix = "_koha_$version";
  1425. } else {
  1426. $backup_suffix = "_upgrade_backup";
  1427. }
  1428. $upgrade .= qq/
  1429. MOD_BACKUP = \$(ABSPERLRUN) -MC4::Installer::UpgradeBackup -e 'backup_changed_files({\@ARGV}, '$backup_suffix', '\''\$(VERBINST)'\'', '\''\$(UNINST)'\'');' --
  1430. upgrade :: make_upgrade_backup install
  1431. \t\$(NOECHO) \$(NOOP)
  1432. make_upgrade_backup ::
  1433. \t\$(NOECHO) umask 022; \$(MOD_BACKUP) \\
  1434. /;
  1435. foreach my $key (qw/KOHA_CONF_DIR INTRANET_TMPL_DIR INTRANET_WWW_DIR OPAC_TMPL_DIR OPAC_WWW_DIR
  1436. ZEBRA_CONF_DIR PLUGINS_DIR/) {
  1437. $upgrade .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
  1438. unless exists $skip_directories->{$key} or
  1439. not exists $target_directories->{$key};
  1440. }
  1441. $upgrade =~ s/\\\n$/\n/;
  1442. return $upgrade;
  1443. }
  1444. sub postamble {
  1445. # put directory mappings into Makefile
  1446. # so that Make will export as environment
  1447. # variables -- this is for the use of
  1448. # rewrite-confg.PL
  1449. my $env;
  1450. #NOTE: Build __PERL5LIB_DIRS__ for rewrite-config.PL
  1451. my $perl5lib_dirs = _build_perl5lib_string({ target_dirs => $target_directories });
  1452. if ($perl5lib_dirs){
  1453. $env .= "export __PERL5LIB_DIRS__ := $perl5lib_dirs\n"
  1454. }
  1455. # Hereagain, we must alter syntax per platform...
  1456. {
  1457. $env .= join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories);
  1458. $env .= "\n\n";
  1459. $env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
  1460. }
  1461. return "$env\n";
  1462. }
  1463. sub _build_perl5lib_string {
  1464. my ($args) = @_;
  1465. my %unique_map = ();
  1466. my $perl5lib_str;
  1467. my $target_dirs = $args->{target_dirs};
  1468. my @dir_codes = ("PERL_MODULE_DIR","PERL_MODULE_LIB_DIR");
  1469. if ($target_dirs){
  1470. foreach my $code (@dir_codes){
  1471. my $path = $target_dirs->{ $code };
  1472. if ($path){
  1473. $unique_map{$path} = 1 unless $unique_map{$path};
  1474. }
  1475. }
  1476. my @paths = sort keys %unique_map;
  1477. if (@paths){
  1478. $perl5lib_str = join(':',@paths);
  1479. }
  1480. }
  1481. return $perl5lib_str;
  1482. }
  1483. __END__
  1484. =head1 SEE ALSO
  1485. ExtUtils::MakeMaker(3)
  1486. =head1 AUTHORS
  1487. MJ Ray mjr at phonecoop.coop
  1488. Galen Charlton galen.charlton at liblime.com
  1489. =cut
  1490. FIXME: deal with .htaccess