Skip to content

Commit

Permalink
v9.8
Browse files Browse the repository at this point in the history
- DietPi-FirstBoot | The network time sync mirror configured in dietpi.txt is now applied before the first time sync is done, instead of after login and initial DietPi update. Many thanks to `@bigops` for making us aware of this: https://dietpi.com/forum/t/21600
  • Loading branch information
MichaIng committed Oct 7, 2024
1 parent d3c970c commit f2ec267
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ v9.8
(2024-09-21)

Enhancements:
- DietPi-FirstBoot | The network time sync mirror configured in dietpi.txt is now applied before the first time sync is done, instead of after login and initial DietPi update. Many thanks to @bigops for making us aware of this: https://dietpi.com/forum/t/21600
- DietPi-Software | NoMachine: Our install option will now always download the latest NoMachine version, instead of a hardcoded one depending on the DietPi version. Many thanks to @tzvi208 for for figuring it out to version-agnostic download URLs: https://github.com/MichaIng/DietPi/issues/7198
- DietPi-Software | Portainer: It has been enabled to accept private/custom CA certificates by using the trusted CA certificates of the host, instead of the ones shipped with the container image. Many thanks to @oldboys92 for implementing this enhancement: https://github.com/MichaIng/DietPi/pull/7217

Expand Down
4 changes: 1 addition & 3 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -14492,7 +14492,6 @@ _EOF_
local AUTOINSTALL_FILESERVERINDEX=$(sed -n '/^[[:blank:]]*AUTO_SETUP_FILE_SERVER_INDEX=/{s/^[^=]*=//p;q}' /boot/dietpi.txt) # pre-v7.9
local AUTOINSTALL_LOGGINGINDEX=$(sed -n '/^[[:blank:]]*AUTO_SETUP_LOGGING_INDEX=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
AUTOINSTALL_CUSTOMSCRIPTURL=$(sed -n '/^[[:blank:]]*AUTO_SETUP_CUSTOM_SCRIPT_EXEC=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
local AUTOINSTALL_TIMESYNCMODE=$(sed -n '/^[[:blank:]]*CONFIG_NTP_MODE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
local AUTOINSTALL_RESTORE=$(sed -n '/^[[:blank:]]*AUTO_SETUP_BACKUP_RESTORE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
local AUTOINSTALL_RAMLOG_SIZE=$(sed -n '/^[[:blank:]]*AUTO_SETUP_RAMLOG_MAXSIZE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
AUTO_SETUP_DHCP_TO_STATIC=$(grep -cm1 '^[[:blank:]]*AUTO_SETUP_DHCP_TO_STATIC=1' /boot/dietpi.txt)
Expand All @@ -14503,7 +14502,6 @@ _EOF_
[[ $AUTOINSTALL_FILESERVERINDEX ]] || AUTOINSTALL_FILESERVERINDEX=0 # pre-v7.9
[[ $AUTOINSTALL_LOGGINGINDEX ]] || AUTOINSTALL_LOGGINGINDEX=-1
[[ $AUTOINSTALL_CUSTOMSCRIPTURL ]] || AUTOINSTALL_CUSTOMSCRIPTURL=0
[[ $AUTOINSTALL_TIMESYNCMODE ]] || AUTOINSTALL_TIMESYNCMODE=2
[[ $AUTOINSTALL_RESTORE ]] || AUTOINSTALL_RESTORE=0
[[ $AUTOINSTALL_RAMLOG_SIZE ]] || AUTOINSTALL_RAMLOG_SIZE=50

Expand Down Expand Up @@ -14658,7 +14656,7 @@ _EOF_
findmnt /var/log > /dev/null && G_EXEC mount -o remount /var/log

# Set time sync mode if no container system
(( $G_HW_MODEL == 75 )) || /boot/dietpi/func/dietpi-set_software ntpd-mode "$AUTOINSTALL_TIMESYNCMODE"
(( $G_HW_MODEL == 75 )) || /boot/dietpi/func/dietpi-set_software ntpd-mode

# Apply choice and preference system settings
Apply_SSHServer_Choices "$AUTOINSTALL_SSHINDEX"
Expand Down
84 changes: 46 additions & 38 deletions dietpi/func/dietpi-set_software
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $FP_SCRIPT useradd X=create user with name X and default permissions, using g
$FP_SCRIPT apt-mirror <url>|default
$FP_SCRIPT apt clean|reset|cache|lists|archives|compress [enable|disable|ram|disk]
$FP_SCRIPT ntpd-mode [0-4] Time sync modes: 0=custom|1=boot|2=boot+daily|3=boot+hourly|4=daemon+drift
$FP_SCRIPT timesync-mirror Apply network time sync mirror from dietpi.txt
$FP_SCRIPT verify_dietpi.txt Verifies dietpi.txt entries, adds missing entries if required
$FP_SCRIPT passwords NULL=Prompt user to change DietPi related passwords | X=optional set X as global password for future dietpi-software installations and \"root\" + \"dietpi\" login passwords.
$FP_SCRIPT boot_wait_for_network [01] Enable or disable waiting for network interface configuration before DietPi-PostBoot is started, including postboot.d custom scripts and service startups
Expand Down Expand Up @@ -431,52 +432,58 @@ deb $INPUT_MODE_VALUE $G_DISTRO_NAME-backports main contrib non-free' > /etc/apt
#/////////////////////////////////////////////////////////////////////////////////////
# ntpd-mode: Also sets mirror as defined in dietpi.txt CONFIG_NTP_MIRROR
#/////////////////////////////////////////////////////////////////////////////////////
TimeSync_Main()
TimeSync_Mirror()
{
if [[ ! $INPUT_MODE_VALUE || $INPUT_MODE_VALUE == [0-4] ]]
then
# If no input given, re-apply current dietpi.txt setting, else revert to default mode 2
[[ $INPUT_MODE_VALUE ]] || INPUT_MODE_VALUE=$(sed -n '/^[[:blank:]]*CONFIG_NTP_MODE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
[[ $INPUT_MODE_VALUE ]] || INPUT_MODE_VALUE=2

local ntp_mirror=$(sed -n '/^[[:blank:]]*CONFIG_NTP_MIRROR=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
[[ $ntp_mirror ]] || ntp_mirror='default'
local ntp_mirror=$(sed -n '/^[[:blank:]]*CONFIG_NTP_MIRROR=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
[[ $ntp_mirror ]] || ntp_mirror='default'

# Gateway, auto detect local gateway(s)/router(s) to use as NTP server(s).
if [[ ${ntp_mirror,,} == 'gateway' ]]
# Gateway, auto detect local gateway(s)/router(s) to use as NTP server(s).
if [[ ${ntp_mirror,,} == 'gateway' ]]
then
# Convert mawk output to single line via ORS, remove trailing space afterwards
local gateway=$(ip r l 0/0 | mawk '{print $3}' ORS=' '); gateway=${gateway% }
if [[ $gateway ]]
then
# Convert mawk output to single line via ORS, remove trailing space afterwards
local gateway=$(ip r l 0/0 | mawk '{print $3}' ORS=' '); gateway=${gateway% }
if [[ $gateway ]]
G_DIETPI-NOTIFY 0 "Gateway(s) detected: $gateway, adding as NTP server(s)."
ntp_mirror=$gateway
else
G_DIETPI-NOTIFY 1 'No local gateway detected. Reverting NTP mirror back to system defaults.'
EXIT_CODE=1
ntp_mirror='default'
fi
fi

# Default, lets timesyncd use DHCP server or fallback to debian.pool.ntp.org.
if [[ ${ntp_mirror,,} == 'default' ]]
then
[[ -f '/etc/systemd/timesyncd.conf' ]] && G_EXEC rm /etc/systemd/timesyncd.conf
else
local i ntp_mirror_entry
for i in $ntp_mirror
do
if [[ $i == *'pool.ntp.org' ]]
then
G_DIETPI-NOTIFY 0 "Gateway(s) detected: $gateway, adding as NTP server(s)."
ntp_mirror=$gateway
ntp_mirror_entry+="0.$i 1.$i 2.$i 3.$i "
else
G_DIETPI-NOTIFY 1 'No local gateway detected. Reverting NTP mirror back to system defaults.'
EXIT_CODE=1
ntp_mirror='default'
ntp_mirror_entry+="$i "
fi
fi
done

# Default, lets timesyncd use DHCP server or fallback to debian.pool.ntp.org.
if [[ ${ntp_mirror,,} == 'default' ]]
then
[[ -f '/etc/systemd/timesyncd.conf' ]] && G_EXEC rm /etc/systemd/timesyncd.conf
else
local i ntp_mirror_entry
for i in $ntp_mirror
do
if [[ $i == *'pool.ntp.org' ]]
then
ntp_mirror_entry+="0.$i 1.$i 2.$i 3.$i "
else
ntp_mirror_entry+="$i "
fi
done
# Set mirror
echo -e "[Time]\nNTP=${ntp_mirror_entry% }" > /etc/systemd/timesyncd.conf
fi
}

# Set mirror
echo -e "[Time]\nNTP=${ntp_mirror_entry% }" > /etc/systemd/timesyncd.conf
fi
TimeSync_Main()
{
if [[ ! $INPUT_MODE_VALUE || $INPUT_MODE_VALUE == [0-4] ]]
then
# Apply mirror as well
TimeSync_Mirror

# If no input given, re-apply current dietpi.txt setting, else revert to default mode 2
[[ $INPUT_MODE_VALUE ]] || INPUT_MODE_VALUE=$(sed -n '/^[[:blank:]]*CONFIG_NTP_MODE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
[[ $INPUT_MODE_VALUE == [0-4] ]] || INPUT_MODE_VALUE=2

# Daemon mode: dbus required for timedatectl which users may expect
if [[ $INPUT_MODE_VALUE == 4 ]]
Expand Down Expand Up @@ -897,6 +904,7 @@ deb $INPUT_MODE_VALUE $G_DISTRO_NAME-backports main contrib non-free' > /etc/apt
'apt'|'apt-cache') Apt_Main;; # Pre-v8.4: Backwards compatibility for "apt-cache" => "apt cache"
'useradd') Useradd_Main;;
'ntpd-mode') TimeSync_Main;;
'timesync-mirror') TimeSync_Mirror;;
'allo') Allo_Main;;
'verify_dietpi.txt') Verify_DietPi_Txt;;
'locale') Locale_Main;;
Expand Down
7 changes: 5 additions & 2 deletions rootfs/var/lib/dietpi/services/dietpi-firstboot.bash
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ _EOF_

fi

# Disable serial console if set in dietpi.txt
grep -q '^[[:blank:]]*CONFIG_SERIAL_CONSOLE_ENABLE=0' /boot/dietpi.txt && /boot/dietpi/func/dietpi-set_hardware serialconsole disable

# Regenerate unique Dropbear host keys
local i type
for i in /etc/dropbear/dropbear_*_host_key
Expand All @@ -251,8 +254,8 @@ _EOF_
# Apply SSH password login setting
/boot/dietpi/func/dietpi-set_software disable_ssh_password_logins

# Disable serial console if set in dietpi.txt
grep -q '^[[:blank:]]*CONFIG_SERIAL_CONSOLE_ENABLE=0' /boot/dietpi.txt && /boot/dietpi/func/dietpi-set_hardware serialconsole disable
# Apply network time sync mirror
/boot/dietpi/func/dietpi-set_software timesync-mirror

# Apply forced Ethernet link speed if set in dietpi.txt
/boot/dietpi/func/dietpi-set_hardware eth-forcespeed "$(sed -n '/^[[:blank:]]*AUTO_SETUP_NET_ETH_FORCE_SPEED=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)"
Expand Down

0 comments on commit f2ec267

Please sign in to comment.