#!/bin/bash PACKAGE_PYTHON="python3.11" PACKAGE_RSYNC="rsync" INSTALL_LOCALREPO=true INSTALL_PYTHON=true INSTALL_ANSIBLE=true INSTALL_COLLECTION=true INSTALL_RSYNC=true LANG=en_US.UTF-8 function _localrepo() { echo -e "\033[33mlocalrepo install start!\033[0m" yum config-manager --add-repo file://$PWD/kubespray/roles/exem-infra/files/files_repo echo -e "\033[32mlocalrepo install done!\033[0m" echo "module_hotfixes=1" >> /etc/yum.repos.d/$(ls /etc/yum.repos.d/ |grep files_repo |awk '{printf $1}') echo "gpgcheck=0" >> /etc/yum.repos.d/$(ls /etc/yum.repos.d/ |grep files_repo |awk '{printf $1}') yum clean all ls /etc/yum.repos.d/ } function _install_python() { if rpm -q $PACKAGE_PYTHON; then echo -e "\n\033[32mpython is installed!\n\033[0m" else echo -e "\n\033[33mpython install start!\n\033[0m" yum install -y python3.11 python3.11-pip if rpm -q $PACKAGE_PYTHON; then echo -e "\n\033[32mpython install done!\n\033[0m" python3.11 --version else echo -e "\n\033[31mpython install Faild!\n\033[0m" exit fi fi } function _install_ansible() { if ansible --version; then echo -e "\n\033[32mansible is installed!\n\033[0m" else echo -e "\n\033[33mansible install start!\n\033[0m" pip3 install -f $PWD/kubespray/roles/exem-infra/files/files_repo/python/* --prefix=/usr if ansible --version; then echo -e "\n\033[32mansible install done!\n\033[0m" else echo -e "\n\033[31mansible install Faild!\n\033[0m" exit fi fi } function _install_collection() { mkdir -p ~/.ansible/collections/ansible_collections/ cp -r ./collection/* ~/.ansible/collections/ansible_collections/ } function _install_rsync() { if rpm -q $PACKAGE_RSYNC; then echo -e "\n\033[32mrsync is installed!\n\033[0m" else echo -e "\n\033[33mrsync install start!\n\033[0m" yum install -y rsync if rpm -q $PACKAGE_RSYNC; then echo -e "\n\033[32mrsync install done!\n\033[0m" rsync --version else echo -e "\n\033[31mrsync install Faild!\n\033[0m" exit fi fi } function main() { if [ $INSTALL_LOCALREPO = true ]; then _localrepo fi if [ $INSTALL_PYTHON = true ]; then _install_python fi if [ $INSTALL_ANSIBLE = true ]; then _install_ansible fi if [ $INSTALL_COLLECTION = true ]; then _install_collection fi if [ $INSTALL_RSYNC = true ]; then _install_rsync fi } main