| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- #!/bin/bash
- #########################################################################
- # Script for change important parameters #
- # Created by DoIT #
- # 1.3 #
- #########################################################################
- #------------------------------ DEFINITION -----------------------------#
- SERIAL="N"
- MOD=TEST
- #------------------------------- LOCAL IP ------------------------------#
- check_nic(){
- NICS=$(find /sys/class/net -type l ! -lname '*lo*' -printf '%f\n')
- for i in $NICS;
- do
- CI=$(ifconfig $i | grep -w inet)
- if [ ! -z "$CI" ]; then
- echo -e "- \e[1;32mActive\e[0m [\e[1;33m$i\e[0m]"
- SN=$(ifconfig $i | grep -w ether | sed 's/:/ /g' | awk '{print tolower ($5$6$7)}')
- IP=$(ifconfig $i | grep -w inet | awk '{print $2}')
- fi
- done
- if [ -z "$IP" ]; then
- echo -e "- \e[1;31mmissing\e[0m IP address"
- exit 1
- else
- echo -e "- \e[1;32mIP-Address\e[0m [\e[1;33m$IP\e[0m]"
- fi
- OLDURL=$(cat /etc/monit/monitrc | grep "use address" | awk '{print $3}')
- }
- #--------------------------- UPDATE HOSTNAME ---------------------------#
- update_host(){
- if [[ "$SERIAL" == "Y" ]]; then
- HOST=$(cat /etc/hosts | grep "$MOD-$SN" | awk '{print $2}' | head -1)
- HNAME=$(cat /etc/hostname | grep "$MOD-$SN")
- if [[ "$MOD-$SN" != "$HOST" ]] || [[ "$MOD-$SN" != "$HNAME" ]];
- then
- echo -e "- \e[1;33mUpdating\e[0m [\e[1;34mHOST\e[0m]"
- chattr -i /etc/hostname
- echo "$MOD-$SN" > /etc/hostname
- chattr +i /etc/hostname
- chattr -i /etc/hosts
- echo "127.0.0.1 localhost" > /etc/hosts
- echo "127.0.1.1 $MOD-$SN" >> /etc/hosts
- chattr +i /etc/hosts
- hostname "$MOD-$SN"
- fi
- else
- HOST=$(cat /etc/hosts | grep "$MOD" | awk '{print $2}' | head -1)
- HNAME=$(cat /etc/hostname | grep "$MOD")
- if [[ "$MOD" != "$HOST" ]] || [[ "$MOD" != "$HNAME" ]];
- then
- echo -e "- \e[1;33mUpdating\e[0m [\e[1;34mHOST\e[0m]"
- chattr -i /etc/hostname
- echo "$MOD" > /etc/hostname
- chattr +i /etc/hostname
- chattr -i /etc/hosts
- echo "127.0.0.1 localhost" > /etc/hosts
- echo "127.0.1.1 $MOD" >> /etc/hosts
- chattr +i /etc/hosts
- hostname "$MOD"
- fi
- fi
- }
- #----------------------------- UPDATE MONIT ----------------------------#
- update_monit(){
- MONIT=$(cat /etc/monit/monitrc | grep "check system" | awk '{print $3}')
- MONIP=$(cat /etc/monit/monitrc | grep "use address" | awk '{print $3}')
- if [[ "$SERIAL" == "Y" ]]; then
- if [[ "$MOD-$SN" != "$MONIT" ]] || [[ "$IP" != "$MONIP" ]]; then
- echo -e "- \e[1;33mUpdating\e[0m [\e[1;35m/etc/monit/monitrc\e[0m]"
- sed -i "s/check system.*/check system $MOD-$SN/g" /etc/monit/monitrc
- sed -i "s/use address.*/use address $IP/g" /etc/monit/monitrc
- /etc/init.d/monit restart > /dev/null 2>&1 || systemctl restart monit > /dev/null 2>&1
- fi
- else
- if [[ "$MOD" != "$MONIT" ]] || [[ "$IP" != "$MONIP" ]]; then
- echo -e "- \e[1;33mUpdating\e[0m [\e[1;35m/etc/monit/monitrc\e[0m]"
- sed -i "s/check system.*/check system $MOD/g" /etc/monit/monitrc
- sed -i "s/use address.*/use address $IP/g" /etc/monit/monitrc
- /etc/init.d/monit restart > /dev/null 2>&1 || systemctl restart monit > /dev/null 2>&1
- fi
- fi
- }
- #----------------------------- UPDATE APC ------------------------------#
- update_apc(){
- APCD=$(cat /etc/apcupsd/apcupsd.conf | grep UPSNAME | awk '{print $2}')
- APCH=$(cat /etc/apcupsd/hosts.conf | grep MONITOR | awk '{print $3}' | sed 's/"//g')
- APCI=$(cat /etc/apcupsd/hosts.conf | grep MONITOR | awk '{print $2}' | sed 's/"//g')
- if [[ "$SERIAL" == "Y" ]]; then
- if [[ "$MOD-$SN" != "$APCD" ]] || [[ "$MOD-$SN" != "$APCH" ]] || [[ "$IP" != "$APCI" ]]; then
- echo -e "- \e[1;33mUpdating\e[0m [\e[1;35m/etc/apcupsd/hosts.conf\e[0m]"
- echo -e "- \e[1;33mUpdating\e[0m [\e[1;35m/etc/apcupsd/apcupsd.conf\e[0m]"
- sed -i "s/UPSNAME.*/UPSNAME $MOD-$SN/g" /etc/apcupsd/apcupsd.conf
- sed -i "s/MONITOR.*/MONITOR $IP \"$MOD-$SN\"/g" /etc/apcupsd/hosts.conf
- /etc/init.d/apcupsd restart > /dev/null 2>&1 || systemctl restart monit > /dev/null 2>&1
- fi
- else
- if [[ "$MOD" != "$APCD" ]] || [[ "$MOD" != "$APCH" ]] || [[ "$IP" != "$APCI" ]]; then
- echo -e "- \e[1;33mUpdating\e[0m [\e[1;35m/etc/apcupsd/hosts.conf\e[0m]"
- echo -e "- \e[1;33mUpdating\e[0m [\e[1;35m/etc/apcupsd/apcupsd.conf\e[0m]"
- sed -i "s/UPSNAME.*/UPSNAME $MOD/g" /etc/apcupsd/apcupsd.conf
- sed -i "s/MONITOR.*/MONITOR $IP \"$MOD\"/g" /etc/apcupsd/hosts.conf
- /etc/init.d/apcupsd restart > /dev/null 2>&1 || systemctl restart monit > /dev/null 2>&1
- fi
- fi
- }
- #--------------------------- UPDATE POSTFIX ----------------------------#
- update_postfix(){
- POSTFIX=$(cat /etc/postfix/main.cf | grep -w "^myhostname" | awk '{print $3}')
- if [[ "$SERIAL" == "Y" ]]; then
- if [[ "$MOD-$SN" != "$POSTFIX" ]]; then
- echo -e "- \e[1;33mUpdating\e[0m [\e[1;35m/etc/postfix/main.cf\e[0m]"
- sed -i "s/myhostname =.*/myhostname = $MOD-$SN/g" /etc/postfix/main.cf
- sed -i "s/mydestination = \$myhostname,.*/mydestination = \$myhostname, $MOD-$SN, localhost/g" /etc/postfix/main.cf
- newaliases
- /etc/init.d/postfix restart > /dev/null 2>&1 || systemctl restart postfix > /dev/null 2>&1
- fi
- else
- if [[ "$MOD" != "$POSTFIX" ]]; then
- echo -e "- \e[1;33mUpdating\e[0m [\e[1;35m/etc/postfix/main.cf\e[0m]"
- sed -i "s/myhostname =.*/myhostname = $MOD/g" /etc/postfix/main.cf
- sed -i "s/mydestination = \$myhostname,.*/mydestination = \$myhostname, $MOD, localhost/g" /etc/postfix/main.cf
- newaliases
- /etc/init.d/postfix restart > /dev/null 2>&1 || systemctl restart postfix > /dev/null 2>&1
- fi
- fi
- }
- #-------------------------- UPDATE WEB SOURCE --------------------------#
- update_web(){
- OLDURL=$(cat /var/www/index.html | grep http | awk '{print $4}' | sed 's/\/\// /g' | sed 's/\// /g' | sed 's/:/ /g' | awk '{print $2}' | sort | uniq | grep [0-9])
- LST=$(find /var/www/ -name index.htm*)
- if [[ "$OLDURL" != "$IP" ]]; then
- echo -e "- \e[1;33mUpdating\e[0m \e[1;34mIP\e[0m [\e[1;35m$IP\e[0m]"
- for w in $LST;
- do
- sed -i "s/$OLDURL/$IP/g" $w
- done
- fi
- for w in $LST;
- do
- OLDHST=$(cat $w | grep -i TITLE | sed 's/>/ /g' | sed 's/</ /g' | awk '{print $2}')
- if [[ "$SERIAL" == "Y" ]]; then
- if [[ "$OLDHST" != "$MOD-$SN" ]]; then
- echo -e "- \e[1;33mUpdating\e[0m \e[1;34mHOST\e[0m [\e[1;35m$w\e[0m]"
- sed -i "s/<TITLE>.*/<TITLE>$MOD-$SN<\/TITLE>/g" $w
- sed -i "s/<title>.*/<title>$MOD-$SN<\/title>/g" $w
- # sed -i "s/on server.*/on server [<b>$MOD-$SN<\/b>]<\/font><\/p>/g" $w
- sed -i "/on server/s/\[[^]]*\]/[$MOD-$SN]/g" $w
- fi
- else
- if [[ "$OLDHST" != "$MOD" ]]; then
- echo -e "- \e[1;33mUpdating\e[0m \e[1;34mHOST\e[0m [\e[1;35m$w\e[0m]"
- sed -i "s/<TITLE>.*/<TITLE>$MOD<\/TITLE>/g" $w
- sed -i "s/<title>.*/<title>$MOD<\/title>/g" $w
- # sed -i "s/on server.*/on server [<b>$MOD<\/b>]<\/font><\/p>/g" $w
- sed -i "/on server/s/\[[^]]*\]/[$SRV]/g" $w
- fi
- fi
- done
- }
- #--------------------------------- CORE --------------------------------#
- clear
- check_nic
- update_host
- test -f /etc/monit/monitrc && update_monit
- test -f /etc/postfix/main.cf && update_postfix
- test -f /etc/apcupsd/apcupsd.conf && update_apc
- test -d /var/www/ && update_web
|