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);
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 my $dir=IkiWiki::dirname($config{$key})."/";
41 my $base=IkiWiki::basename($config{$key});
42 while (-e $dir.$add.$base) {
46 $config{$key}=$dir.$add.$base;
51 if ($config{rcs} eq 'git') {
52 $config{git_wrapper}=$config{repository}."/hooks/post-update";
54 elsif ($config{rcs} eq 'svn') {
55 $config{svn_wrapper}=$config{repository}."/hooks/post-commit";
57 elsif ($config{rcs} eq 'monotone') {
58 $config{mtn_wrapper}=$config{srcdir}."_MTN/ikiwiki-netsync-hook";
60 elsif ($config{rcs} eq 'bzr') {
63 elsif ($config{rcs} eq 'mercurial') {
67 error sprintf(gettext("unsupported revision control system %s"),
72 IkiWiki::checkconfig();
74 print "\n\nSetting up $config{wikiname} ...\n";
76 # Set up the repository.
77 mkpath($config{srcdir}) || die "mkdir $config{srcdir}: $!";
78 delete $config{repository} if ! $config{rcs} || $config{rcs}=~/bzr|mercurial/;
80 my @params=($config{rcs}, $config{srcdir});
81 push @params, $config{repository} if exists $config{repository};
82 if (system("ikiwiki-makerepo", @params) != 0) {
83 error gettext("failed to set up the repository with ikiwiki-makerepo");
87 # Generate setup file.
88 require IkiWiki::Setup;
89 IkiWiki::Setup::dump($config{dumpsetup});
91 # Build the wiki, but w/o wrappers, so it's not live yet.
92 mkpath($config{destdir}) || die "mkdir $config{destdir}: $!";
93 if (system("ikiwiki", "--refresh", "--setup", $config{dumpsetup}) != 0) {
94 die "ikiwiki --refresh --setup $config{dumpsetup} failed";
97 # Create admin user(s).
98 foreach my $admin (@{$config{adminuser}}) {
99 next if $admin=~/^http\?:\/\//; # openid
101 # Prompt for password w/o echo.
102 system('stty -echo 2>/dev/null');
104 print "\n\nCreating wiki admin $admin ...\n";
105 print "Choose a password: ";
106 chomp(my $password=<STDIN>);
108 system('stty sane 2>/dev/null');
110 if (IkiWiki::userinfo_setall($admin, { regdate => time }) &&
111 IkiWiki::Plugin::passwordauth::setpassword($admin, $password)) {
112 IkiWiki::userinfo_set($admin, "email", $config{adminemail}) if defined $config{adminemail};
115 error("problem setting up $admin user");
119 # Add wrappers, make live.
120 if (system("ikiwiki", "--wrappers", "--setup", $config{dumpsetup}) != 0) {
121 die "ikiwiki --wrappers --setup $config{dumpsetup} failed";
124 # Add it to the wikilist.
125 mkpath("$ENV{HOME}/.ikiwiki");
126 open (WIKILIST, ">>$ENV{HOME}/.ikiwiki/wikilist") || die "$ENV{HOME}/.ikiwiki/wikilist: $!";
127 print WIKILIST "$ENV{USER} $config{dumpsetup}\n";
129 if (system("ikiwiki-update-wikilist") != 0) {
130 print STDERR "** Failed to add you to the system wikilist file.\n";
131 print STDERR "** (Probably ikiwiki-update-wikilist is not SUID root.)\n";
132 print STDERR "** Your wiki will not be automatically updated when ikiwiki is upgraded.\n";
136 print "\n\nSuccessfully set up $config{wikiname}:\n";
137 foreach my $key (qw{url srcdir destdir repository}) {
138 next unless exists $config{$key};
139 print "\t$key: ".(" " x (10 - length($key)))." ".
140 prettydir($config{$key})."\n";
142 print "To modify settings, edit ".prettydir($config{dumpsetup})." and then run:\n";
143 print " ikiwiki -setup ".prettydir($config{dumpsetup})."\n";