Initial fix to bug 417: non-root installer
[koha.git] / misc / installer.pl
1 #!/usr/bin/perl -w # please develop with -w
2
3 #use diagnostics;
4
5 use Install;
6 use strict; # please develop with the strict pragma
7
8 use vars qw( $input );
9
10 Install::setlanguage 'en';
11
12 my $domainname = `hostname`; # Note: must not have any arguments (portability)
13 if ($domainname =~ /^[^\s\.]+\.([-a-z0-9\.]+)$/) {
14    $domainname = $1;
15 } else {
16    undef $domainname;
17    if (open(INPUT, "</etc/resolv.conf")) {
18       while (<INPUT>) {
19          $domainname = $1 if /^domain\s+([-a-z0-9\.]+)\s*$/i;
20       last if defined $domainname;
21       }
22       close INPUT;
23    }
24 }
25 Install::setdomainname $domainname;
26
27 ###############################################
28 # SET  THE  etcdir  ENVIRONMENT  VAR  INSTEAD #
29 ###############################################
30 my $etcdir = $ENV{etcdir}||'/etc';
31 system("mkdir -p $etcdir");
32
33 Install::setetcdir $etcdir;
34
35 unless (-d 'intranet-html') {
36    print <<EOP;
37 You seem to be installing from CVS. Please run the "buildrelease" script
38 and install from the resulting release tarball.
39 EOP
40    exit 1;
41 }
42
43 my $kohaversion=`cat koha.version`;
44 chomp $kohaversion;
45 Install::setkohaversion $kohaversion;
46
47
48 if ($kohaversion =~ /RC/) {
49     releasecandidatewarning();
50 }
51
52 checkabortedinstall();
53
54 if (-e "$etcdir/koha.conf") {
55     my $installedversion=`grep kohaversion= "$etcdir/koha.conf"`;
56     chomp $installedversion;
57     $installedversion=~m/kohaversion=(.*)/;
58     $installedversion=$1;
59     my $installedversionmsg;
60     if ($installedversion) {
61         $installedversionmsg=getmessage('KohaVersionInstalled', [$installedversion]);
62     } else {
63         $installedversionmsg=getmessage('KohaUnknownVersionInstalled');
64     }
65
66     my $message=getmessage('KohaAlreadyInstalled', [$etcdir, $kohaversion, $installedversionmsg]);
67     showmessage($message, 'none');
68     exit;
69 }
70
71 my $continuingmsg=getmessage('continuing');
72
73 my $message=getmessage('WelcomeToKohaInstaller');
74 my $answer=showmessage($message, 'yn');
75
76 if ($answer eq "Y" || $answer eq "y") {
77         print $continuingmsg;
78     } else {
79     print qq|
80 This installer currently does not support a completely automated
81 setup.
82
83 Please be sure to read the documentation, or visit the Koha website
84 at http://www.koha.org for more information.
85 |;
86     exit;
87 };
88
89 # Check for missing Perl Modules
90 checkperlmodules();
91
92 # Ask for installation directories
93 getapacheinfo();
94
95 getinstallationdirectories();
96
97 getdatabaseinfo();
98
99 getapachevhostinfo();
100
101 updateapacheconf();
102
103 basicauthentication();
104
105 installfiles();
106
107 backupmycnf();
108
109 databasesetup();
110
111 updatedatabase();
112
113 populatedatabase();
114
115 restoremycnf();
116
117 finalizeconfigfile();
118
119 restartapache();
120
121
122
123
124 showmessage(getmessage('AuthenticationWarning', [$etcdir]), 'PressEnter');
125
126
127 showmessage(getmessage('Completed', [ Install::getservername(), Install::getintranetport(), Install::getservername(), Install::getopacport()]), 'PressEnter');
128
129
130
131
132 if (-f "kohareporter") {
133     my $reply=showmessage('Would you like to complete a survey about your library?', 'yn', 'y');
134     if ($reply=~/y/i) {
135         system("perl kohareporter");
136     }
137 }