-
Notifications
You must be signed in to change notification settings - Fork 2
/
Vagrant.mk
97 lines (79 loc) · 2.72 KB
/
Vagrant.mk
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
# Makefile for make-server/Vagrant
# __ __ _ _
# \ \ / /_ _ __ _ _ __ __ _ _ __ | |_ _ __ ___ | | __
# \ \ / / _` |/ _` | '__/ _` | '_ \| __| | '_ ` _ \| |/ /
# \ V / (_| | (_| | | | (_| | | | | |_ _| | | | | | <
# \_/ \__,_|\__, |_| \__,_|_| |_|\__(_)_| |_| |_|_|\_\
# |___/
# -----------------------------------------------------------------------------
HEREIAM := $(shell pwd)
PWDNAME := $(shell echo $(HEREIAM) | xargs basename)
CURNODE := $(shell echo $(dir $(HEREIAM)) | xargs basename )
MAKEDIR := mkdir -p
.DEFAULT_GOAL := login
MAKESERVERDIR := $(shell head -1 .make-server-directory)
ROOTDIRECTORY := server
VAGRANTCONFIG := Vagrantfile
VAGRANTSCRIPT := script
VAG_INVENTORY := $(ROOTDIRECTORY)/vagrant
MOUNTPOINTDIR := data
VIRTUALBOXDIR := .vagrant
VIRTUALBOXNET := 172.25
SSHCOMMAND := ssh -v42
SECRETKEY := $(VIRTUALBOXDIR)/machines/default/virtualbox/private_key
# -----------------------------------------------------------------------------
.PHONY: clean all
%-box:
- ! test -f ./$(VAGRANTCONFIG)
vagrant init $*
rm -f ./$(VAGRANTCONFIG)
$(MAKE) -f Vagrant.mk $(VAGRANTCONFIG) VIRTUALBOXSET=$*
$(MAKE) -f Vagrant.mk $(VAG_INVENTORY)
$(MAKE) -f Vagrant.mk $(VAGRANTSCRIPT)
$(MAKEDIR) $(MOUNTPOINTDIR)
$(VAG_INVENTORY):
test -f $(VAGRANTCONFIG)
VMIPV4ADDRESS="`$(MAKE) addr`"; \
cat $(MAKESERVERDIR)/$@ | sed \
-e "s/__IPV4ADDRESS__/$$VMIPV4ADDRESS/g" \
-e 's/__OPENSSHPORT__/22/g' \
> $@
$(VAGRANTCONFIG):
O3="`perl -lE 'print int(rand(250)) + 2'`"; \
O4="`perl -lE 'print int(rand(250)) + 2'`"; \
cat $(MAKESERVERDIR)/$@ | sed \
-e 's/__HOSTNAME__/vm.$(CURNODE)/g' \
-e "s/__IPV4ADDRESS__/$(VIRTUALBOXNET).$$O3.$$O4/g" \
-e 's/__VIRTUALBOX__/$(VIRTUALBOXSET)/g' > ./$@
$(VAGRANTSCRIPT):
$(MAKE) -C $@
addr:
@test -f $(VAGRANTCONFIG)
@grep 'private_network' ./$(VAGRANTCONFIG) | sed -e 's/^.*ip://g' | tr -d ' "'
down: $(VAGRANTCONFIG) $(VIRTUALBOXDIR)
vagrant halt
list:
vagrant box list
login:
$(SSHCOMMAND) -l vagrant -i $(SECRETKEY) `$(MAKE) addr`
os:
@test -f $(VAGRANTCONFIG)
@grep 'config.vm.box = ' $(VAGRANTCONFIG) | awk '{ print $$3 }' | tr -d '"'
restart: $(VAGRANTCONFIG) $(VIRTUALBOXDIR)
vagrant reload
ssh:
$(SSHCOMMAND) -l $(DEPLOYUSER) -i $(DEPLOYKEY) `$(MAKE) addr`
up: $(VAGRANTSCRIPT) $(VAGRANTCONFIG)
$(MAKE) -f Vagrant.mk $(VAG_INVENTORY)
$(MAKE) -f Makefile remove-host-key
vagrant up
destroy: $(VAGRANTCONFIG)
vagrant destroy
$(MAKE) -f Makefile remove-host-key
init-vm: $(VAGRANTCONFIG)
$(MAKE) destroy && $(MAKE) up
$(MAKE) init-host INVENTORYFILE=$(ROOTDIRECTORY)/vagrant
clean:
clean-vm:
rm -f ./$(VAGRANTCONFIG) ./$(VAG_INVENTORY)
rm -rf ./$(VIRTUALBOXDIR)