-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathinstall-ansible-aix-support.sh
executable file
·67 lines (58 loc) · 2.27 KB
/
install-ansible-aix-support.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
#!/bin/bash
#
# Ansible AIX support installation script
#
echo "Starting installation of Ansible AIX support"
echo ""
if [ "$(uname)" != "Linux" ]; then
echo "[WARNING] Ansible AIX support is tested only on Linux and this scripts can fail."
echo -e " Press enter to continue or Ctrl+C to cancel it."
read continue
fi
if [ "$(whoami)" != "root" ];then
echo "[ERROR] You need to be root to install it"
exit 1
fi
echo "[INFO] Checking Ansible installation."
ansible_data=$(ansible --version)
if [ $? -ne 0 ]; then
echo "[ERROR] Ansible not found."
exit 1
fi
echo "[INFO] Ansible found."
echo "[INFO] Checking Ansible installation"
ansible_version=$(echo ${ansible_data} | awk '{ print $2 }' | awk -F"." '{ print $1"."$2 }')
if [ "${ansible_version}" != "2.4" ]; then
echo "[WARNING] Ansible AIX support is tested with Ansible 2.4, you have version ${ansible_version}"
echo -e " Press enter to continue or Ctrl+C to cancel."
read continue
fi
echo "[INFO] Version compatible."
if [ ! -d lib/ ]; then
echo "[ERROR] Directory lib not found. Are you in the Ansible AIX support dir?"
exit 1
fi
ansible_lib_path=$(echo ${ansible_data} | awk -F "ansible python module location =" '{ print $2 }' | awk '{ print $1 }')
for file in $(find lib/ | grep .py); do
destination_file_path=$(echo ${file} | awk -F 'ansible' '{ print $2 }')
if [ -f ${ansible_lib_path}${destination_file_path} ]; then
check_diff=$(diff ${file} ${ansible_lib_path}${destination_file_path} > /dev/null 2>&1)
if [ $? -ne 0 ]; then
if [ ! -d backup ]; then
echo "[INFO] Creating backup directory"
mkdir backup
fi
echo "[INFO] Saving backup file ${ansible_lib_path}${destination_file_path}"
cp ${ansible_lib_path}${destination_file_path} backup/$(echo $file | awk -F "/" '{ print $NF }')_$(date "+%m%d%H%M%Y.%S")
echo "[INFO] Adding ${ansible_lib_path}${destination_file_path}"
cp ${file} ${ansible_lib_path}${destination_file_path}
else
echo "[INFO] No update required: ${ansible_lib_path}${destination_file_path}"
fi
else
echo "[INFO] Adding ${ansible_lib_path}${destination_file_path}"
cp ${file} ${ansible_lib_path}${destination_file_path}
fi
done
echo "[INFO] Finished."
echo