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 'monotone') {
56 $config{mtn_wrapper}=$config{srcdir}."_MTN/ikiwiki-netsync-hook";
58 elsif ($config{rcs} eq 'bzr') {
61 elsif ($config{rcs} eq 'mercurial') {
65 error sprintf(gettext("unsupported revision control system %s"),
70 IkiWiki::checkconfig();
72 print "\n\nSetting up $config{wikiname} ...\n";
74 # Set up the repository.
75 mkpath($config{srcdir}) || die "mkdir $config{srcdir}: $!";
76 delete $config{repository} if ! $config{rcs} || $config{rcs}=~/bzr|mercurial/;
78 my @params=($config{rcs}, $config{srcdir});
79 push @params, $config{repository} if exists $config{repository};
80 if (system("ikiwiki-makerepo", @params) != 0) {
81 error gettext("failed to set up the repository with ikiwiki-makerepo");
85 # Generate setup file.
86 require IkiWiki::Setup;
87 IkiWiki::Setup::dump($config{dumpsetup});
89 # Build the wiki, but w/o wrappers, so it's not live yet.
90 mkpath($config{destdir}) || die "mkdir $config{destdir}: $!";
91 if (system("ikiwiki", "--refresh", "--setup", $config{dumpsetup}) != 0) {
92 die "ikiwiki --refresh --setup $config{dumpsetup} failed";
95 # Create admin user(s).
96 foreach my $admin (@{$config{adminuser}}) {
97 next if $admin=~/^http\?:\/\//; # openid
99 # Prompt for password w/o echo.
100 system('stty -echo 2>/dev/null');
102 print "\n\nCreating wiki admin $admin ...\n";
103 print "Choose a password: ";
104 chomp(my $password=<STDIN>);
106 system('stty sane 2>/dev/null');
108 if (IkiWiki::userinfo_setall($admin, { regdate => time }) &&
109 IkiWiki::Plugin::passwordauth::setpassword($admin, $password)) {
110 IkiWiki::userinfo_set($admin, "email", $config{adminemail}) if defined $config{adminemail};
113 error("problem setting up $admin user");
117 # Add wrappers, make live.
118 if (system("ikiwiki", "--wrappers", "--setup", $config{dumpsetup}) != 0) {
119 die "ikiwiki --wrappers --setup $config{dumpsetup} failed";
122 # Add it to the wikilist.
123 mkpath("$ENV{HOME}/.ikiwiki");
124 open (WIKILIST, ">>$ENV{HOME}/.ikiwiki/wikilist") || die "$ENV{HOME}/.ikiwiki/wikilist: $!";
125 print WIKILIST "$ENV{USER} $config{dumpsetup}\n";
127 if (system("ikiwiki-update-wikilist") != 0) {
128 print STDERR "** Failed to add you to the system wikilist file.\n";
129 print STDERR "** (Probably ikiwiki-update-wikilist is not SUID root.)\n";
130 print STDERR "** Your wiki will not be automatically updated when ikiwiki is upgraded.\n";
134 print "\n\nSuccessfully set up $config{wikiname}:\n";
135 foreach my $key (qw{url srcdir destdir repository}) {
136 next unless exists $config{$key};
137 print "\t$key: ".(" " x (10 - length($key)))." ".
138 prettydir($config{$key})."\n";
140 print "To modify settings, edit ".prettydir($config{dumpsetup})." and then run:\n";
141 print " ikiwiki -setup ".prettydir($config{dumpsetup})."\n";