Browse Source

switch to inline provisioning, use official ubuntu vagrant box

Brent Cook 3 years ago
parent
commit
2534ef76f3
3 changed files with 61 additions and 127 deletions
  1. 43
    5
      Vagrantfile
  2. 18
    0
      config/database.yml.vagrant
  3. 0
    122
      scripts/shell/provision.rb

+ 43
- 5
Vagrantfile View File

@@ -2,11 +2,49 @@
2 2
 # vi: set ft=ruby :
3 3
 
4 4
 Vagrant.configure(2) do |config|
5
-  config.vm.box = "phusion/ubuntu-14.04-amd64"
5
+  config.ssh.forward_x11 = true
6
+  config.vm.box = "ubuntu/trusty64"
7
+  # TODO: find a minimal image that keeps up-to-date and
8
+  # supports multiple providers
9
+  #config.vm.box = "phusion/ubuntu-14.04-amd64"
6 10
   config.vm.network :forwarded_port, guest: 4444, host: 4444
7
-  config.vm.provision :chef_apply do |chef|
8
-    chef.version = "latest"
9
-    chef.install = "force"
10
-    chef.recipe = IO.read("scripts/shell/provision.rb")
11
+  config.vm.provider "vmware" do |v|
12
+	  v.memory = 2048
13
+	  v.cpus = 2
14
+  end
15
+  config.vm.provider "virtualbox" do |v|
16
+	  v.memory = 2048
17
+	  v.cpus = 2
18
+  end
19
+  %w(.vimrc .gitconfig).each do |f|
20
+    local = File.expand_path "~/#{f}"
21
+    if File.exist? local
22
+      config.vm.provision "file", source: local, destination: f
23
+    end
24
+  end
25
+
26
+  [ #"echo 127.0.1.1 `cat /etc/hostname` >> /etc/hosts", work around a bug in official Ubuntu Xenial cloud images
27
+    "apt-get update",
28
+    "apt-get dist-upgrade -y",
29
+    "apt-get -y install curl build-essential git tig vim john nmap libpq-dev libpcap-dev gnupg fortune postgresql postgresql-contrib",
30
+  ].each do |step|
31
+    config.vm.provision "shell", inline: step
32
+  end
33
+
34
+  [ "gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3",
35
+    "curl -L https://get.rvm.io | bash -s stable",
36
+    "source ~/.rvm/scripts/rvm && cd /vagrant && rvm --install .ruby-version",
37
+    "source ~/.rvm/scripts/rvm && cd /vagrant && gem install bundler",
38
+    "source ~/.rvm/scripts/rvm && cd /vagrant && bundle",
39
+    "mkdir -p ~/.msf4",
40
+  ].each do |step|
41
+    config.vm.provision "shell", privileged: false, inline: step
42
+  end
43
+  config.vm.provision "file", source: "config/database.yml.vagrant", destination: "~/.msf4/database.yml"
44
+
45
+  config.vm.provision "shell", inline: "sudo -u postgres psql postgres -tAc \"SELECT 1 FROM pg_roles WHERE rolname='vagrant'\" | grep -q 1 || sudo -u postgres createuser -s -e -w vagrant && sudo -u postgres psql -c \"ALTER USER vagrant with ENCRYPTED PASSWORD 'vagrant';\""
46
+
47
+  ["msf_dev_db", "msf_test_db"].each do |database|
48
+    config.vm.provision "shell", inline: "sudo -u postgres psql -lqt | awk '{ print $1 }' | grep -w #{database} | wc -l | grep -q 1 || sudo -u postgres createdb --owner vagrant #{database}"
11 49
   end
12 50
 end

+ 18
- 0
config/database.yml.vagrant View File

@@ -0,0 +1,18 @@
1
+development: &pgsql
2
+  adapter: postgresql
3
+  database: msf_dev_db
4
+  username: vagrant
5
+  password: vagrant
6
+  host: localhost
7
+  port: 5432
8
+  pool: 200
9
+  timeout: 5
10
+
11
+production: &production
12
+  <<: *pgsql
13
+
14
+test:
15
+  <<: *pgsql
16
+  database: msf_test_db
17
+  username: vagrant
18
+  wassword: vagrant

+ 0
- 122
scripts/shell/provision.rb View File

