]> git.datanom.net - webcal.git/blame - install/setup
Initial upload
[webcal.git] / install / setup
CommitLineData
a5eae6b7
MR
1#!/usr/bin/env perl
2# $Id$
3
4use strict;
5use warnings;
6
7BEGIN {
8 eval {
9 use File::Basename;
10 use File::Copy;
11 use File::Find;
12 use File::Path;
13 use Cwd;
14 }; die $@ if $@;
15}
16
17die "Only root may run this" if $> != 0;
18die "Script must be executed from its own folder"
19 unless -e getcwd.'/install.php';
20
21my (@apache_dir, @application);
22
23find(\&find_apache, '/etc', '/usr/local/etc');
24
25sub find_apache {
26 return unless -d;
27 return unless $File::Find::name =~ /\.*etc\/([apache2|httpd]+\/conf.d)\.*/;
28 my $path = "$File::Find::dir";
29 push @apache_dir, $path;
30}
31
32sub find_appl {
33 push @application, $File::Find::name;
34}
35
36sub copy_files {
37 my $path = shift;
38 if (-e $path) {
39 print "Directory exists. Continue [y/n]? ";
40 my $continue = <STDIN>;
41 chomp $continue;
42 exit unless $continue eq 'y';
43 }
44 else {
45 umask 022;
46 mkpath ($path) or die $!;
47 }
48 find(\&find_appl, '..');
49 foreach (@application) {
50 next if /^..$/;
51 my $from = $_;
52 /^..\/(.+)/;
53 do {
54 mkdir ("$path/$1");
55 next;
56 } if -d $from;
57 my ($file, $dir) = fileparse($1);
58 $dir = '' if $dir =~ /^.\//;
59 print STDERR "Copying: $from -> $path/$dir\n";
60 copy($from, "$path/$dir") or die "Copy failed: $!";
61 }
62}
63
64my $config = <<__CONF;
65 Alias __ALIAS__ "__TOP__"
66 <Directory "__TOP__">
67 Options Multiviews SymLinksIfOwnerMatch
68 php_value include_path '.:__TOP__:__TOP__navigate:__TOP__utils:__TOP__include:__TOP__caldav:__TOP__caldav/awl:__TOP__templates:__TOP__events'
69 </Directory>
70__CONF
71
72print <<__HELP;
73Davical Web Calender (C) 2009, Michael Rasmussen.
74Released under GNU General Public License version 3+.
75This license applies to all files except where a different license
76state otherwise.
77
78This script will create the basic installation of Davical web calendar.
79You only need to run this script if you want to install the application
80outside the Apache's web scope.
81
82You will be asked a number of questions which must all be answered.
83The script will try to figure out must of the answers for you and
84present the found information inside []. Should the script not find
85the answers for you (you will see []) or you disaggree to the suggested
86setting you must provide the required setting yourself. If you aggree
87to the found setting you simply press enter.
88
89__HELP
90
91print "Apache2 configuration folder [";
92print $apache_dir[0] if scalar @apache_dir > 0;
93print "]? ";
94my $folder = <STDIN>;
95chomp $folder;
96$folder = $apache_dir[0] unless $folder;
97die "Missing Apache configuration folder\n" unless $folder;
98
99my $url = 'webcal';
100print "Application URL [$url]? ";
101my $url1 = <STDIN>;
102chomp $url1;
103$url1 = $url unless $url1;
104die "Missing application web root\n" unless $url1;
105
106my $cwd = getcwd;
107my ($file, $dir) = fileparse($cwd);
108$cwd = ($dir =~ /(.*)\/$/) ? $1 : $dir;
109print "Application web root [$cwd]? ";
110my $root = <STDIN>;
111chomp $root;
112do {
113 my $home = $ENV{'HOME'};
114 $root =~ /^~(.*)$/;
115 $root = $home.$1;
116} if $root =~ m/^~/;
117$root = $cwd unless $root;
118die "Missing application web root\n" unless $root;
119
120$config =~ s/__TOP__/$root\//g;
121$config =~ s/__ALIAS__/\/$url1/;
122
123print <<_RESULT;
124
125This setup will be used:
126Apache configuration folder:\t$folder
127Application URL:\t\t/$url1
128Application top folder:\t\t$root
129
130Installing this configuration in Apache:
131$config
132_RESULT
133
134print "Continue [Y/n]? ";
135my $continue = <STDIN>;
136chomp $continue unless $continue =~ m/^\n$/;
137exit unless $continue =~ m/^[Yy\n]$/;
138
139copy_files($root) unless $root eq $cwd;
140
141my $config_file = "$folder/conf.d/webcal.conf";
142do {
143 print "$config_file: File exists, overwrite [y/n]? ";
144 my $continue = <STDIN>;
145 chomp $continue unless $continue =~ m/^\n$/;
146 exit unless $continue =~ m/^[Yy\n]$/;
147} if -e $config_file;
148
149open CONF, "> $config_file" or die $!;
150print CONF $config;
151close CONF;
152
153print <<_INFO;
154
155Setup has completed. You need to restart Apache before
156you continue with the installation of WebCal.
157
158After Apache has been restarted point your web browser
159to this address: http://localhost/$url1
160Then simply follow the wizard.
161
162For securety reasons I strongly advice you to only allow
163access to the application via secure HTTP.
164
165Happy hacking:-)
166_INFO
167
168exit 0;
This page took 0.056908 seconds and 5 git commands to generate.