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 error gettext("you must enter a wikiname (that contains alphanumerics)");
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};
49 if ($config{rcs} eq 'git') {
50 $config{git_wrapper}=$config{repository}."/hooks/post-update";
52 elsif ($config{rcs} eq 'svn') {
53 $config{svn_wrapper}=$config{repository}."/hooks/post-commit";
55 elsif ($config{rcs} eq 'bzr') {
58 elsif ($config{rcs} eq 'mercurial') {
62 error sprintf(gettext("unsupported revision control system %s"),
67 IkiWiki::checkconfig();
69 print "\n\nSetting up $config{wikiname} ...\n";
71 # Set up the repository.
72 mkpath($config{srcdir}) || die "mkdir $config{srcdir}: $!";
73 delete $config{repository} if ! $config{rcs} || $config{rcs}=~/bzr|mercurial/;
75 my @params=($config{rcs}, $config{srcdir});
76 push @params, $config{repository} if exists $config{repository};
77 if (system("ikiwiki-makerepo", @params) != 0) {
78 error gettext("failed to set up the repository with ikiwiki-makerepo");
82 # Generate setup file.
83 require IkiWiki::Setup;
84 IkiWiki::Setup::dump($config{dumpsetup});
86 # Build the wiki, but w/o wrappers, so it's not live yet.
87 mkpath($config{destdir}) || die "mkdir $config{destdir}: $!";
88 if (system("ikiwiki", "--refresh", "--setup", $config{dumpsetup}) != 0) {
89 die "ikiwiki --refresh --setup $config{dumpsetup} failed";
92 # Create admin user(s).
93 foreach my $admin (@{$config{adminuser}}) {
94 next if $admin=~/^http\?:\/\//; # openid
96 # Prompt for password w/o echo.
97 system('stty -echo 2>/dev/null');
99 print "\n\nCreating wiki admin $admin ...\n";
100 print "Choose a password: ";
101 chomp(my $password=<STDIN>);
103 system('stty sane 2>/dev/null');
105 if (IkiWiki::userinfo_setall($admin, { regdate => time }) &&
106 IkiWiki::Plugin::passwordauth::setpassword($admin, $password)) {
107 IkiWiki::userinfo_set($admin, "email", $config{adminemail}) if defined $config{adminemail};
110 error("problem setting up $admin user");
114 # Add wrappers, make live.
115 if (system("ikiwiki", "--wrappers", "--setup", $config{dumpsetup}) != 0) {
116 die "ikiwiki --wrappers --setup $config{dumpsetup} failed";
119 # Add it to the wikilist.
120 mkpath("$ENV{HOME}/.ikiwiki");
121 open (WIKILIST, ">>$ENV{HOME}/.ikiwiki/wikilist") || die "$ENV{HOME}/.ikiwiki/wikilist: $!";
122 print WIKILIST "$ENV{USER} $config{dumpsetup}\n";
124 if (system("ikiwiki-update-wikilist") != 0) {
125 print STDERR "** Failed to add you to the system wikilist file.\n";
126 print STDERR "** (Probably ikiwiki-update-wikilist is not SUID root.)\n";
127 print STDERR "** Your wiki will not be automatically updated when ikiwiki is upgraded.\n";
131 print "\n\nSuccessfully set up $config{wikiname}:\n";
132 foreach my $key (qw{url srcdir destdir repository}) {
133 next unless exists $config{$key};
134 print "\t$key: ".(" " x (10 - length($key)))." ".
135 prettydir($config{$key})."\n";
137 print "To modify settings, edit ".prettydir($config{dumpsetup})." and then run:\n";
138 print " ikiwiki -setup ".prettydir($config{dumpsetup})."\n";