-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·129 lines (110 loc) · 2.83 KB
/
install.sh
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
#!/bin/bash
set -u -e
# workaround for https://github.com/ansible/ansible-modules-core/issues/3706
# (fixed in Ansible 2.1.1).
# joshualund.golang role fails without this
export LANG=C
export LC_ALL=C
unset LANGUAGE
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
k8s_repo_url=
ansible_via_docker=
target_hostname=
provider_args=
vm_type=libvirt
USE_VIRTUALBOX="${USE_VIRTUALBOX:-}"
export ANSIBLE_ROLES_PATH=$script_dir/provisioning/roles
if [ $# -gt 0 ]; then
if [ "$1" = "-d" ]; then
ansible_via_docker=y
shift
fi
fi
if [ $# -eq 0 ]; then
usage
fi
cmd="$1"
shift
if [ "$cmd" = "remote" ]; then
if [ $# -eq 0 ]; then
echo "must specify target hostname" 1>& 2
fi
target_hostname="$1"
shift
fi
k8s_repo_url=
if [ $# -gt 0 ]; then
k8s_repo_url="$1"
fi
if [[ "$OSTYPE" == darwin* && "$cmd" != "remote" ]]; then
export USE_VIRTUALBOX=1
else
export VAGRANT_DEFAULT_PROVIDER=libvirt
provider_args="--provider=libvirt"
fi
if [ -n "$USE_VIRTUALBOX" ]; then
vm_type=virtualbox
fi
function install_roles {
mkdir -p $ANSIBLE_ROLES_PATH
ansible-galaxy install -r requirements.yml
}
function usage {
echo "usage:" 1>&2
echo " $0 vagrant [K8S_REPO_URL]"
echo " $0 host"
echo " $0 local [K8S_REPO_URL]"
echo " $0 remote HOST [K8S_REPO_URL]"
exit 1
}
function install_using_vagrant {
# https://kushaldas.in/posts/storage-volume-error-in-libvirt-with-vagrant.html
# FIXME: happens too often for me for some reason
virsh pool-refresh tmp >& /dev/null || true
K8S_REPO_URL=$k8s_repo_url vagrant up $provider_args
}
function provision_vm_host {
ansible-playbook -i localhost, -c local --ask-sudo-pass \
-e "devbox_type=vm_host vm_type=$vm_type" provisioning/playbook.yml
}
function install_via_ansible {
conn_opts="$*"
install_roles
extra_vars="devbox_type=host vm_type=$vm_type"
if [ -n "$k8s_repo_url" ]; then
extra_vars="$extra_vars k8s_repo_url=$k8s_repo_url"
fi
ansible-playbook $conn_opts --ask-sudo-pass \
-e "$extra_vars" provisioning/playbook.yml
}
function install_locally {
install_via_ansible -i localhost, -c local
}
function install_remotely {
install_via_ansible -i "$target_hostname", --ssh-extra-args="-oForwardAgent=yes"
}
if ! hash ansible-playbook 2>&1; then
ansible_via_docker=y
fi
if [ -n "$ansible_via_docker" ]; then
echo "WiP: ansible invocation via docker doesn't work currently for vagrant due to ssh & file perm problems" 1>& 2
exit 1
# export PATH="$script_dir/ansible-via-docker:$PATH"
fi
case "$cmd" in
vagrant)
install_using_vagrant
;;
host)
provision_vm_host
;;
local)
install_locally
;;
remote)
install_remotely
;;
*)
usage
;;
esac