]> git.imager.perl.org - bse.git/blame - install.perl
make the request object accessible from the cart object
[bse.git] / install.perl
CommitLineData
5abdb380
TC
1#!perl -w
2use strict;
3use Term::ReadLine;
4use Config;
5my $term = new Term::ReadLine "BSE Install";
6use POSIX ();
7
8$|=1;
9
10unless ($term->ReadLine eq 'Term::ReadLine') {
11 print "Happily, you may have a decent readline\n";
12}
13else {
14 print "Sadly, you only have the basic readline stub installed\n";
15}
16
17print <<EOS;
18BSE installation
19================
20
21This script will take you through installation of BSE.
22
23If you want to perform an upgrade, change directory to the cgi-bin directory
24of the existing installation and run this script again.
25
26Press Enter to continue (or Ctrl-C to abort).
27EOS
28<STDIN>;
29++$|;
30
31my %config;
32my $upgrade;
33if (-e 'modules/Constants.pm' && -e 'modules/Generate/Article.pm') {
34 my $prompt = <<EOS;
35An existing installation has been found.
36
37Do you want to perform an upgrade?
38EOS
39 if (askYN($prompt, 1)) {
40
41 }
42}
43
44my @conf_info =
45 (
46 DB => { desc => "Name of mysql database", cat=>'db', },
47 UN => { desc => "Mysql database username", cat=>'db', },
48 PW => { desc => "Mysql database password", cat=>'db', },
49 BASEDIR => { desc=>"Base directory of installation", cat=>'dir',
50 help => <<EOS,
51The directory that the other directories are based under. This isn't
52actually used directly, but can be used to help initialize the other
53directory names.
54
55This must be an absolute directory.
56EOS
57 val => \&is_absdir, def=>},
58 TMPLDIR => { desc=>"Templates directory", cat=>'dir',
59 def=>'$BASEDIR/templates', help=><<EOS,
60This is where page and email templates are stored.
61
62This can be an absolute directory, or use ./foo to make it relative to
63BASEDIR.
64EOS
65 val => \&is_abs_baserel },
66 CONTENTBASE => { desc=>"Content directory", cat=>'dir',
67 def=>'$BASEDIR/htdocs', help=><<"EOS",
68The base directory that contains your site content. This must be the top
69directory of your site.
70
71This can be an absolute directory, or use ./foo to make it relative to
72BASEDIR.
73EOS
74 val=>\&is_abs_baserel },
75 IMAGEDIR => { desc => "Images directory", cat=>'dir',
76 def => '$CONTENTDIR/images', help => <<"EOS",
77
78EOS
79 },
80 DATADIR => { desc => "Data directory" },
81 );
82
83my %conf_info = @conf_info;
84my @conf_order = grep !ref, @conf_info;
85
86
87
88sub askYN {
89 my ($query, $def) = @_;
90 print $query;
91 while (1) {
92 print $def ? "[Y]" : "[N]",":";
93 my $resp = $term->readline;
94 return $def if $resp =~ /^\s*$/;
95 return 1 if $resp =~ /y/i;
96 return 0 if $resp =~ /n/i;
97 print "Please enter yes or no ";
98 }
99}
100
101sub askDir {
102 my ($item) = @_;
103
104 my $def;
105 $item->{def} and ($def = $item->{def}) =~ s/\$(\w+)/$config{$1}/g;
106 while (1) {
107 my $resp = $term->readline($item->{desc}, $def);
108 if ($resp eq 'help' || $resp eq '?') {
109 print $item->{help} || "Sorry, no help for this item\n";
110 next;
111 }
112 if ($item->{val}) {
113 eval {
114 $item->{val}->($resp);
115 };
116 if ($@) {
117 print $@;
118 next;
119 }
120 }
121 return $resp;
122 }
123}
124
125sub clear {
126 if ($^O =~ /win32/i) {
127 system "cls";
128 }
129 else {
130 system "clear";
131 }
132}