-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathvm
executable file
·85 lines (79 loc) · 2.56 KB
/
vm
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
#!/usr/bin/env bash
# pretty print things witch color!
pretty() {
# first arg is one of [info, warn, error]
case $1 in
"info") COLOR="\e[1;34m" ;; # blue
"warn") COLOR="\e[1;33m" ;; # yellow
"error") COLOR="\e[1;31m" ;; # red
*) COLOR="\e[1;34m" ;; # blue
esac
# print second arg
printf "$COLOR[VM SCRIPT]:: $2 ::"
printf "\e[0m"
echo
}
# Switch over actions
case $1 in
"up")
pretty "info" "Checking existing snapshots"
if [[ $(vagrant snapshot list) == *vanilla* ]]; then
pretty "info" "Vanilla snapshot found. Running [vagrant up]"
vagrant up
else
pretty "info" "Vanilla snapshot not found. Creating new VM"
vagrant up --no-provision
pretty "info" "Creating [vanilla] snapshot of the VM"
vagrant snapshot save vanilla
pretty "info" "Provisioning VM"
ANSIBLE_STDOUT_CALLBACK=debug
vagrant provision
fi
;;
"destroy")
pretty "info" "Destroying VM"
vagrant destroy
;;
"provision")
pretty "info" "Provisioning VM"
vagrant provision
;;
"vanilla")
pretty "info" "Restoring vanilla snapshot [no provisioning]"
pretty "info" "After restore, run [vagrant provision] to provision VM"
vagrant snapshot restore vanilla --no-provision
eval $INSTALL_PACKGE
;;
"recreate")
pretty "info" "Attempting to restore vanilla snapshot"
if [[ $(vagrant snapshot list) == *vanilla* ]]; then
pretty "info" "Vanilla snapshot exists, restoring and provisioning"
vagrant snapshot restore vanilla
else
pretty "info" "Vanilla snapshot not found. Creating new VM [./vm up]"
./vm up
fi
;;
"help")
echo "
A helper script to run usefull vagrant commands
Usage: ./vm [action]
actions:
help........You're looking at it.
up..........Create VM, take vanilla snapshot* then provison.
destroy.....Runs: [vagrant destroy].
provision...Runs [vagrant provision]
vanilla.....Restores vanilla snapshot but does not provision it.
recreate....Restore vanilla snapshot and provision it
If snapshot does not exist, run [./vm provision].
*Vanilla snapshot: This is a VM snapshot taken when [./vm up] is
first run and before provisioning. This means
that vanilla snapshot has no AEM or anything
else installed. Hence, vanilla.
"
;;
*)
pretty "error" "oops only allowed arguments are: [help, up, destroy, provision, vanilla, recreate]"
exit 1
;;
esac