-
Notifications
You must be signed in to change notification settings - Fork 23
/
Vagrantfile
366 lines (272 loc) · 12.8 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# -*- mode: ruby -*-
# vi: set ft=ruby :
$shellinit = <<SHELLINIT
# NOTICE: This script is run as user root
# Fix so that precise64 (which NetArchive Suite uses) maps to right ip
sed -ri 's/127\.0\.1\.1/192.168.0.64/g' /etc/hosts
# Ensure .bashrc ends with a newline...
echo '' >>/home/vagrant/.bashrc
# ...then add shortcut aliases to .bashrc
echo "alias l='ls -G'" >>/home/vagrant/.bashrc
echo "alias ll='ls -lG'" >>/home/vagrant/.bashrc
echo "alias a='ls -AG'" >>/home/vagrant/.bashrc
echo "alias la='ls -lAG'" >>/home/vagrant/.bashrc
echo 'c () { cd "$@"; l; }' >>/home/vagrant/.bashrc
echo "alias b='cd ..; l'" >>/home/vagrant/.bashrc
echo "alias e='vim'" >>/home/vagrant/.bashrc
echo "alias p='less -x4 -i'" >>/home/vagrant/.bashrc
echo "alias t='cat'" >>/home/vagrant/.bashrc
echo "alias gr='grep -E --color=auto'" >>/home/vagrant/.bashrc
echo "alias untgz='tar -xzf'" >>/home/vagrant/.bashrc
echo "alias m='man'" >>/home/vagrant/.bashrc
echo "alias sshte='ssh test@precise64'" >>/home/vagrant/.bashrc
echo '' >>/home/vagrant/.bashrc
# Quick update of apt-get repository
apt-get -q -y update
# Install Vim, answering yes to all questions during installation
apt-get -q -y install vim
# Install unzip
apt-get -q -y install unzip
# Fix timezone
cp /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime
# Install lynx browser
apt-get -q -y install lynx-cur
# Install curl
apt-get -q -y install curl
# Install git
apt-get -q -y install git
# Install postgres
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get --option Dpkg::Options::=--force-confold -q -y install 'postgresql-8.4'
SHELLINIT
$javainstall = <<JAVAINSTALL
# Install java 8
apt-get install -y python-software-properties
add-apt-repository -y ppa:webupd8team/java
apt-get update > /dev/null
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
apt-get install -qq -y oracle-java8-installer oracle-java8-set-default
echo 'export JAVA_HOME=/usr/lib/jvm/java-8-oracle/' >>/home/vagrant/.bashrc
JAVAINSTALL
$testuserssh = <<TESTUSERSSH
# Create an extra user called 'test' and create it's home dir (-m)
useradd -m test -s /bin/bash
# Ensure .bashrc ends with a newline...
echo '' >>/home/test/.bashrc
# ...then add shortcut aliases to .bashrc
echo "alias l='ls -G'" >>/home/test/.bashrc
echo "alias ll='ls -lG'" >>/home/test/.bashrc
echo "alias a='ls -AG'" >>/home/test/.bashrc
echo "alias la='ls -lAG'" >>/home/test/.bashrc
echo 'c () { cd "$@"; l; }' >>/home/test/.bashrc
echo "alias b='cd ..; l'" >>/home/test/.bashrc
echo "alias e='vim'" >>/home/test/.bashrc
echo "alias p='less -x4 -i'" >>/home/test/.bashrc
echo "alias t='cat'" >>/home/test/.bashrc
echo "alias gr='grep -E --color=auto'" >>/home/test/.bashrc
echo "alias untgz='tar -xzf'" >>/home/test/.bashrc
echo "alias m='man'" >>/home/test/.bashrc
echo '' >>/home/test/.bashrc
# Enable ssh-access from user vagrant to user test
# Generate ssh-key with empty passphrase for 'vagrant' user
ssh-keygen -t rsa -N '' -f '/home/vagrant/.ssh/id_rsa'
chown -R vagrant:vagrant /home/vagrant/.ssh
mkdir /home/test/.ssh
cat /home/vagrant/.ssh/id_rsa.pub >>/home/test/.ssh/authorized_keys
chown -R test:test /home/test/.ssh
chmod 700 /home/test/.ssh
# Run command ssh as user vagrant, from vagrant user's home dir, and
# without asking for a 'yes' upon login, ssh running the dummy true cmd
# (this is to get rid of the yes/no question for later ssh'ings)
su - vagrant -c 'ssh -oStrictHostKeyChecking=no test@precise64 true'
su - vagrant -c 'ssh -oStrictHostKeyChecking=no test@localhost true'
mkdir /root/.ssh
# Enable ssh-access from user root to user test
# Generate ssh-key with empty passphrase for 'root' user
echo $'\n' | ssh-keygen -t rsa -N ''
cat /root/.ssh/id_rsa.pub >>/home/test/.ssh/authorized_keys
# Run command ssh as user root, from root user's home dir, and
# without asking for a 'yes' upon login, ssh running the dummy true cmd
# (this is to get rid of the yes/no question for later ssh'ings)
ssh -v -oStrictHostKeyChecking=no test@precise64 true
ssh -v -oStrictHostKeyChecking=no test@localhost true
TESTUSERSSH
$netarchiveinstall = <<NETARCHIVEINSTALL
cd /home/vagrant
mkdir netarchive
cd netarchive
# Netarchive: Setup JMS (Java Messaging Service)
# Download openmq installation script
wget -N https://raw.githubusercontent.com/netarchivesuite/netarchivesuite/master/deploy/deploy-core/scripts/openmq/mq.sh
chmod +x mq.sh
# Install the openmq broker (to ~/MessageQueue5.1) and start it
./mq.sh install
./mq.sh start
cd /vagrant
# Netarchive: Download NetarchiveSuite, latest release
wget -N -O NetarchiveSuite.zip https://sbforge.org/nexus/service/local/repositories/releases/content/org/netarchivesuite/distribution/5.2/distribution-5.2.zip
# Netarchive: Download latest bundles harvester
wget -N -O NetarchiveSuite-heritrix3-bundler.zip https://sbforge.org/nexus/service/local/repositories/releases/content/org/netarchivesuite/heritrix3-bundler/5.2/heritrix3-bundler-5.2.zip
cd /home/vagrant/netarchive
# Netarchive: Download deploy_standalone_vagrant_example and
# RunNetarchiveSuite
wget -N https://raw.githubusercontent.com/netarchivesuite/netarchivesuite/for-vagrant-quickstart/deploy/distribution/src/main/resources/examples/deploy_standalone_vagrant_example.xml
wget -N https://raw.githubusercontent.com/netarchivesuite/netarchivesuite/master/deploy/deploy-core/scripts/RunNetarchiveSuite.sh
chmod +x RunNetarchiveSuite.sh
cp /vagrant/NetarchiveSuite.zip ./
cp /vagrant/NetarchiveSuite-heritrix3-bundler.zip ./
# Before deploying Netarchive...
mkdir -p /home/vagrant/tmp
# Extract sql-init-file for database from NetarchiveSuite zip-file
unzip -j /home/vagrant/netarchive/NetarchiveSuite.zip scripts/postgresql/netarchivesuite_init.sql -d /home/vagrant/tmp/
unzip -j /home/vagrant/netarchive/NetarchiveSuite.zip scripts/sql/createArchiveDB.pgsql -d /home/vagrant/tmp/
# Copy in testdata
cp /vagrant/harvestdb.testdata.sql /home/vagrant/tmp/
NETARCHIVEINSTALL
$postgressetup = <<POSTGRESSETUP
PG_DATA=/var/lib/postgresql/8.4/main
sudo mkdir $PG_DATA/tsindex
sudo chown postgres:postgres $PG_DATA/tsindex
# Start psql
#psql -U postgres -W
echo "Vagrantfile: postgressetup - create roles'n'databases..."
# As user 'postgres', do..
sudo -i -u postgres <<END
# Create database-user called devel, with proper privileges
psql <<CREATEUSEREND
CREATE TABLESPACE tsindex
LOCATION '/var/lib/postgresql/8.4/main/tsindex';
GRANT ALL ON TABLESPACE tsindex TO PUBLIC;
CREATE ROLE "devel" LOGIN PASSWORD 'develpass'
NOINHERIT CREATEDB
VALID UNTIL 'infinity';
CREATE DATABASE "harvestdb"
WITH
TEMPLATE=template0
ENCODING='SQL_ASCII'
OWNER="devel";
CREATE DATABASE "admindb"
WITH
TEMPLATE=template0
ENCODING='SQL_ASCII'
OWNER="devel";
CREATE ROLE "netarchivesuite" LOGIN PASSWORD 'netarchivesuitepass'
NOINHERIT CREATEDB
VALID UNTIL 'infinity';
CREATEUSEREND
# Insert "host harvestdb devel 0.0.0.0/0 md5"
# in file /etc/postgresql/8.4/main/pg_hba.conf below
# '# IPv4 local connections:'
sed -r "/# IPv4 local connections:/a\\
host harvestdb devel 0.0.0.0/0 md5" \\
/etc/postgresql/8.4/main/pg_hba.conf \\
>/tmp/vagrantfilepghbaconfmidlertidigTMP.txt
mv /tmp/vagrantfilepghbaconfmidlertidigTMP.txt \\
/etc/postgresql/8.4/main/pg_hba.conf
# Restart postgres server
service postgresql restart
# Provide password to psql
echo 'localhost:5432:harvestdb:devel:develpass'$'\n' >~/.pgpass
echo 'localhost:5432:admindb:devel:develpass'$'\n' >>~/.pgpass
chmod 0600 ~/.pgpass
echo "Vagrantfile: postgressetup - init netarchivesuite..."
# Create, init, populate harvest database
psql -h localhost -U devel -d harvestdb \\
</home/vagrant/tmp/netarchivesuite_init.sql
echo "Vagrantfile: postgressetup - do harvestdb.testdata..."
psql -h localhost -U devel -d harvestdb \\
</home/vagrant/tmp/harvestdb.testdata.sql
echo "Vagrantfile: postgressetup - init/populate admin db..."
# Create, init, populate admin database
psql -h localhost -U devel -d admindb \\
</home/vagrant/tmp/createArchiveDB.pgsql
# TODO...
echo "Vagrantfile: postgressetup - done"
END
POSTGRESSETUP
$netarchivedeploy = <<NETARCHIVEDEPLOY
# Netarchive: Deploy
cd /home/vagrant/netarchive
./RunNetarchiveSuite.sh NetarchiveSuite.zip deploy_standalone_vagrant_example.xml deploy NetarchiveSuite-heritrix3-bundler.zip
/sbin/ifconfig
# For convenience of testing in Firefox, extract and report the IP-addy
echo 'You can now TEST the NetarchiveSuite installation in a browser with:'
echo http://`/sbin/ifconfig eth1 | grep -Eo 'inet addr:([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})'|cut -s -d":" -f 2| tr -d '[:space:]'`:8074/HarvestDefinition/
NETARCHIVEDEPLOY
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/precise64"
#config.vm.box_version = "1.1.0"
# These network things are nessesary to make ubuntu work fast
config.vm.network :public_network, :nictype => 'virtio', :type => "dhcp", :use_dhcp_assigned_default_route => true
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
#
# In Firefox, we want to access the Net Archive Suite Main menu on
# http://192.168.0.64:8074/HarvestDefinition/
# ... how to make this work? TODO
#
#config.vm.network "forwarded_port", guest: 8074, host: 8074
#config.vm.network "forwarded_port", guest: 8070, host: 8070
#config.vm.network "forwarded_port", guest_ip: "127.0.1.1", guest: 8192, host: 8192
# Create a private network, which allows host-only access to the machine
# using a specific IP.
#config.vm.network "private_network", ip: "192.168.0.64", auto_config: false
#config.vm.provision 'shell', inline: "ifconfig eth1 192.168.0.64"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
#config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# As of November 2016, a memory setting of 1024 is needed for NAS,
# if less than 1024 is used, NetArchive Suite will not start
vb.memory = "1024"
end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push
# strategies such as FTP and Heroku are also available. See the
# documentation at https://docs.vagrantup.com/v2/push/atlas.html for more
# information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see
# the documentation for more information about their specific syntax and
# use.
config.vm.provision "shell", inline: $shellinit, name: "shellinit"
config.vm.provision "shell", inline: $javainstall, name: "javainstall"
config.vm.provision "shell", inline: $testuserssh, name: "testuserssh"
config.vm.provision "shell", inline: $netarchiveinstall, name: "netarchiveinstall"
config.vm.provision "shell", inline: $postgressetup, name: "postgressetup"
config.vm.provision "shell", inline: $netarchivedeploy, name: "netarchivedeploy"
end