#!/usr/bin/perl -w
my
$VERSION
=
'0.1'
;
my
$overwrite
= 0;
print
<<
"__HEREDOC__"
;
installwebfiles.PL by Leo Charre
================================
This script lets you auto install website support files
for
this distro.
It deploys html files, template files, cgis, css, etc.
It is here
for
your convenience and you are under
no
obligation/need to
use
it
for
the usefulness of this distribution.
To
use
this, your structure must have
~/public_html
~/cgi-bin
Where ~ is your home directory. If any files exist you will be prompted
before
they are overwritten. Only cgi and html support files will be
handled by this script.
__HEREDOC__
my
$action
= ioyn(
'Would you like to go ahead and install the web files?'
) or
exit
;
if
(
$action
==2){
$overwrite
=1;}
$ENV
{HOME} = iopath(
"Your web account HOME dir? (/home/xxx)?"
,
"$ENV{HOME}"
);
my
@manifest
;
open
(FILE,
'<MANIFEST'
) or
die
(
"missing MANIFEST ? $!"
);
map
{ m/^\b([^
close
FILE;
my
@cgi
=
grep
{ /^cgi-bin/ }
@manifest
;
my
@html
=
grep
{ /^public_html/ }
@manifest
;
for
(
@cgi
){
copyone(
$_
);
}
for
(
@html
){
copyone(
$_
);
}
exit
;
sub
copyone {
my
$manifest
=
shift
;
$manifest
=~/^([^\/]+)\// or
return
;
my
$ok
=1;
-d
"$ENV{HOME}/$1"
or
warn
"$ENV{HOME}/$1 does not exist"
and
return
;
my
$loc
=
$manifest
;
$loc
=~s/\/([^\/]+)$// or
warn
"cant get loc to $manifest\n"
and
return
;
-d
"$ENV{HOME}/$loc"
or File::Path::mkpath(
"$ENV{HOME}/$loc"
);
if
(-f
"$ENV{HOME}/$manifest"
and !
$overwrite
and
$manifest
=~/conf$/){
$ok
= ioyn(
"File [$ENV{HOME}/$manifest] exists, overrite?"
);
if
(
$ok
==2){
$overwrite
=1; }
}
$ok
or
print
STDERR
"[$ENV{HOME}/$manifest] skipped."
;
File::Copy::cp(
$manifest
,
"$ENV{HOME}/$manifest"
);
if
(
$manifest
=~/\.cgi$|\.pl$/){
chmod
0755,
"$ENV{HOME}/$manifest"
; }
}
sub
ioyn {
my
$question
=
shift
;
my
$val
=
undef
;
until
(
defined
$val
){
print
$question
.
' (y/n/a): '
;
$val
= <STDIN>;
chomp
$val
;
if
(
$val
eq
'y'
){
$val
= 1; }
elsif
(
$val
eq
'n'
){
$val
= 0;}
elsif
(
$val
eq
'a'
){
$val
= 2;}
else
{
$val
=
undef
; }
}
return
$val
;
}
sub
iopath {
my
$question
=
shift
;
my
$predetermined
=
shift
;
my
$val
=
undef
;
until
(
$val
){
if
(
$predetermined
){
print
"$question [$predetermined]: "
;
}
else
{
print
"$question []: "
;
}
$val
= <STDIN>;
if
(
$val
eq
"\n"
and
$predetermined
){
$val
=
$predetermined
;
}
chomp
$val
;
unless
(-d
$val
){
print
"That is not a directory on this machine"
;
$val
=
undef
;
}
}
return
$val
;
}