mirror of
https://github.com/myvesta/vesta.git
synced 2025-01-10 21:12:52 -08:00
aa08f6c421
Duplicate interface name detection fix
123 lines
3.9 KiB
Bash
Executable File
123 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# info: update system ip
|
|
# options: [USER] [IP_STATUS]
|
|
#
|
|
# The function scans configured ip in the system and register them with vesta
|
|
# internal database. This call is intended for use on vps servers, where ip is
|
|
# set by hypervizor.
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
# Argument definition
|
|
user=${1-admin}
|
|
ip_status=${2-shared}
|
|
|
|
# Includes
|
|
source /etc/profile.d/vesta.sh
|
|
source $VESTA/func/main.sh
|
|
source $VESTA/func/ip.sh
|
|
source $VESTA/conf/vesta.conf
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Verifications #
|
|
#----------------------------------------------------------#
|
|
|
|
check_args '0' "$#" '[USER] [IP_STATUS]'
|
|
is_format_valid 'user' 'ip_status'
|
|
is_object_valid 'user' 'USER' "$user" "$user"
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
# Get list of ip addresses
|
|
ip_list=$(/sbin/ip addr|grep 'inet '|grep global|awk '{print $2}')
|
|
ip_list=$(echo "$ip_list"|cut -f 1 -d /)
|
|
ip_num=$(echo "$ip_list" | wc -l)
|
|
|
|
# WorkAround for DHCP IP address
|
|
vst_ip_list=$(ls $VESTA/data/ips/)
|
|
vst_ip_num=$(echo "$vst_ip_list" | wc -l)
|
|
|
|
if [ ! -z "$vst_ip_list" ] && [ "$vst_ip_num" -eq '1' ]; then
|
|
if [ $ip_num -eq 1 ] && [ "$ip_list" != "$vst_ip_list" ]; then
|
|
new=$ip_list
|
|
old=$vst_ip_list
|
|
mv $VESTA/data/ips/$old $VESTA/data/ips/$new
|
|
if [ ! -z "$PROXY_SYSTEM" ]; then
|
|
mv /etc/$PROXY_SYSTEM/conf.d/$old.conf \
|
|
/etc/$PROXY_SYSTEM/conf.d/$new.conf
|
|
sed -i "s/$old/$new/g" /etc/$PROXY_SYSTEM/conf.d/$new.conf
|
|
fi
|
|
if [ ! -z "$WEB_SYSTEM" ]; then
|
|
mv /etc/$WEB_SYSTEM/conf.d/$old.conf \
|
|
/etc/$WEB_SYSTEM/conf.d/$new.conf
|
|
sed -i "s/$old/$new/g" /etc/$WEB_SYSTEM/conf.d/$new.conf
|
|
sed -i "s/$old/$new/g" $VESTA/data/users/*/web.conf
|
|
|
|
# Rebuild web domains
|
|
for user in $(ls $VESTA/data/users/); do
|
|
$BIN/v-rebuild-web-domains $user no
|
|
done
|
|
fi
|
|
if [ ! -z "$FTP_SYSTEM" ];then
|
|
ftpd_conf_file=$(find /etc/ -maxdepth 2 -name $FTP_SYSTEM.conf)
|
|
sed -i "s/$old/$new/g" $ftpd_conf_file
|
|
fi
|
|
|
|
# Restarting web server
|
|
$BIN/v-restart-web
|
|
|
|
# Restarting ftp server
|
|
$BIN/v-restart-ftp
|
|
|
|
# Restarting proxy server
|
|
if [ ! -z "$PROXY_SYSTEM" ]; then
|
|
$BIN/v-restart-proxy
|
|
fi
|
|
|
|
# Restarting firewall
|
|
if [ ! -z "$FIREWALL_SYSTEM" ]; then
|
|
$BIN/v-update-firewall
|
|
fi
|
|
|
|
if [ ! -z "$DNS_SYSTEM" ]; then
|
|
# Rebuild dns domains
|
|
for user in $(ls $VESTA/data/users/); do
|
|
sed -i "s/$old/$new/g" $VESTA/data/users/$user/dns.conf
|
|
sed -i "s/$old/$new/g" $VESTA/data/users/$user/dns/*.conf
|
|
$BIN/v-rebuild-dns-domains $user no
|
|
done
|
|
$BIN/v-restart-dns
|
|
check_result $? "dns restart failed" >/dev/null
|
|
fi
|
|
|
|
# No further comparation is needed
|
|
exit
|
|
fi
|
|
fi
|
|
|
|
# Compare ips
|
|
for ip in $ip_list; do
|
|
check_ifconfig=$(/sbin/ifconfig |grep "$ip")
|
|
if [ ! -e "$VESTA/data/ips/$ip" ] && [ ! -z "$check_ifconfig" ]; then
|
|
interface=$(/sbin/ip addr |grep $ip |awk '{print $NF}'|uniq)
|
|
interface=$(echo "$interface" |cut -f 1 -d : |head -n 1)
|
|
netmask=$(/sbin/ip addr |grep $ip |cut -f 2 -d / |cut -f 1 -d \ )
|
|
netmask=$(convert_cidr $netmask)
|
|
$BIN/v-add-sys-ip $ip $netmask $interface
|
|
fi
|
|
done
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
exit
|