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.
 
 
 
 
 
 

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