Commit | Line | Data |
---|---|---|
5abdb380 TC |
1 | #!perl -w |
2 | use strict; | |
3 | use Term::ReadLine; | |
4 | use Config; | |
5 | my $term = new Term::ReadLine "BSE Install"; | |
6 | use POSIX (); | |
7 | ||
8 | $|=1; | |
9 | ||
10 | unless ($term->ReadLine eq 'Term::ReadLine') { | |
11 | print "Happily, you may have a decent readline\n"; | |
12 | } | |
13 | else { | |
14 | print "Sadly, you only have the basic readline stub installed\n"; | |
15 | } | |
16 | ||
17 | print <<EOS; | |
18 | BSE installation | |
19 | ================ | |
20 | ||
21 | This script will take you through installation of BSE. | |
22 | ||
23 | If you want to perform an upgrade, change directory to the cgi-bin directory | |
24 | of the existing installation and run this script again. | |
25 | ||
26 | Press Enter to continue (or Ctrl-C to abort). | |
27 | EOS | |
28 | <STDIN>; | |
29 | ++$|; | |
30 | ||
31 | my %config; | |
32 | my $upgrade; | |
33 | if (-e 'modules/Constants.pm' && -e 'modules/Generate/Article.pm') { | |
34 | my $prompt = <<EOS; | |
35 | An existing installation has been found. | |
36 | ||
37 | Do you want to perform an upgrade? | |
38 | EOS | |
39 | if (askYN($prompt, 1)) { | |
40 | ||
41 | } | |
42 | } | |
43 | ||
44 | my @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, | |
51 | The directory that the other directories are based under. This isn't | |
52 | actually used directly, but can be used to help initialize the other | |
53 | directory names. | |
54 | ||
55 | This must be an absolute directory. | |
56 | EOS | |
57 | val => \&is_absdir, def=>}, | |
58 | TMPLDIR => { desc=>"Templates directory", cat=>'dir', | |
59 | def=>'$BASEDIR/templates', help=><<EOS, | |
60 | This is where page and email templates are stored. | |
61 | ||
62 | This can be an absolute directory, or use ./foo to make it relative to | |
63 | BASEDIR. | |
64 | EOS | |
65 | val => \&is_abs_baserel }, | |
66 | CONTENTBASE => { desc=>"Content directory", cat=>'dir', | |
67 | def=>'$BASEDIR/htdocs', help=><<"EOS", | |
68 | The base directory that contains your site content. This must be the top | |
69 | directory of your site. | |
70 | ||
71 | This can be an absolute directory, or use ./foo to make it relative to | |
72 | BASEDIR. | |
73 | EOS | |
74 | val=>\&is_abs_baserel }, | |
75 | IMAGEDIR => { desc => "Images directory", cat=>'dir', | |
76 | def => '$CONTENTDIR/images', help => <<"EOS", | |
77 | ||
78 | EOS | |
79 | }, | |
80 | DATADIR => { desc => "Data directory" }, | |
81 | ); | |
82 | ||
83 | my %conf_info = @conf_info; | |
84 | my @conf_order = grep !ref, @conf_info; | |
85 | ||
86 | ||
87 | ||
88 | sub 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 | ||
101 | sub 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 | ||
125 | sub clear { | |
126 | if ($^O =~ /win32/i) { | |
127 | system "cls"; | |
128 | } | |
129 | else { | |
130 | system "clear"; | |
131 | } | |
132 | } |