GIF89a;
Direktori : /etc/rc3.d/ |
Current File : //etc/rc3.d/S70cpanelconfig |
#!/bin/bash # Put me in /etc/rc.d/rc3.d to start just after MySQL service and before the cPanel's services logger "$0 - START" # Generate a better resolv.conf NS1='8.8.8.8' NS2='8.8.4.4' resolvconf='/etc/resolv.conf' resolversnum=`cat $resolvconf | grep '^nameserver.*$' |wc -l 2>/dev/null` if [ $resolversnum -lt 2 ]; then logger "$0 - Configuring nameservers with $NS1 and or $NS2 ..." if grep $NS1 $resolvconf >/dev/null 2>&1; then logger "$0 - $NS1 found." else echo "nameserver $NS1" >> $resolvconf fi if grep $NS2 $resolvconf >/dev/null 2>&1; then logger "$0 - $NS2 found." else echo "nameserver $NS2" >> $resolvconf fi fi # Get the IP and hostname IP= HOSTNAME= IP=`ifconfig eth0 2>/dev/null | grep "inet addr" 2>/dev/null | awk '{print $2}' 2>/dev/null | awk -F: '{print $2}' 2>/dev/null` HOSTNAME=`hostname 2>/dev/null` if [ "x${IP}" != "x" -a "x${HOSTNAME}" != "x" ]; then # Generate the cPanel www config logger "$0 - Create /etc/wwwacct.conf and configure it with ADDR: $IP; HOST: $HOSTNAME" cat << ! > /etc/wwwacct.conf HOST $HOSTNAME HOMEDIR /home ETHDEV NS ns1.vm NS2 ns2.vm HOMEMATCH home NSTTL 86400 NS4 TTL 14400 ADDR $IP DEFMOD x3 SCRIPTALIAS y CONTACTPAGER MINUID 500 NS3 CONTACTEMAIL LOGSTYLE combined DEFWEBMAILTHEME x3 ! # Set primary IP address logger "$0 - Create /var/cpanel/mainip" echo $IP > /var/cpanel/mainip # Replace old IP (set up during the cPanel install) with current primary one logger "$0 - Set the IP for 'VirtualHost' in all found httpd.conf*" find / -name httpd.conf\* -exec sed -i "s/<VirtualHost [0-9\.]\+:/<VirtualHost $IP:/g; s/RewriteCond %{HTTP_HOST} .\+$/RewriteCond %{HTTP_HOST} \!\^$HOSTNAME$/g; s/ServerName .\+$/ServerName $HOSTNAME/g; s/ServerAdmin .\+$/ServerAdmin root@$HOSTNAME/g" {} \; # Fix/create /etc/mail_reverse_dns with correct primary IP address and host name logger "$0 - Create /etc/mail_reverse_dns" echo "$IP: $HOSTNAME" > /etc/mail_reverse_dns # Fix/create /etc/localdomains with correct host name logger "$0 - Create /etc/localdomains" echo "$HOSTNAME" > /etc/localdomains else logger "$0 - Undefined IP: '$IP' or hostname: '$HOSTNAME'" fi # Tidy up > /var/log/wtmp > /root/.bash_history # Reset mysql root user password if [ -e /root/.my.cnf ]; then passwd= passwd=`grep 'pass=' /root/.my.cnf 2>/dev/null | sed 's/.*pass="\(.\+\)".*/\1/g' 2>/dev/null` new_passwd= new_passwd=`tr -dc 'a-zA-Z0-9!#$%^&()' < /dev/urandom 2>/dev/null | fold -w 10 2>/dev/null | sed 5q 2>/dev/null | head -1 2>/dev/null` if [ "x${passwd}" != "x" -a "x${new_passwd}" != "x" ]; then logger "$0 - Changing MySQL root user password ..." mysql mysql --password="${passwd}" -e "UPDATE user SET Password = PASSWORD('${new_passwd}') WHERE User = 'root'; FLUSH PRIVILEGES;" if [ $? -eq 0 ]; then logger "$0 - MySQL root user password has been changed." echo -e "[client]\npass=\"${new_passwd}\"\nuser=root" > /root/.my.cnf fi fi fi # Don't run again rm -f $0 logger "$0 - FINISHED"