Skip to content

Commit 7f27d6c

Browse files
committed
Add support for netplan ip configuration.
1 parent 3e8d711 commit 7f27d6c

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

bin/v-add-sys-ip

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,29 @@ if [ -z "$sys_ip_check" ]; then
7373

7474
# Adding Debian/Ubuntu startup script
7575
if [ -e "/etc/debian_version" ]; then
76-
sys_ip="\n# Added by hestia"
77-
sys_ip="$sys_ip\nauto $iface"
78-
sys_ip="$sys_ip\niface $iface inet static"
79-
sys_ip="$sys_ip\naddress $ip"
80-
sys_ip="$sys_ip\nnetmask $netmask"
81-
echo -e $sys_ip >> /etc/network/interfaces
76+
if [ -d "/etc/netplan" ]; then
77+
if [ -f "/etc/netplan/60-hestia.yaml" ]; then
78+
sys_ip=" - $ip/$cidr"
79+
else
80+
sys_ip="\n# Added by hestia"
81+
sys_ip="$sys_ip\nnetwork:"
82+
sys_ip="$sys_ip\n version: 2"
83+
sys_ip="$sys_ip\n renderer: networkd"
84+
sys_ip="$sys_ip\n ethernets:"
85+
sys_ip="$sys_ip\n eth0:"
86+
sys_ip="$sys_ip\n addresses:"
87+
sys_ip="$sys_ip\n - $ip/$cidr"
88+
fi
89+
IFS='%'
90+
echo -e $sys_ip >> /etc/netplan/60-hestia.yaml
91+
else
92+
sys_ip="\n# Added by hestia"
93+
sys_ip="$sys_ip\nauto $iface"
94+
sys_ip="$sys_ip\niface $iface inet static"
95+
sys_ip="$sys_ip\naddress $ip"
96+
sys_ip="$sys_ip\nnetmask $netmask"
97+
echo -e $sys_ip >> /etc/network/interfaces
98+
fi
8299
fi
83100
fi
84101

bin/v-delete-sys-ip

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,18 @@ fi
6464

6565
# Deleting startup conf on Debian/Ubuntu
6666
if [ -e "/etc/network/interfaces" ]; then
67-
ip_str=$(grep -n $ip$ /etc/network/interfaces |cut -f1 -d:)
68-
if [ ! -z "$ip_str" ]; then
69-
first_str=$((ip_str - 3))
70-
last_str=$((ip_str + 1))
71-
sed -i "$first_str,$last_str d" /etc/network/interfaces
67+
if [ -f "/etc/netplan/60-hestia.yaml" ]; then
68+
sed "/$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
7279
fi
7380
fi
7481

0 commit comments

Comments
 (0)