File tree Expand file tree Collapse file tree 3 files changed +18
-30
lines changed
Expand file tree Collapse file tree 3 files changed +18
-30
lines changed Original file line number Diff line number Diff line change 1414# Variable&Function #
1515# ----------------------------------------------------------#
1616
17+ # Get interface name
18+ iface=$( /bin/ip token | awk -F ' dev ' ' {print $2}' )
19+
1720# Argument definition
1821ip=${1// / }
1922netmask=$2
20- interface =" ${3-eth0 } "
23+ iface =" ${3-$iface } "
2124user=" ${4-admin} "
2225ip_status=" ${5-shared} "
2326ip_name=$6
5053# ----------------------------------------------------------#
5154# Action #
5255# ----------------------------------------------------------#
53- iface= $( get_ip_iface )
56+
5457cidr=$( convert_netmask $netmask )
5558broadcast=$( get_broadcast $ip $netmask )
5659
5760sys_ip_check=$( /sbin/ip addr | grep " $ip " )
5861if [ -z " $sys_ip_check " ]; then
5962 # Adding sys ip
60- /sbin/ip addr add $ip /$cidr dev $interface \
63+ /sbin/ip addr add $ip /$cidr dev $iface \
6164 broadcast $broadcast label $iface
6265
6366 # Adding RHEL/CentOS/Fedora/Amazon startup script
@@ -110,7 +113,7 @@ STATUS='$ip_status'
110113NAME='$ip_name '
111114U_SYS_USERS=''
112115U_WEB_DOMAINS='0'
113- INTERFACE='$interface '
116+ INTERFACE='$iface '
114117NETMASK='$netmask '
115118NAT='$nat_ip '
116119TIME='$time '
Original file line number Diff line number Diff line change @@ -63,19 +63,17 @@ if [ -e "/etc/sysconfig/network-scripts/ifcfg-$interface" ]; then
6363fi
6464
6565# Deleting startup conf on Debian/Ubuntu
66- if [ -e " /etc/network/interfaces" ]; then
67- if [ -f " /etc/netplan/60-hestia.yaml" ]; then
68- sed -i " /$ip /d" /etc/netplan/60-hestia.yaml
69- if ! grep -q ' -' /etc/netplan/60-hestia.yaml; then
70- rm /etc/netplan/60-hestia.yaml
71- fi
72- else
73- ip_str=$( grep -n $ip $ /etc/network/interfaces | cut -f1 -d:)
74- if [ ! -z " $ip_str " ]; then
75- first_str=$(( ip_str - 3 ))
76- last_str=$(( ip_str + 1 ))
77- sed -i " $first_str ,$last_str d" /etc/network/interfaces
78- fi
66+ if [ -f " /etc/netplan/60-hestia.yaml" ]; then
67+ sed -i " /$ip /d" /etc/netplan/60-hestia.yaml
68+ if ! grep -q ' -' /etc/netplan/60-hestia.yaml; then
69+ rm /etc/netplan/60-hestia.yaml
70+ fi
71+ elif [ -e " /etc/network/interfaces" ]; then
72+ ip_str=$( grep -n $ip $ /etc/network/interfaces | cut -f1 -d:)
73+ if [ ! -z " $ip_str " ]; then
74+ first_str=$(( ip_str - 3 ))
75+ last_str=$(( ip_str + 1 ))
76+ sed -i " $first_str ,$last_str d" /etc/network/interfaces
7977 fi
8078fi
8179
Original file line number Diff line number Diff line change @@ -13,19 +13,6 @@ is_ip_free() {
1313 fi
1414}
1515
16- # Get full interface name
17- get_ip_iface () {
18- i=$( /sbin/ip addr | grep -w $interface | \
19- awk ' {print $NF}' | tail -n 1 | cut -f 2 -d :)
20- if [ " $i " = " $interface " ]; then
21- n=0
22- else
23- n=$(( i + 1 ))
24- fi
25- echo " $interface :$n "
26- }
27-
28-
2916# Check ip address specific value
3017is_ip_key_empty () {
3118 key=" $1 "
You can’t perform that action at this time.
0 commit comments