1# -*- mode: ruby -*-
2# vi: set ft=ruby :
3
4# Configuration
5# ----------------------------------------------------------------------
6# Where to put DokuWiki - if you change this, search the _vagrant
7# directory for other occurrences!
8dw_path = "/var/www/html"
9# Choose any email you wish for testing; empty becomes mail@example.com
10dw_admin_email = ""
11# Choose an admin password; empty becomes "CHANGEME"
12dw_admin_pass = ""
13# Which plugins to install before configuring this plugin
14dw_extensions = "dev sqlite struct"
15# What number to add to port numbers for testing
16vb_port_base = 20000
17
18# Calculated configuration
19# ----------------------------------------------------------------------
20# This is a very BASh-like use of variables - there's probably a better
21# way to do it in Ruby.
22dw_admin_email = "mail@example.com" if "#{dw_admin_email}" == ""
23dw_admin_pass = "CHANGEME" if "#{dw_admin_pass}" == ""
24
25# Plugin name
26cwd = File.dirname(__FILE__)
27dw_plugin = File.basename(File.dirname(cwd))
28
29# Virtual machine
30# ----------------------------------------------------------------------
31Vagrant.configure("2") do |config|
32
33	# Base image
34	config.vm.box = "bento/ubuntu-20.04"
35
36	# VirtualBox customisation
37	config.vm.provider "virtualbox" do |vb|
38		vb.name = "#{dw_plugin}-web"
39	end
40
41	# Networking
42	config.vm.hostname = "web"
43	config.vm.network "forwarded_port", guest: 22,  host: vb_port_base + 22,  auto_correct: true, id: 'ssh'
44	config.vm.network "forwarded_port", guest: 80,  host: vb_port_base + 80,  auto_correct: true
45	config.vm.network "forwarded_port", guest: 443, host: vb_port_base + 443, auto_correct: true
46
47	# Synced folders
48	config.vm.synced_folder "www", dw_path, :mount_options => ["dmode=777", "fmode=666"]
49	config.vm.synced_folder "..", "#{dw_path}/lib/plugins/#{dw_plugin}", :mount_options => ["dmode=777", "fmode=666"]
50
51	# Fix https://github.com/mitchellh/vagrant/issues/1673
52	# Thanks to http://foo-o-rama.com/vagrant--stdin-is-not-a-tty--fix.html
53	config.vm.provision "fix-no-tty", type: "shell" do |shell|
54		shell.privileged = false
55		shell.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
56	end
57
58	# Provisioning web server
59	config.vm.provision "web-server", type: "shell" do |shell|
60		shell.path = "provision_web_server.sh"
61	end
62
63	# Provisioning DokuWiki
64	config.vm.provision "dokuwiki", type: "shell" do |shell|
65		shell.path = "provision_dokuwiki.sh"
66		shell.env  = {
67			"DW_DOWNLOAD"    => "https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz",
68			"DW_PACKAGE"     => "dokuwiki-stable.tgz",
69			"DW_PATH"        => dw_path,
70			"DW_TITLE"       => dw_plugin,
71			"DW_ADMIN_EMAIL" => dw_admin_email,
72			"DW_ADMIN_PASS"  => dw_admin_pass
73		}
74	end
75	config.vm.provision "dependencies", type: "shell" do |shell|
76		shell.path = "install_dokuwiki_extension.sh"
77		shell.env  = {
78			"DW_PATH"       => dw_path,
79			"DW_EXTENSIONS" => dw_extensions
80		}
81	end
82	config.vm.provision "plugin", type: "shell" do |shell|
83		shell.path = "configure_dw-#{dw_plugin}.sh"
84		shell.env  = {
85			"DW_PATH"        => dw_path
86		}
87	end
88
89	# Final message
90	config.vm.post_up_message = "DokuWiki should be available at:
91  http://localhost:#{vb_port_base + 80}
92  Username: admin
93  Password: #{dw_admin_pass}
94N.B.: If Vagrant had to autocorrect a port collision, the correct port
95will be near the top of the output after running `vagrant up`.
96"
97
98	# # Clean up from outside the VM on non-Windows hosts
99	# config.trigger.after :destroy do
100	# 	info "Cleaning up DokuWiki installation, but preserving #{dw_plugin}..."
101	# 	if Vagrant::Util::Platform.windows?
102	# 		info "========================================================================"
103	# 		info "On Windows hosts the virtual machine should be running for this step."
104	# 		info "If Vagrant reports that it's not yet ready for SSH, either start the"
105	# 		info "virtual machine or remove the DokuWiki files around the plugin manually."
106	# 		info "========================================================================"
107	# 		run_remote "/vagrant/deprovision_dokuwiki_from_but_protect.sh #{dw_path} lib/plugins/#{dw_plugin}"
108	# 	else
109	# 		run "deprovision_dokuwiki_from_but_protect.sh www lib/plugins/#{dw_plugin}"
110	# 	end
111	# end
112end
113