-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
83 lines (65 loc) · 3.21 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# ---------------------------------------------------------------------------
# Copyright 2017, BuzzingPixel, LLC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the Apache License 2.0.
# http://www.apache.org/licenses/LICENSE-2.0
# ---------------------------------------------------------------------------
# Require yaml
require 'yaml'
# Specify Vagrant API version
VAGRANTFILE_API_VERSION ||= "2"
# Specify script paths
vagrantConfig = "scripts/vagrantConfig.yaml"
aliasesPath = "scripts/vagrantAliases"
# Configure Loop
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Specify the vagrant box to use
config.vm.box = "buzzingpixel/phpbrew"
# Load settings from YAML file
yamlConfig = YAML::load(File.read(vagrantConfig))
# Check if aliases file exists
if File.exist? aliasesPath then
config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases"
end
# Create a private network
config.vm.network "private_network", ip: yamlConfig["ipAddress"]
# Example sync directories
# config.vm.synced_folder __dir__ + "/libraries/ExpressionEngine", "/var/www/html", type: "nfs"
# config.vm.synced_folder __dir__ + "/ansel", "/var/www/html/system/user/addons/ansel", type: "nfs"
# config.vm.synced_folder __dir__ + "/ansel_themes", "/var/www/html/themes/user/ansel", type: "nfs"
# Add ssh keys
config.vm.provision "file", source: "#{Dir.home}/.ssh/id_rsa.pub", destination: "/home/vagrant/.ssh/id_rsa.pub"
config.vm.provision "file", source: "#{Dir.home}/.ssh/id_rsa", destination: "/home/vagrant/.ssh/id_rsa"
# Add public key for SSH access
config.vm.provision "shell" do |s|
ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
s.inline = <<-SHELL
sed -i -e "s,. ~/.custom_message,,g" /home/vagrant/.bashrc
echo ". ~/.custom_message" >> /home/vagrant/.bashrc
cp /vagrant/scripts/.custom_message /home/vagrant/.custom_message
echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
chown vagrant:vagrant /home/vagrant/.ssh/id_rsa.pub
chmod 0644 /home/vagrant/.ssh/id_rsa.pub
chmod 0600 /home/vagrant/.ssh/id_rsa
chown vagrant:vagrant /home/vagrant/.ssh/id_rsa
cp /home/vagrant/.ssh/id_rsa.pub /root/.ssh/id_rsa.pub
chown root:root /root/.ssh/id_rsa.pub
chmod 0644 /root/.ssh/id_rsa.pub
cp /home/vagrant/.ssh/id_rsa /root/.ssh/id_rsa
chown root:root /root/.ssh/id_rsa
chmod 0600 /root/.ssh/id_rsa
SHELL
end
# Set the timesync threshold to 5 seconds, instead of the default 20 minutes, and set timesync to run automatically upon wake.
config.vm.provider :virtualbox do |v|
v.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", "5000"]
v.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-start"]
v.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore", "1"]
end
# Run shell script provisioning on first box boot
config.vm.provision :shell, path: "scripts/vagrantProvision.sh"
# Run a script at every boot
config.vm.provision :shell, path: "scripts/vagrantStart.sh", run: "always", privileged: true
end # /Configure Loop