-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
common.sh
68 lines (58 loc) · 1.5 KB
/
common.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
function check_os ()
{
apt --version &> /dev/null && export PKG_MGR='apt' || export PKG_MGR='dnf'
}
function check_sudo ()
{
CAN_SUDO=0
sudo --version > /dev/null 2>&1 && CAN_SUDO=1
if [ ${CAN_SUDO} -ne 1 ]
then
RUNNER=$(id --user)
if [ ${RUNNER} -ne 0 ]
then
echo "Error! You are not root and sudo is unavailable!"
exit 1
else
"${PKG_MGR}" -y -q install sudo > /dev/null
fi
fi
}
function check_epel ()
{
FEDORA=0
grep 'ID=fedora' /etc/os-release > /dev/null && FEDORA=1 || true
if [ "${FEDORA}" -ne 1 ] && [ "${PKG_MGR}" != 'apt' ]
then
sudo "${PKG_MGR}" -y -q install epel-release > /dev/null
fi
}
function install_ansible ()
{
if [ "${PKG_MGR}" == 'apt' ]
then
sudo "${PKG_MGR}" -y -q install software-properties-common > /dev/null
sudo add-apt-repository -y ppa:ansible/ansible > /dev/null
fi
sudo DEBIAN_FRONTEND=noninteractive "${PKG_MGR}" -y -q install ansible > /dev/null
ansible-galaxy install --force -r requirements.yml
}
function find_ip ()
{
if [ "${PKG_MGR}" == 'apt' ]
then
IP_PKG='iproute2'
else
IP_PKG='iproute'
fi
sudo DEBIAN_FRONTEND=noninteractive "${PKG_MGR}" -y -q install "${IP_PKG}" > /dev/null
export IP_ADDR=$(ip -4 a s | grep inet | grep -v '127\.0\.0' | awk '{print $2}' | cut -d'/' -f1)
}
function init_klf ()
{
check_os
check_sudo
check_epel
install_ansible
find_ip
}