#!/bin/bash # Script checks if CUCM has assigned IP address 10.79.1.8. If the IP address is detected, the script suggests to change extension range, SNMP configuration and # IPv4 address in CUCM database. Then the script changes IPv4 address and default gw in OS according to the BT number and reboots CUCM. # If no IP address 10.79.1.8 is detected, it skips IPv4 configuration and continue with changing NTP and DNS server. Hostname must be changed manually from # CUCM CLI and let CUCM to reboot. The script continues with IPv6 address configuration, delete logs and reboots CUCM again. default_ntp=$(cat /etc/ntp.conf | grep 'server -4' | cut -d " " -f3) default_dns=$(cat /etc/resolv.conf | grep nameserver | cut -d " " -f2) default_hostname=$(hostname) default_ip=10.79.1.8 default_ipv6=$(cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep 'IPV6ADDR' | cut -d "=" -f2) clear until [[ $team -gt 0 && $team -lt 14 ]] || [[ $team -eq 79 ]]; do echo -n "Enter the number of CUCM e.g. for CUCM-BLUE1 enter 1: " read team done ip=$(ifconfig eth0 | grep 'inet addr' | cut -d ":" -f2 | cut -d " " -f1) ntp1=10.$team.1.2 ntp2=10.$team.1.9 dns1=10.$team.1.2 dns2=10.$team.1.9 hostname=cucm-blue$team ipv6=2001:10:$team:1::8/64 function clear_logs { rm -f /var/log/*.log rm -f /var/log/*.log.* rm -f /var/log/boot rm -f /var/log/auth* rm -f /var/log/*.gz rm -f /var/log/apache2/* rm -f /var/log/apt/* rm -f /var/log/ejabberd/* rm -f /var/log/mail* rm -f /var/log/dmesg* rm -f /var/log/debug* rm -f /var/log/messages* rm -f /var/log/kern* rm -f /var/log/syslog* rm -f /var/log/mysql/* rm -f /var/log/mysql* rm -f /var/log/nginx/* rm -f /var/log/udev* rm -f /var/log/dpkg* rm -f /root/.viminfo rm -f /root/.vim/* rm -f /root/.bash_history rm -f /root/.mysql_history rm -f /home/greenteam/.viminfo rm -f /home/greenteam/.bash_history rm -f /home/greenteam/.mysql_history rm -f /var/log/xferlog* rm -f /var/log/alternatives* rm -f /var/log/samba/* rm -f /var/log/landscape/* rm -f /var/log/ntpstats/* rm -f /var/log/upstart/* rm -f /var/log/ConsoleKit/* rm -f /var/log/cups/* rm -f /var/log/fsck/* rm -f /var/log/installer/* rm -f /var/log/lightdm/* rm -f /var/log/upstart/* rm -f /var/log/ntpd.log rm -f /var/log/clamd.log rm -f /root/.ssh/known_hosts rm -f /home/greenteam/.ssh/known_hosts } echo "" #PHASE 1 - Compare actual IP with default IP address, if they are different skip to NTP configuration if [[ "$ip" == "$default_ip" ]] then echo "CUCM interface eth0 is configured with IP address $ip, we're going to change it to: 10.$team.1.8" case $team in 1) echo -e "fea34d3133e8616c7d18504e776ca55b13e3aacb" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 1000 - 1499\n" team_changed=0$team ;; 2) echo -e "4ca1046f0af1ce5736f6a99fd977b55c3b3aa338" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 1500 - 1999\n" team_changed=0$team ;; 3) echo -e "09245b59e02159ccd96bdfbf6ccf450cfb7ddf58" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 2000 - 2499\n" team_changed=0$team ;; 4) echo -e "b307df27ff2494db0ba2b3aaf2ba5e58d115d701" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 2500 - 2999\n" team_changed=0$team ;; 5) echo -e "0f441f6afad600184250c802e6dcc9c375f0d397" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 3000 - 3499\n" team_changed=0$team ;; 6) echo -e "c50c4901d3a3908dcec79bd3a175bf70cdb42d1f" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 3500 - 3999\n" team_changed=0$team ;; 7) echo -e "898e97a824d6038aa79da5c69ff7b2b48a840b52" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 4000 - 4499\n" team_changed=0$team ;; 8) echo -e "ceedd2e12327692bad619c111784e2cfd58cf38d" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 4500 - 4999\n" team_changed=0$team ;; 9) echo -e "c43257852d6c0fc81f7db354e9dda51ed57f5d73" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 5000 - 5499\n" team_changed=0$team ;; 10) echo -e "3a7017903e72a9ee00660d86fd0cb2a57c86385c" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 5500 - 5999\n" team_changed=$team ;; 11) echo -e "cf15dc1da5a5706f2cdbd8460f8f9787a48c340b" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 6000 - 6499\n" team_changed=$team ;; 12) echo -e "9739d62b933e4d2eab933a72851cb0947741e414" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 6500 - 6999\n" team_changed=$team ;; 13) echo -e "86c87d9c5ac89b0f185fc6d660b3f800634c24c0" > /etc/hash echo -e "\nHASH $(cat /etc/hash) was copied into /etc/hash\n" echo -e "Extension range for CUCM-BLUE$team is 7000 - 7499\n" team_changed=$team ;; 79) echo -e "\nHASH is not needed for CUCM-BLUE$team, nothing to do\n" echo -e "Extension range for CUCM-BLUE$team is 7500 - 7999\n" team_changed=$team ;; *) echo "Sorry, team doesn't exist, exiting now " exit ;; esac echo -n "Have you changed extension range for CUCM-BLUE$team in System->Cisco Unified CM? [yes]: " read input echo "" while [ "$input" != yes ] do echo -n "Have you changed extension range for CUCM-BLUE$team in System->Cisco Unified CM? [yes]: " read input done echo -n "Have you configured SNMP settings, trap destination 10.$team.4.3, port 8980, version V2C, string->public for CUCM-BLUE$team in Cisco Unified Serviceability? [yes]: " read input echo "" while [ "$input" != yes ] do echo -n "Have you configured SNMP settings, trap destination 10.$team.4.3 for CUCM-BLUE$team in Cisco Unified Serviceability? [yes]: " read input done echo -n "Have you configured IPv4 address 10.$team.1.8 in System-> Server? [yes]: " read input echo "" while [ "$input" != yes ] do echo -n "Have you configured IPv4 address 10.$team.1.8 in System-> Server? [yes]: " read input done #Change the IP address and default GW according to BT settings sed -i "s/10.79.1.8/10.$team.1.8/g" /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i "s/10.79.1.1/10.$team.1.1/g" /etc/sysconfig/network-scripts/ifcfg-eth0 echo -e "\nThe content of /etc/sysconfig/network-scripts/ifcfg-eth0 is following:" cat /etc/sysconfig/network-scripts/ifcfg-eth0 echo -e "\nIf it's ok I'm going to shutdown CUCM" echo -e "Please don't forget to change VMware NIC to 'dvTeam$team_changed-VLAN1`echo $team_changed`1' once VM is powered off\n" echo -n "May I shutdown CUCM? [yes]: " read input echo "" while [ "$input" != yes ] do echo -n "Use CTRL-C to exit script or type 'yes' to shutdown CUCM-BLUE$team [yes]: " read input done /sbin/shutdown -h now else #PHASE 2 - Continue with NTP, DNS, hostname and IPV6 echo -e "CUCM default IP address $default_ip isn't detected, the interface eth0 is configured with IP address $ip" echo -e "We can continue with NTP, DNS, hostname and IPv6 configuration" #Only change NTP server configuration if it does not match particular BT NTP, then restart ntpd service if [[ "$(echo $ntp1 $ntp2)" == "$(echo $default_ntp)" ]] then echo -e "\nCUCM-BLUE$team is configured with the NTP servers:" echo "$default_ntp" echo "Nothing to do" else echo -e "\nCUCM-BLUE$team is configured with the NTP servers:" echo -e "$default_ntp" echo -e "I'm going to change them to: $ntp1 and $ntp2" sed -i "s/10.79.1.2/$ntp1/g" /etc/ntp.conf sed -i "s/10.79.1.9/$ntp2/g" /etc/ntp.conf /etc/init.d/ntpd restart echo -e "These are NTP servers now:\n$(cat /etc/ntp.conf | grep 'server -4' | cut -d " " -f3)" fi #Only change DNS client configuration if it does not match particular BT DNS if [[ "$(echo $dns1 $dns2)" == "$(echo $default_dns)" ]] then echo -e "\nCUCM-BLUE$team is configured with the DNS servers:" echo "$default_dns" echo "Nothing to do" else echo -e "\nCUCM-BLUE$team is configured with the DNS servers:" echo -e "$default_dns" echo -e "I'm going to changed them to: $dns1 and $dns2" echo "nameserver $dns1" > /etc/resolv.conf echo "nameserver $dns2" >> /etc/resolv.conf echo -e "These are DNS servers now:\n$(cat /etc/resolv.conf | grep nameserver | cut -d " " -f2)" fi #User must change hostname from CUCM CLI if it doesn not match particular BT hostname if [[ "$hostname" == "$default_hostname" ]] then echo -e "\nCUCM-BLUE$team is configured with the hostname: $default_hostname, nothing to do" else echo -e "\nCUCM-BLUE$team is configured with the hostname: $default_hostname\n" echo -e "DON'T CHANGE HOSTNAME FROM LINUX CLI OTHERWISE CUCM DATABASE FAILS" echo -e "Type 'exit' to exit from Linux CLI and login to CUCM CLI" echo -e "Type 'set network hostname $hostname' and CUCM will restart automatically'" echo -e "Script is exiting now, after reboot start the script again\n" exit fi #PHASE3 - IPv6 configuration if [[ "$ipv6" == "$default_ipv6" ]] then echo -e "\nCUCM-BLUE$team has assigned IPv6 address: $default_ipv6, nothing to do\n" clear_logs echo -e "Logs were deleted\n" else echo -e "\nConfiguring IPV6 settings for CUCM-BLUE$team" echo "IPv6 address: 2001:10:$team:1::8/64" echo -e "IPv6 default GW: 2001:10:$team:1::1\n" echo "NETWORKING_IPV6=yes" >> /etc/sysconfig/network echo "IPV6INIT=yes" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "IPV6ADDR=2001:10:$team:1::8/64" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "IPV6_AUTOCONF=yes" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "DHCPV6C=no" >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo "IPV6_DEFAULTGW=2001:10:$team:1::1" >> /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/init.d/network restart echo "" echo -n "Have you configured IPv6 address 2001:10:$team:1::8 in System-> Server? [yes]: " read input echo "" while [ "$input" != yes ] do echo -n "Have you configured IPv6 address 2001:10:$team:1::8 in System-> Server? [yes]: " read input done clear_logs echo -e "\nLogs were deleted\n" if [[ -f /root/deploy-cucm ]] then rm -f /root/deploy-cucm echo -e "File '/root/deploy-cucm' was deleted\n" else echo -e "File '/root/deploy-cucm' not found, delete it manually after reboot!\n" fi echo -e "\n===> Deployment of CUCM-BLUE$team is finished, system is going down for reboot <===\n" /sbin/shutdown -r now fi fi