#!/usr/bin/env perl # $Id$ use strict; use warnings; BEGIN { eval { use File::Basename; use File::Copy; use File::Find; use File::Path; use Cwd; }; die $@ if $@; } die "Only root may run this" if $> != 0; die "Script must be executed from its own folder" unless -e getcwd.'/install.php'; my (@apache_dir, @application); find(\&find_apache, '/etc', '/usr/local/etc'); sub find_apache { return unless -d; return unless $File::Find::name =~ /\.*etc\/([apache2|httpd]+\/conf.d)\.*/; my $path = "$File::Find::dir"; push @apache_dir, $path; } sub find_appl { push @application, $File::Find::name; } sub copy_files { my $path = shift; if (-e $path) { print "Directory exists. Continue [y/n]? "; my $continue = ; chomp $continue; exit unless $continue eq 'y'; } else { umask 022; mkpath ($path) or die $!; } find(\&find_appl, '..'); foreach (@application) { next if /^..$/; my $from = $_; /^..\/(.+)/; do { mkdir ("$path/$1"); next; } if -d $from; my ($file, $dir) = fileparse($1); $dir = '' if $dir =~ /^.\//; print STDERR "Copying: $from -> $path/$dir\n"; copy($from, "$path/$dir") or die "Copy failed: $!"; } } my $config = <<__CONF; Alias __ALIAS__ "__TOP__" Options Multiviews SymLinksIfOwnerMatch php_value include_path '.:__TOP__:__TOP__navigate:__TOP__utils:__TOP__include:__TOP__caldav:__TOP__caldav/awl:__TOP__templates:__TOP__events' __CONF print <<__HELP; Davical Web Calender (C) 2009, Michael Rasmussen. Released under GNU General Public License version 3+. This license applies to all files except where a different license state otherwise. This script will create the basic installation of Davical web calendar. You only need to run this script if you want to install the application outside the Apache's web scope. You will be asked a number of questions which must all be answered. The script will try to figure out must of the answers for you and present the found information inside []. Should the script not find the answers for you (you will see []) or you disaggree to the suggested setting you must provide the required setting yourself. If you aggree to the found setting you simply press enter. __HELP print "Apache2 configuration folder ["; print $apache_dir[0] if scalar @apache_dir > 0; print "]? "; my $folder = ; chomp $folder; $folder = $apache_dir[0] unless $folder; die "Missing Apache configuration folder\n" unless $folder; my $url = 'webcal'; print "Application URL [$url]? "; my $url1 = ; chomp $url1; $url1 = $url unless $url1; die "Missing application web root\n" unless $url1; my $cwd = getcwd; my ($file, $dir) = fileparse($cwd); $cwd = ($dir =~ /(.*)\/$/) ? $1 : $dir; print "Application web root [$cwd]? "; my $root = ; chomp $root; do { my $home = $ENV{'HOME'}; $root =~ /^~(.*)$/; $root = $home.$1; } if $root =~ m/^~/; $root = $cwd unless $root; die "Missing application web root\n" unless $root; $config =~ s/__TOP__/$root\//g; $config =~ s/__ALIAS__/\/$url1/; print <<_RESULT; This setup will be used: Apache configuration folder:\t$folder Application URL:\t\t/$url1 Application top folder:\t\t$root Installing this configuration in Apache: $config _RESULT print "Continue [Y/n]? "; my $continue = ; chomp $continue unless $continue =~ m/^\n$/; exit unless $continue =~ m/^[Yy\n]$/; copy_files($root) unless $root eq $cwd; my $config_file = "$folder/conf.d/webcal.conf"; do { print "$config_file: File exists, overwrite [y/n]? "; my $continue = ; chomp $continue unless $continue =~ m/^\n$/; exit unless $continue =~ m/^[Yy\n]$/; } if -e $config_file; open CONF, "> $config_file" or die $!; print CONF $config; close CONF; print <<_INFO; Setup has completed. You need to restart Apache before you continue with the installation of WebCal. After Apache has been restarted point your web browser to this address: http://localhost/$url1 Then simply follow the wizard. For securety reasons I strongly advice you to only allow access to the application via secure HTTP. Happy hacking:-) _INFO exit 0;