]> git.datanom.net - webcal.git/blob - install/setup
Initial upload
[webcal.git] / install / setup
1 #!/usr/bin/env perl
2 # $Id$
3
4 use strict;
5 use warnings;
6
7 BEGIN {
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
17 die "Only root may run this" if $> != 0;
18 die "Script must be executed from its own folder"
19 unless -e getcwd.'/install.php';
20
21 my (@apache_dir, @application);
22
23 find(\&find_apache, '/etc', '/usr/local/etc');
24
25 sub 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
32 sub find_appl {
33 push @application, $File::Find::name;
34 }
35
36 sub 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
64 my $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
72 print <<__HELP;
73 Davical Web Calender (C) 2009, Michael Rasmussen.
74 Released under GNU General Public License version 3+.
75 This license applies to all files except where a different license
76 state otherwise.
77
78 This script will create the basic installation of Davical web calendar.
79 You only need to run this script if you want to install the application
80 outside the Apache's web scope.
81
82 You will be asked a number of questions which must all be answered.
83 The script will try to figure out must of the answers for you and
84 present the found information inside []. Should the script not find
85 the answers for you (you will see []) or you disaggree to the suggested
86 setting you must provide the required setting yourself. If you aggree
87 to the found setting you simply press enter.
88
89 __HELP
90
91 print "Apache2 configuration folder [";
92 print $apache_dir[0] if scalar @apache_dir > 0;
93 print "]? ";
94 my $folder = <STDIN>;
95 chomp $folder;
96 $folder = $apache_dir[0] unless $folder;
97 die "Missing Apache configuration folder\n" unless $folder;
98
99 my $url = 'webcal';
100 print "Application URL [$url]? ";
101 my $url1 = <STDIN>;
102 chomp $url1;
103 $url1 = $url unless $url1;
104 die "Missing application web root\n" unless $url1;
105
106 my $cwd = getcwd;
107 my ($file, $dir) = fileparse($cwd);
108 $cwd = ($dir =~ /(.*)\/$/) ? $1 : $dir;
109 print "Application web root [$cwd]? ";
110 my $root = <STDIN>;
111 chomp $root;
112 do {
113 my $home = $ENV{'HOME'};
114 $root =~ /^~(.*)$/;
115 $root = $home.$1;
116 } if $root =~ m/^~/;
117 $root = $cwd unless $root;
118 die "Missing application web root\n" unless $root;
119
120 $config =~ s/__TOP__/$root\//g;
121 $config =~ s/__ALIAS__/\/$url1/;
122
123 print <<_RESULT;
124
125 This setup will be used:
126 Apache configuration folder:\t$folder
127 Application URL:\t\t/$url1
128 Application top folder:\t\t$root
129
130 Installing this configuration in Apache:
131 $config
132 _RESULT
133
134 print "Continue [Y/n]? ";
135 my $continue = <STDIN>;
136 chomp $continue unless $continue =~ m/^\n$/;
137 exit unless $continue =~ m/^[Yy\n]$/;
138
139 copy_files($root) unless $root eq $cwd;
140
141 my $config_file = "$folder/conf.d/webcal.conf";
142 do {
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
149 open CONF, "> $config_file" or die $!;
150 print CONF $config;
151 close CONF;
152
153 print <<_INFO;
154
155 Setup has completed. You need to restart Apache before
156 you continue with the installation of WebCal.
157
158 After Apache has been restarted point your web browser
159 to this address: http://localhost/$url1
160 Then simply follow the wizard.
161
162 For securety reasons I strongly advice you to only allow
163 access to the application via secure HTTP.
164
165 Happy hacking:-)
166 _INFO
167
168 exit 0;
This page took 0.091112 seconds and 6 git commands to generate.