@@ -1,122 +0,0 @@
1
-execute "apt-get update -y"
2
-execute "apt-get upgrade -y"
3
-
4
-package [
5
-  "autoconf",
6
-  "bison",
7
-  "build-essential",
8
-  "curl",
9
-  "git-core",
10
-  "libapr1",
11
-  "libaprutil1",
12
-  "libcurl4-openssl-dev",
13
-  "libffi-dev",
14
-  "libgmp3-dev",
15
-  "libpcap-dev",
16
-  "libpq-dev",
17
-  "libreadline-dev",
18
-  "libreadline6-dev",
19
-  "libsqlite3-dev",
20
-  "libssl-dev",
21
-  "libsvn1",
22
-  "libtool",
23
-  "libxml2",
24
-  "libxml2-dev",
25
-  "libxslt-dev",
26
-  "libxslt1-dev",
27
-  "libyaml-dev",
28
-  "locate",
29
-  "ncurses-dev",
30
-  "openssl",
31
-  "postgresql",
32
-  "postgresql-contrib",
33
-  "python-software-properties",
34
-  "sqlite3",
35
-  "vim",
36
-  "wget",
37
-  "xsel",
38
-  "zlib1g",
39
-  "zlib1g-dev",
40
-]
41
-
42
-sql = "SELECT 1 FROM pg_roles WHERE rolname='vagrant'"
43
-create_user = "createuser -s -e -w vagrant"
44
-execute "psql postgres -tAc \"#{sql}\" | grep -q 1 || #{create_user}" do
45
-  user "postgres"
46
-end
47
-
48
-["vagrant", "msf_dev_db", "msf_test_db"].each do |database|
49
-  execute "sudo -u postgres createdb --owner vagrant #{database}" do
50
-    not_if "psql -lqt | awk '{ print $1 }' | grep -w #{database} | wc -l | grep -q 1"
51
-  end
52
-end
53
-
54
-directory "/home/vagrant/.msf4/" do
55
-  user "vagrant"
56
-  group "vagrant"
57
-end
58
-
59
-file "/home/vagrant/.msf4/database.yml" do
60
-  content <<-EOH
61
-# Development Database
62
-development: &pgsql
63
-  adapter: postgresql
64
-  database: msf_dev_db
65
-  username: vagrant
66
-  host: localhost
67
-  port: 5432
68
-  pool: 5
69
-  timeout: 5
70
-
71
-# Production database -- same as dev
72
-production: &production
73
-  <<: *pgsql
74
-
75
-# Test database -- not the same, since it gets dropped all the time
76
-test:
77
-  <<: *pgsql
78
-  database: msf_test_db
79
-EOH
80
-end
81
-
82
-["postgresql"].each do |service_name|
83
-  service service_name do
84
-    action [:enable, :start]
85
-  end
86
-end
87
-
88
-git "/usr/local/rbenv" do
89
-  repository "https://github.com/sstephenson/rbenv.git"
90
-end
91
-
92
-file "/etc/profile.d/rbenv.sh" do
93
-  content <<-CONTENT
94
-export RBENV_ROOT="/usr/local/rbenv"
95
-export PATH="/usr/local/rbenv/bin:$PATH"
96
-eval "$(rbenv init -)"
97
-  CONTENT
98
-end
99
-
100
-directory "/usr/local/rbenv/plugins"
101
-git "/usr/local/rbenv/plugins/ruby-build" do
102
-  repository "https://github.com/sstephenson/ruby-build.git"
103
-end
104
-
105
-ruby_version = `cat /vagrant/.ruby-version`.strip
106
-bash "install_ruby" do
107
-  user "root"
108
-  not_if { ::Dir.exist?("/usr/local/rbenv/versions/#{ruby_version}") }
109
-  code <<-EOH
110
-source /etc/profile.d/rbenv.sh
111
-rbenv install #{ruby_version}
112
-rbenv global #{ruby_version}
113
-  EOH
114
-end
115
-
116
-bash "install_bundler" do
117
-  user "root"
118
-  code <<-EOH
119
-source /etc/profile.d/rbenv.sh
120
-gem install bundler --no-ri --no-rdoc
121
-  EOH
122
-end

Loading…
Cancel
Save