Updated TODO.
[gruta.git] / bin / gruta_mksite
blob6abe79e8046665391fd09cc15360163576e2edfc
1 #!/usr/bin/perl
3 # Creates a Gruta site, asking for values interactively
4 # Angel Ortega <angel@triptico.com>
6 print <<EOF;
7 This scripts guides you in the creation of a Gruta web site.
8 You better execute it as the Apache user, probably www-data.
9 EOF
11 my $g_cgi = '';
12 my $r;
14 print "\nDo you want to build a ptkdb-debuggable site?\n";
15 print "(You probable don't) [y/N] ";
17 $r = <>; chomp($r);
19 if ($r eq 'y') {
20 $g_cgi .= "#!/usr/bin/perl -d:ptkdb\n";
21 $g_cgi .= "sub BEGIN { \$ENV{'DISPLAY'} = ':0.0'; }\n\n";
23 else {
24 $g_cgi .= "#!/usr/bin/perl\n\n";
27 print "\nEnter your locale. If you don't want one, leave it empty.\n";
28 print "It would probably be a string like es_ES.UTF-8\n";
29 print "Locale: ";
31 $r = <>; chomp($r);
33 $g_cgi .= "use locale;\n";
34 $g_cgi .= "use POSIX qw (locale_h);\n";
36 if ($r) {
37 $g_cgi .= "setlocale(LC_ALL, '" . $r . "');\n";
40 $g_cgi .= "\n";
42 print "\nWhich source backend do you prefer, FS or DBI?\n";
43 print "FS are plain files, DBI is an SQL database.\n";
44 print "(If DBI, you need the DBD drivers and probably a server)\n";
46 do {
47 print "Source (enter FS or DBI): ";
48 $r = <>; chomp($r);
49 } while ($r ne 'FS' && $r ne 'DBI');
51 $source = $r;
53 $g_cgi .= join(";\n", (
54 'use Gruta',
55 'use Gruta::CGI',
56 'use Gruta::Source::' . $source,
57 'use Gruta::Renderer::Grutatxt',
58 'use Gruta::Renderer::HTML',
59 'use Gruta::Renderer::Text',
60 'use Gruta::Template::Artemus'
64 if ($source eq 'DBI') {
65 print "\nEnter your DBI string. If you use SQLite, it will probably\n";
66 print "be something like dbi:SQLite:\$base/var/gruta.db\n";
68 do {
69 print "DBI String: ";
70 $r = <>; chomp($r);
71 } while ($r eq '');
73 $dbi_string = $r;
76 $g_cgi .= ";\n\n";
78 print "\nEnter the name of your site. It would probably your host name,\n";
79 print "but not necessarily. Do NOT include http://.\n";
80 print "Site name: ";
82 $r = <>; chomp($r);
84 $sitename = $r;
86 $s = $sitename || 'yoursite';
88 print "\nEnter the base directory. It should best be inside\n";
89 print "the Apache www tree, so /var/www/${s} is probably correct.\n";
91 do {
92 print "Basename: ";
93 $r = <>; chomp($r);
94 } while ($r eq '');
96 $basename = $r;
98 $g_cgi .= "\$base = '" . $basename . "';\n\n";
100 print "\nEnter your base url (probably http://$sitename). Can be empty.\n";
101 print "Base url: ";
103 $r = <>; chomp($r);
105 $baseurl = $r;
107 print "\nDo you want static URLs? If you say yes, you must add the\n";
108 print "Apache's mod_rewrite directives in the documentation.\n";
109 print "Use static URLs? [y/N]: ";
111 $r = <>; chomp($r);
113 $static_urls = $r eq 'y' ? 1 : 0;
115 print "\nUpload directories. Enter a list of blank-separated subdirectories.\n";
116 print "If you don't include 'img', it will be included for you.\n";
117 print "Upload directories: ";
119 $r = <>; chomp($r);
121 if (!($r =~ /img/)) {
122 $r .= ' img ';
125 @uploads = split(/\s/, $r);
127 $g_cgi .= "my \$g = Gruta-new(\n";
128 $g_cgi .= "\tid\t\t=> '" . $sitename . "',\n";
130 if ($source eq 'FS') {
131 $g_cgi .= "\tsource\t\t=> Gruta::Source::FS->new(path => \"\${base}/var\"),\n";
133 else {
134 $g_cgi .= "\tsource\t\t=> Gruta::Source::DBI->new(string => \"$dbi_string\"),\n";
137 $g_cgi .= "\trenderers\t=> [\n";
138 $g_cgi .= "\t\tGruta::Renderer::Grutatxt->new(),\n",
139 $g_cgi .= "\t\tGruta::Renderer::HTML->new(),\n",
140 $g_cgi .= "\t\tGruta::Renderer::HTML->new( valid_tags => undef ),\n",
141 $g_cgi .= "\t\tGruta::Renderer::Text->new(),\n";
142 $g_cgi .= "\t],\n";
143 $g_cgi .= "\ttemplate\t=> Gruta::Template::Artemus->new(\n";
144 $g_cgi .= "\t\t\tpath => [\n";
145 $g_cgi .= "\t\t\t\t'/usr/share/gruta/templates/artemus/ALL',\n";
146 $g_cgi .= "\t\t\t\t'/usr/share/gruta/templates/artemus/en'\n";
147 $g_cgi .= "\t\t\t]\n";
148 $g_cgi .= "\t),\n";
149 $g_cgi .= "\tcgi\t\t=> Gruta::CGI->new(\n";
150 $g_cgi .= "\t\t\tupload_dirs => [\n";
152 foreach my $d (@uploads) {
153 $g_cgi .= "\t\t\t\t\"\${base}/$d\",\n" if $d;
156 $g_cgi .= "\t\t\t],\n";
157 $g_cgi .= "\targs\t\t=> {\n";
159 if ($baseurl) {
160 $g_cgi .= "\t\t\tbase_url\t=>\t'" . $baseurl . "',\n";
163 $g_cgi .= "\t\t\tstatic_urls\t=>\t$static_urls,\n";
165 $g_cgi .= "\t}\n";
166 $g_cgi .= ");\n\n";
167 $g_cgi .= "\$g->run();\n";
169 # start of build
171 print "\nCreating...\n";
172 mkdir $basename or die "Cannot create $basename: $!";
173 mkdir "$basename/var" or die "Cannot create $basename/var: $!";
175 open O, ">$basename/g.cgi" or die "Cannot create $basename/g.cgi: $!";
176 print O $g_cgi;
177 close O;
179 print <<EOF;
181 Operation successful.
183 You'll need at least the following Apache directives affecting
184 the newly created $basename:
186 DirectoryIndex g.cgi
188 <Location /var>
189 order allow,deny
190 deny from all
191 </Location>