From 91843bf43307fb885b096a8a531b4f842a58e0ae Mon Sep 17 00:00:00 2001 From: Yuuki Galaxy Date: Fri, 29 Jul 2022 04:17:34 +0800 Subject: [PATCH] modified: calamares/etc/local.d/hostself.start --- etc/Server/aconfmgr/11-etcignore.sh | 2 +- etc/Server/aconfmgr/30-root-overlay.sh | 5 ++- etc/Server/aconfmgr/40-setup.sh | 5 +++ .../aconfmgr/calamares/etc/local.d/hostself.start | 44 +++++++++++++++------- 4 files changed, 41 insertions(+), 15 deletions(-) rewrite etc/Server/aconfmgr/calamares/etc/local.d/hostself.start (77%) diff --git a/etc/Server/aconfmgr/11-etcignore.sh b/etc/Server/aconfmgr/11-etcignore.sh index 20edaac8c..2b77352e5 100644 --- a/etc/Server/aconfmgr/11-etcignore.sh +++ b/etc/Server/aconfmgr/11-etcignore.sh @@ -27,7 +27,7 @@ IgnorePath '/var/lib/NetworkManager/*' IgnorePath '/var/lib/random-seed' IgnorePath '/var/lib/sddm/*' IgnorePath '/var/lib/upower/*' -IgnorePath '/var/spool/anacron/*' +IgnorePath '/var/spool/*' IgnorePath '/var/lib/logrotate.status' IgnorePath '/etc/cups/subscriptions.conf*' IgnorePath '/etc/printcap' diff --git a/etc/Server/aconfmgr/30-root-overlay.sh b/etc/Server/aconfmgr/30-root-overlay.sh index 9c6238fb5..2734a22cb 100644 --- a/etc/Server/aconfmgr/30-root-overlay.sh +++ b/etc/Server/aconfmgr/30-root-overlay.sh @@ -12,7 +12,9 @@ QTWEBENGINE_CHROMIUM_FLAGS="-blink-settings=darkModeEnabled=true -enable-feature EOF IgnorePath '/etc/hosts' +IgnorePath '/etc/hosts.*' IgnorePath '/etc/hostname' +IgnorePath '/etc/hostname.*' HostsFile="$(GetPackageOriginalFile filesystem /etc/hosts)" cat >> "$HostsFile" <> "$HostsFile" < /etc/hostname -fi - -if [ -f /etc/hostname ]; then - echo -ne '\n# This host address\n127.0.0.1\t' >> /etc/hosts - cat /etc/hostname >> /etc/hosts - cp --reflink=auto -Pp /etc/hosts /etc/hosts.init -fi - -rm -f $0 +#!/bin/sh + +# https://stackoverflow.com/a/106223/159695 +#Valid952HostnameRegex="^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$" +#ValidHostnameRegex="^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$" +ExHostnameRegEx="[A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]" # Or -P "\w|\w[\w\-]*\w" with extra '_'. +DefaultHostname="GalaxyVM" +if [ ! -s /etc/hostname ]; then + echo "$DefaultHostname" > /etc/hostname +elif ( ! grep -Exq "$ExHostnameRegEx" /etc/hostname ) || (( $(wc -l < /etc/hostname) > 1 )); then + echo "$DefaultHostname" > /etc/hostname +fi +#HostnameSize=$(stat -c%s "/etc/hostname") + +HostsHeader="# This host address" +if ( ! grep -Fxq "$HostsHeader" /etc/hosts.init ); then + echo -e "\n$HostsHeader\n127.0.0.1\t$(cat /etc/hostname)" >> /etc/hosts.init +fi + +if [ -s /etc/hosts ]; then + HostsInitSize=$(stat -c%s "/etc/hosts.init") + HostsSize=$(stat -c%s "/etc/hosts") + if (( HostsInitSize > HostsSize )); then + mv /etc/hosts /etc/hosts.ibak + cp --reflink=auto -Pp /etc/hosts.init /etc/hosts + fi +else + cp --reflink=auto -Pp /etc/hosts.init /etc/hosts +fi + +rm -f $0 -- 2.11.4.GIT