setup automator
authorJoey Hess <joey@kodama.kitenet.net>
Sun, 27 Jul 2008 05:39:11 +0000 (01:39 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Sun, 27 Jul 2008 05:39:11 +0000 (01:39 -0400)
"ikiwiki -setup /etc/ikiwiki/simple.setup"
can be used set up a new wiki in seconds

IkiWiki/Setup/Automator.pm [new file with mode: 0644]
debian/changelog
doc/setup.mdwn
simple.setup

diff --git a/IkiWiki/Setup/Automator.pm b/IkiWiki/Setup/Automator.pm
new file mode 100644 (file)
index 0000000..8cf158d
--- /dev/null
@@ -0,0 +1,95 @@
+#!/usr/bin/perl
+# Ikiwiki setup automator.
+
+package IkiWiki::Setup::Automator;
+
+use warnings;
+use strict;
+use IkiWiki;
+use Term::ReadLine;
+use File::Path;
+
+sub ask ($$) { #{{{
+       my ($question, $default)=@_;
+
+       my $r=Term::ReadLine->new("ikiwiki");
+       $r->readline($question." ", $default);
+} #}}}
+
+sub import (@) { #{{{
+       my %setup=@_;
+
+       # Sanitize this to avoid problimatic directory names.
+       $setup{wikiname}=~s/[^-A-Za-z0-9_] //g;
+       if (! length $setup{wikiname}) {
+               die "you must enter a wikiname\n";
+       }
+
+       # Avoid overwriting any existing files.
+       foreach my $key (qw{srcdir destdir repository setupfile}) {
+               next unless exists $setup{$key};
+               my $add="";
+               while (-e $setup{$key}.$add) {
+                       $add=1 if ! $add;
+                       $add++;
+               }
+               $setup{$key}.=$add;
+       }
+
+       print "\n\nSetting up $setup{wikiname} ...\n";
+
+       # Set up the repository.
+       mkpath($setup{srcdir}) || die "mkdir $setup{srcdir}: $!";
+       delete $setup{repository} if ! $setup{rcs} || $setup{rcs}=~/bzr|mercurial/;
+       if ($setup{rcs}) {
+               my @params=($setup{rcs}, $setup{srcdir});
+               push @params, $setup{repository} if exists $setup{repository};
+               if (system("ikiwiki-makerepo", @params) != 0) {
+                       die "failed: ikiwiki-makerepo @params";
+               }
+       }
+
+       # Generate setup file.
+       my @params=(
+               "--dumpsetup", $setup{setupfile},
+               "--wikiname", $setup{wikiname},
+               "--url", $setup{url},
+               "--cgiurl", $setup{cgiurl}
+       );
+       push @params, "--rcs", $setup{rcs} if $setup{rcs};
+       if (exists $setup{add_plugins}) {
+               foreach my $plugin (@{$setup{add_plugins}}) {
+                       push @params, "--plugin", $plugin;
+               }
+       }
+       if (exists $setup{disable_plugins}) {
+               foreach my $plugin (@{$setup{disable_plugins}}) {
+                       push @params, "--disable-plugin", $plugin;
+               }
+       }
+       foreach my $key (keys %setup) {
+               next if $key =~ /^(disable_plugins|add_plugins|setupfile|wikiname|url|cgiurl||srcdir|destdir|repository)$/;
+               push @params, "--set", "$key=$setup{$key}";
+       }
+       if (system("ikiwiki", @params, $setup{srcdir}, $setup{destdir}) != 0) {
+               die "failed: ikiwiki @params";
+       }
+
+       # Build the wiki.
+       mkpath($setup{destdir}) || die "mkdir $setup{destdir}: $!";
+       if (system("ikiwiki", "--setup", $setup{setupfile}) != 0) {
+               die "ikiwiki --setup $setup{setupfile} failed";
+       }
+
+       # Done!
+       print "\n\nSuccessfully set up $setup{wikiname}:\n";
+       foreach my $key (qw{url srcdir destdir repository setupfile}) {
+               next unless exists $setup{$key};
+               my $value=$setup{$key};
+               $value=~s/^\Q$ENV{HOME}\E\//~\//;
+               print "\t$key: ".(" " x (10 - length($key)))." $value\n";
+       }
+       exit 0;
+} #}}}
+
+1
index 982c557962325d19741f69f5155a3d4d276772dd..e146bf8d4ab93efabb782abe5fda9215d8b0deb1 100644 (file)
@@ -1,5 +1,7 @@
 ikiwiki (2.60) UNRELEASED; urgency=low
  
+  * Starting with this version, "ikiwiki -setup /etc/ikiwiki/simple.setup"
+    can be used set up a new wiki in seconds.
   * Add getsetup hook, all plugins that add fields to %config should use it.
   * ikiwiki --dumpsetup can generate a nice setup file snapshotting ikiwiki's
     current configuration.
index 9c67c2a6caccdb9c7cc0c714c498ee7318047c0d..bc93da7b39d52e525f7488b548d98b4423f6b220 100644 (file)
@@ -7,6 +7,20 @@ This tutorial will walk you through setting up a wiki with ikiwiki.
 If you're using Debian or Ubuntu, ikiwiki is an `apt-get install ikiwiki` away.
 If you're not, see the [[download]] and [[install]] pages.
 
+## Quick start
+
+If you'd like to set up a wiki now, and learn more later, just run this command
+and answer a couple of questions.
+
+       % ikiwiki -setup /etc/ikiwiki/simple.setup
+       What will the wiki be named? mywiki
+       What revision control system to use? git
+
+Wait for it to tell you an url for your new wiki.. Done!
+
+(If the CGI doesn't seem to let you edit pages, you might need to
+[[configure_apache|apache_cgi]]).)
+
 ## Decide where your wiki's files will go.
 
 As a wiki compiler, ikiwiki builds a wiki from files in a source directory,
index c7be9a7f3544331e6142354fde58b47f88f6c46d..7c2e635c88e83e815c9f6dca202d45452edc03a6 100644 (file)
@@ -16,6 +16,7 @@ our $wikiname=IkiWiki::Setup::Automator::ask(
        "What will the wiki be named?", "wiki");
 our $rcs=IkiWiki::Setup::Automator::ask(
        "What revision control system to use?", "git");
+our $hostname=`hostname -f`; chomp $hostname;
 
 IkiWiki::Setup::Automator::import(
        wikiname => $wikiname,
@@ -24,4 +25,16 @@ IkiWiki::Setup::Automator::import(
        destdir => "$ENV{HOME}/public_html/$wikiname",
        repository => "$ENV{HOME}/$wikiname.$rcs",
        setupfile => "$ENV{HOME}/$wikiname.setup",
+       url => "http://$hostname/~$ENV{USER}/$wikiname",
+       cgiurl => "http://$hostname/~$ENV{USER}/$wikiname/ikiwiki.cgi",
+       cgi_wrapper => "$ENV{HOME}/public_html/$wikiname/ikiwiki.cgi",
+       adminemail => "$ENV{USER}\@$hostname",
+       add_plugins => [qw{ goodstuff }],
+       disable_plugins => [qw{  }],
+       libdir => "$ENV{HOME}/.ikiwiki",
+       rss => 1,
+       atom => 1,
+       syslog => 1,
+       prefix_directives => 1,
+       hardlink => 1,
 );