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.
 
 
 
 
 
 

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