Skip to content

Commit 3eedab1

Browse files
authored
Check if netplan file is created (hestiacp#2612)
* Check if netplan file is created * Fix bug in netplan detection * Fix bug in test * Improve shellcheck code in cause major failure. * Fix bug in v-add-sys-ip Improve output if shellcheck fails in first step * Fix bug * Fix bug in v-add-sys-ip * Fix bug in test * Add warning message for existing setups that match critera
1 parent 2a3441e commit 3eedab1

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

bin/v-add-sys-ip

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ if [ -z "$sys_ip_check" ]; then
7575
broadcast $broadcast label $iface
7676

7777
# Check if netplan is in use and generate configuration file
78-
if dpkg-query -W -f'${Status}' "netplan*" 2>/dev/null | grep -q "ok installed"; then
79-
result=$(cat /etc/netplan/*.yaml 2>/dev/null | grep $(hostname -I | cut -d' ' -f1));
80-
if [ -n "$result" ]; then
78+
if [ ! -z $(which netplan) ]; then
79+
if [ ! -z "$(netplan generate --mapping "$iface" | grep networkd)" ]; then
8180
netplan=1
8281
else
8382
netplan=0

install/upgrade/versions/1.6.0.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ if [ -f "/etc/cron.d/hestia-sftp" ]; then
9595
echo "@reboot root sleep 60 && /usr/local/hestia/bin/v-add-sys-sftp-jail > /dev/null" > /etc/cron.d/hestia-sftp
9696
fi
9797

98+
ips=$(ls /usr/local/hestia/data/ips/ | wc -l)
99+
release=$(lsb_release -s -i);
100+
if [ $release = 'Ubuntu' ]; then
101+
if [ $ips -gt 1 ]; then
102+
add_upgrade_message "Warning: Please check your network configuration!\n\n A bug has been discovered that might affect your setup and can lead to issues after a system reboot. Please review your network configuration. See https://github.com/hestiacp/hestiacp/pull/2612#issuecomment-1135571835 for more info regarding this issue!"
103+
$HESTIA/bin/v-add-user-notification admin "Warning: Please check your network configuration!\n\n A bug has been discovered that might affect your setup and can lead to issues after a system reboot. Please review your network configuration. <a href='https://github.com/hestiacp/hestiacp/pull/2612#issuecomment-1135571835'>More info</a>"
104+
fi
105+
fi
106+
98107
if [ -d /etc/phpmyadmin/conf.d ]; then
99108
for file in /etc/phpmyadmin/conf.d/*; do
100109
if [ -z "$(grep -i 'information_schema' $file)" ]; then

test/shellcheck.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,19 @@ for file in $files; do
3131
printf "%s: \033[0;31m Fail \033[0m\n" "$file"
3232
err=1
3333
else
34+
# split loop in 2 parts allowing debuggin in earier stage
3435
printf "%s: \033[0;32m Success \033[0m\n" "$file"
35-
shellcheck -x "$file" -e "SC2086,SC2002,SC2153,SC2181,SC2153,SC2129,SC2016,SC2196,SC1090,SC2031,SC2010,SC2143,SC2046"
3636
fi
3737
done
3838

39+
if [ $err == 1 ];
40+
then
41+
exit "$err";
42+
fi
43+
44+
for file in $files; do
45+
echo "Linting: $file"
46+
shellcheck -x "$file" -e "SC2086,SC2002,SC2153,SC2181,SC2153,SC2129,SC2016,SC2196,SC1090,SC2031,SC2010,SC2143,SC2046"
47+
done
48+
3949
exit "$err";

test/test.bats

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,31 @@ function check_ip_not_banned(){
581581
[ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
582582
[ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
583583
fi
584+
585+
}
586+
587+
@test "Ip: [Ubuntu] Netplan file updated" {
588+
# Skip if Debian
589+
if [ $(lsb_release -s -i) != "Ubuntu" ]; then
590+
skip
591+
fi
592+
593+
# Test will fail if systemd (For example Proxmox) is used for setting ip addresses. How ever there is no "decent" way to check if Netplan is used except via the method used in v-add-sys-ip and there for breaking the reason to test this. How ever if the test used in v-add-sys-ip fails it still should check if it exists!
594+
595+
assert_file_exist /etc/netplan/60-hestia.yaml
596+
597+
# also check if file contains the newly added ip
598+
assert_file_contains /etc/netplan/60-hestia.yaml "$ip"
599+
}
584600

601+
@test "Ip: [Debian] Netplan file updated" {
602+
# Skip with netplan
603+
if [ -f /etc/netplan/60-hestia.yaml ]; then
604+
skip
605+
fi
606+
607+
assert_file_exist /etc/network/interfaces
608+
assert_file_contains /etc/network/interfaces "$ip"
585609
}
586610

587611
@test "Ip: Add ip (duplicate)" {

0 commit comments

Comments
 (0)