diff --git a/actions/ikiwiki b/actions/ikiwiki
index 2720ff539..af7d50540 100755
--- a/actions/ikiwiki
+++ b/actions/ikiwiki
@@ -31,14 +31,97 @@ CONFIG_FILE = '/etc/apache2/conf-available/ikiwiki.conf'
SETUP_WIKI = '/etc/ikiwiki/plinth-wiki.setup'
SETUP_BLOG = '/etc/ikiwiki/plinth-blog.setup'
SITE_PATH = '/var/www/ikiwiki'
-WIKI_PATH = '/var/ikiwiki'
+WIKI_PATH = '/var/lib/ikiwiki'
+apache_cgi_configuration = '''
+Alias /ikiwiki /var/www/ikiwiki
+AddHandler cgi-script .cgi
+
+
+ Options +ExecCGI
+
+'''
+
+ikiwiki_setup_automator = '''
+#!/usr/bin/perl
+# Ikiwiki setup automator for Plinth.
+
+require IkiWiki::Setup::Automator;
+
+our $wikiname=$ARGV[0];
+our $admin=$ARGV[1];
+if (($wikiname eq "") || ($admin eq "")) {
+ print "Usage: ikiwiki -setup /etc/ikiwiki/plinth-wiki.setup wiki_name admin_name";
+ exit;
+}
+
+our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname($wikiname);
+
+IkiWiki::Setup::Automator->import(
+ wikiname => $wikiname,
+ adminuser => [$admin],
+ rcs => "git",
+ srcdir => "/var/lib/ikiwiki/$wikiname_short",
+ destdir => "/var/www/ikiwiki/$wikiname_short",
+ repository => "/var/lib/ikiwiki/$wikiname_short.git",
+ dumpsetup => "/var/lib/ikiwiki/$wikiname_short.setup",
+ url => "/ikiwiki/$wikiname_short",
+ cgiurl => "/ikiwiki/$wikiname_short/ikiwiki.cgi",
+ cgi_wrapper => "/var/www/ikiwiki/$wikiname_short/ikiwiki.cgi",
+ add_plugins => [qw{goodstuff websetup httpauth}],
+ rss => 1,
+ atom => 1,
+ syslog => 1,
+)
+'''
+
+ikiwiki_setup_automator_blog = '''
+#!/usr/bin/perl
+# Ikiwiki setup automator for Plinth (blog version).
+
+require IkiWiki::Setup::Automator;
+
+our $wikiname=$ARGV[0];
+our $admin=$ARGV[1];
+if (($wikiname eq "") || ($admin eq "")) {
+ print "Usage: ikiwiki -setup /etc/ikiwiki/plinth-blog.setup blog_name admin_name";
+ exit;
+}
+
+our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname($wikiname);
+
+IkiWiki::Setup::Automator->import(
+ wikiname => $wikiname,
+ adminuser => [$admin],
+ rcs => "git",
+ srcdir => "/var/lib/ikiwiki/$wikiname_short",
+ destdir => "/var/www/ikiwiki/$wikiname_short",
+ repository => "/var/lib/ikiwiki/$wikiname_short.git",
+ dumpsetup => "/var/lib/ikiwiki/$wikiname_short.setup",
+ url => "/ikiwiki/$wikiname_short",
+ cgiurl => "/ikiwiki/$wikiname_short/ikiwiki.cgi",
+ cgi_wrapper => "/var/www/ikiwiki/$wikiname_short/ikiwiki.cgi",
+ add_plugins => [qw{goodstuff websetup comments calendar sidebar trail httpauth}],
+ rss => 1,
+ atom => 1,
+ syslog => 1,
+ example => "blog",
+ comments_pagespec => "posts/* and !*/Discussion",
+ archive_pagespec => "page(posts/*) and !*/Discussion",
+ global_sidebars => 0,
+ discussion => 0,
+ tagbase => "tags",
+)
+'''
def parse_arguments():
"""Return parsed command line arguments as dictionary."""
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
+ # Setup ikiwiki site
+ subparsers.add_parser('setup', help='Perform first time setup operations')
+
# Get whether ikiwiki site is enabled
subparsers.add_parser('get-enabled',
help='Get whether ikiwiki site is enabled')
@@ -73,6 +156,11 @@ def parse_arguments():
return parser.parse_args()
+def subcommand_setup(_):
+ """Perform first time setup operations."""
+ setup()
+
+
def subcommand_get_enabled(_):
"""Get whether ikiwiki site is enabled."""
if os.path.isfile(CONFIG_ENABLE):
@@ -83,13 +171,8 @@ def subcommand_get_enabled(_):
def subcommand_enable(_):
"""Enable ikiwiki site."""
- if not os.path.isfile(CONFIG_FILE):
- setup()
- subprocess.check_call(['a2enconf', 'ikiwiki'])
- subprocess.check_call(['service', 'apache2', 'restart'])
- else:
- subprocess.check_call(['a2enconf', 'ikiwiki'])
- subprocess.check_call(['service', 'apache2', 'reload'])
+ subprocess.check_call(['a2enconf', 'ikiwiki'])
+ subprocess.check_call(['service', 'apache2', 'reload'])
def subcommand_disable(_):
@@ -141,110 +224,29 @@ def subcommand_delete(arguments):
shutil.rmtree(wiki_folder)
shutil.rmtree(wiki_folder + '.git')
os.remove(wiki_folder + '.setup')
- print('Deleted %s' % arguments.name)
+ print('Deleted {0}'.format(arguments.name))
except FileNotFoundError:
- print('Error: %s not found.' % arguments.name)
+ print('Error: {0} not found.'.format(arguments.name))
exit(1)
def setup():
- """Initial setup"""
+ """Write Apache configuration and wiki/blog setup scripts."""
if not os.path.exists(SITE_PATH):
os.makedirs(SITE_PATH)
subprocess.check_call(['a2enmod', 'cgi'])
with open(CONFIG_FILE, 'w') as conffile:
- conffile.writelines([
- 'Alias /ikiwiki /var/www/ikiwiki\n',
- 'AddHandler cgi-script .cgi\n',
- '\n',
- '\n',
- ' Options +ExecCGI\n',
- '\n'
- ])
+ conffile.write(apache_cgi_configuration)
with open(SETUP_WIKI, 'w') as setupfile:
- setupfile.writelines([
- '#!/usr/bin/perl\n',
- '# Ikiwiki setup automator for Plinth.\n',
- '\n',
- 'require IkiWiki::Setup::Automator;\n',
- '\n',
- 'our $wikiname=$ARGV[0];\n',
- 'our $admin=$ARGV[1];\n',
- 'if (($wikiname eq "") || ($admin eq "")) {\n',
- ' print "Usage: ikiwiki -setup /etc/ikiwiki/plinth-wiki.setup ',
- 'wiki_name admin_name";\n',
- ' exit;\n',
- '}\n',
- '\n',
- 'our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname',
- '($wikiname);\n',
- '\n',
- 'IkiWiki::Setup::Automator->import(\n',
- ' wikiname => $wikiname,\n',
- ' adminuser => [$admin],\n',
- ' rcs => "git",\n',
- ' srcdir => "/var/ikiwiki/$wikiname_short",\n',
- ' destdir => "/var/www/ikiwiki/$wikiname_short",\n',
- ' repository => "/var/ikiwiki/$wikiname_short.git",\n',
- ' dumpsetup => "/var/ikiwiki/$wikiname_short.setup",\n',
- ' url => "/ikiwiki/$wikiname_short",\n',
- ' cgiurl => "/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
- ' cgi_wrapper => "/var/www/ikiwiki/$wikiname_short/ikiwiki.cgi",'
- '\n',
- ' add_plugins => [qw{goodstuff websetup httpauth}],\n',
- ' rss => 1,\n',
- ' atom => 1,\n',
- ' syslog => 1,\n',
- ')\n',
- ])
+ setupfile.writelines(ikiwiki_setup_automator)
with open(SETUP_BLOG, 'w') as setupfile:
- setupfile.writelines([
- '#!/usr/bin/perl\n',
- '# Ikiwiki setup automator for Plinth (blog version).\n',
- '\n',
- 'require IkiWiki::Setup::Automator;\n',
- '\n',
- 'our $wikiname=$ARGV[0];\n',
- 'our $admin=$ARGV[1];\n',
- 'if (($wikiname eq "") || ($admin eq "")) {\n',
- ' print "Usage: ikiwiki -setup /etc/ikiwiki/plinth-blog.setup ',
- 'blog_name admin_name";\n',
- ' exit;\n',
- '}\n',
- '\n',
- 'our $wikiname_short=IkiWiki::Setup::Automator::sanitize_wikiname',
- '($wikiname);\n',
- '\n',
- 'IkiWiki::Setup::Automator->import(\n',
- ' wikiname => $wikiname,\n',
- ' adminuser => [$admin],\n',
- ' rcs => "git",\n',
- ' srcdir => "/var/ikiwiki/$wikiname_short",\n',
- ' destdir => "/var/www/ikiwiki/$wikiname_short",\n',
- ' repository => "/var/ikiwiki/$wikiname_short.git",\n',
- ' dumpsetup => "/var/ikiwiki/$wikiname_short.setup",\n',
- ' url => "/ikiwiki/$wikiname_short",\n',
- ' cgiurl => "/ikiwiki/$wikiname_short/ikiwiki.cgi",\n',
- ' cgi_wrapper => "/var/www/ikiwiki/$wikiname_short/ikiwiki.cgi",'
- '\n',
- ' add_plugins => [qw{goodstuff websetup comments calendar '
- 'sidebar trail httpauth}],\n',
- ' rss => 1,\n',
- ' atom => 1,\n',
- ' syslog => 1,\n',
- '\n',
- ' example => "blog",\n',
- ' comments_pagespec => "posts/* and !*/Discussion",\n',
- ' archive_pagespec => "page(posts/*) and !*/Discussion",\n',
- ' global_sidebars => 0,\n',
- ' discussion => 0,\n',
- ' tagbase => "tags",\n',
- ')\n',
- ])
+ setupfile.writelines(ikiwiki_setup_automator_blog)
+
+ subprocess.check_call(['service', 'apache2', 'restart'])
def main():
diff --git a/plinth/modules/ikiwiki/views.py b/plinth/modules/ikiwiki/views.py
index 43c762af4..0d791f49f 100644
--- a/plinth/modules/ikiwiki/views.py
+++ b/plinth/modules/ikiwiki/views.py
@@ -39,10 +39,16 @@ subsubmenu = [{'url': reverse_lazy('ikiwiki:index'),
'text': _('Create')}]
+def on_install():
+ """Enable Ikiwiki on install."""
+ actions.superuser_run('ikiwiki', ['setup'])
+
+
@login_required
@package.required(['ikiwiki',
'libcgi-formbuilder-perl',
- 'libcgi-session-perl'])
+ 'libcgi-session-perl'],
+ on_install=on_install)
def index(request):
"""Serve configuration page."""
status = get_status()
@@ -163,6 +169,7 @@ def delete(request, name):
messages.success(request, _('%s deleted.') % name)
except actions.ActionError as err:
messages.error(request, _('Could not delete %s: %s') % (name, err))
+
return redirect(reverse_lazy('ikiwiki:manage'))
return TemplateResponse(request, 'ikiwiki_delete.html',