2 # Ikiwiki setup automator.
4 package IkiWiki::Setup::Automator;
14 my ($question, $default)=@_;
16 my $r=Term::ReadLine->new("ikiwiki");
17 $r->readline($question." ", $default);
20 sub prettydir ($) { #{{{
22 $dir=~s/^\Q$ENV{HOME}\E\//~\//;
28 IkiWiki::Setup::merge({@_});
30 # Sanitize this to avoid problimatic directory names.
31 $config{wikiname}=~s/[^-A-Za-z0-9_] //g;
32 if (! length $config{wikiname}) {
33 die "you must enter a wikiname\n";
36 # Avoid overwriting any existing files.
37 foreach my $key (qw{srcdir destdir repository dumpsetup}) {
38 next unless exists $config{$key};
40 while (-e $add.$config{$key}) {
44 $config{$key}=$add.$config{$key};
47 IkiWiki::checkconfig();
49 print "\n\nSetting up $config{wikiname} ...\n";
51 # Set up the repository.
52 mkpath($config{srcdir}) || die "mkdir $config{srcdir}: $!";
53 delete $config{repository} if ! $config{rcs} || $config{rcs}=~/bzr|mercurial/;
55 my @params=($config{rcs}, $config{srcdir});
56 push @params, $config{repository} if exists $config{repository};
57 if (system("ikiwiki-makerepo", @params) != 0) {
58 die "failed: ikiwiki-makerepo @params";
62 # Generate setup file.
63 require IkiWiki::Setup;
65 if ($config{rcs} eq 'git') {
66 $config{git_wrapper}=$config{repository}."/hooks/post-update";
68 elsif ($config{rcs} eq 'svn') {
69 $config{svn_wrapper}=$config{repository}."/hooks/post-commit";
71 elsif ($config{rcs} eq 'bzr') {
74 elsif ($config{rcs} eq 'mercurial') {
78 IkiWiki::Setup::dump($config{dumpsetup});
80 # Build the wiki, but w/o wrappers, so it's not live yet.
81 mkpath($config{destdir}) || die "mkdir $config{destdir}: $!";
82 if (system("ikiwiki", "--refresh", "--setup", $config{dumpsetup}) != 0) {
83 die "ikiwiki --refresh --setup $config{dumpsetup} failed";
86 # Create admin user(s).
87 foreach my $admin (@{$config{adminuser}}) {
88 next if $admin=~/^http\?:\/\//; # openid
90 # Prompt for password w/o echo.
91 system('stty -echo 2>/dev/null');
93 print "\n\nCreating wiki admin $admin ...\n";
94 print "Choose a password: ";
95 chomp(my $password=<STDIN>);
97 system('stty sane 2>/dev/null');
99 if (IkiWiki::userinfo_setall($admin, { regdate => time }) &&
100 IkiWiki::Plugin::passwordauth::setpassword($admin, $password)) {
101 IkiWiki::userinfo_set($admin, "email", $config{adminemail}) if defined $config{adminemail};
104 error("problem setting up $admin user");
108 # Add wrappers, make live.
109 if (system("ikiwiki", "--wrappers", "--setup", $config{dumpsetup}) != 0) {
110 die "ikiwiki --wrappers --setup $config{dumpsetup} failed";
113 # Add it to the wikilist.
114 mkpath("$ENV{HOME}/.ikiwiki");
115 open (WIKILIST, ">>$ENV{HOME}/.ikiwiki/wikilist") || die "$ENV{HOME}/.ikiwiki/wikilist: $!";
116 print WIKILIST "$ENV{USER} $config{dumpsetup}\n";
118 if (system("ikiwiki-update-wikilist") != 0) {
119 print STDERR "** Failed to add you to the system wikilist file.\n";
120 print STDERR "** (Probably ikiwiki-update-wikilist is not SUID root.)\n";
121 print STDERR "** Your wiki will not be automatically updated when ikiwiki is upgraded.\n";
125 print "\n\nSuccessfully set up $config{wikiname}:\n";
126 foreach my $key (qw{url srcdir destdir repository}) {
127 next unless exists $config{$key};
128 print "\t$key: ".(" " x (10 - length($key)))." ".
129 prettydir($config{$key})."\n";
131 print "To modify settings, edit ".prettydir($config{dumpsetup})." and then run:\n";
132 print " ikiwiki -setup ".prettydir($config{dumpsetup})."\n";