diff options
author | Joey Hess <joey@kodama.kitenet.net> | 2008-07-27 01:39:11 -0400 |
---|---|---|
committer | Joey Hess <joey@kodama.kitenet.net> | 2008-07-27 01:39:11 -0400 |
commit | f28b57526ce7a4fe1337dda07533862d918f59b6 (patch) | |
tree | 307ffd6932ee1d82f11061aa56151dd853b2e1a4 /IkiWiki | |
parent | e1f7146041ab7dbbaf045a5da959d9086fbaae50 (diff) | |
download | ikiwiki-f28b57526ce7a4fe1337dda07533862d918f59b6.tar ikiwiki-f28b57526ce7a4fe1337dda07533862d918f59b6.tar.gz |
setup automator
"ikiwiki -setup /etc/ikiwiki/simple.setup"
can be used set up a new wiki in seconds
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/Setup/Automator.pm | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/IkiWiki/Setup/Automator.pm b/IkiWiki/Setup/Automator.pm new file mode 100644 index 000000000..8cf158db2 --- /dev/null +++ b/IkiWiki/Setup/Automator.pm @@ -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 |