Generate random hostname. One less thing to ask the user.
This commit is contained in:
parent
aac1b4ae2a
commit
436d299588
@ -132,7 +132,7 @@ user:
|
|||||||
# always contains "localhost", but may list others that are unsuitable
|
# always contains "localhost", but may list others that are unsuitable
|
||||||
# or broken in special ways.
|
# or broken in special ways.
|
||||||
hostname:
|
hostname:
|
||||||
location: Transient
|
location: None
|
||||||
writeHostsFile: false
|
writeHostsFile: false
|
||||||
forbidden_names: [ localhost ]
|
forbidden_names: [ localhost ]
|
||||||
|
|
||||||
|
|||||||
@ -8,10 +8,12 @@
|
|||||||
# Calamares is Free Software: see the License-Identifier above.
|
# Calamares is Free Software: see the License-Identifier above.
|
||||||
#
|
#
|
||||||
|
|
||||||
import libcalamares
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
import re
|
import re
|
||||||
|
import secrets
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import libcalamares
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
_ = gettext.translation("calamares-python",
|
_ = gettext.translation("calamares-python",
|
||||||
@ -19,6 +21,35 @@ _ = gettext.translation("calamares-python",
|
|||||||
languages=libcalamares.utils.gettext_languages(),
|
languages=libcalamares.utils.gettext_languages(),
|
||||||
fallback=True).gettext
|
fallback=True).gettext
|
||||||
|
|
||||||
|
def random_hostname():
|
||||||
|
adjectives = [
|
||||||
|
"autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark", "summer",
|
||||||
|
"icy", "delicate", "quiet", "white", "cool", "spring", "winter", "patient",
|
||||||
|
"twilight", "dawn", "crimson", "wispy", "weathered", "blue", "billowing",
|
||||||
|
"broken", "cold", "damp", "falling", "frosty", "green", "long", "late", "lingering",
|
||||||
|
"bold", "little", "morning", "muddy", "old", "red", "rough", "still", "small",
|
||||||
|
"sparkling", "thrumming", "shy", "wandering", "withered", "wild", "black",
|
||||||
|
"young", "holy", "solitary", "fragrant", "aged", "snowy", "proud", "floral",
|
||||||
|
"restless", "divine", "polished", "ancient", "purple", "lively", "nameless"
|
||||||
|
]
|
||||||
|
|
||||||
|
nouns = [
|
||||||
|
"waterfall", "river", "breeze", "moon", "rain", "wind", "sea", "morning",
|
||||||
|
"snow", "lake", "sunset", "pine", "shadow", "leaf", "dawn", "glitter", "forest",
|
||||||
|
"hill", "cloud", "meadow", "sun", "glade", "bird", "brook", "butterfly",
|
||||||
|
"bush", "dew", "dust", "field", "fire", "flower", "firefly", "feather", "grass",
|
||||||
|
"haze", "mountain", "night", "pond", "darkness", "snowflake", "silence",
|
||||||
|
"sound", "sky", "shape", "surf", "thunder", "violet", "water", "wildflower",
|
||||||
|
"wave", "water", "resonance", "sun", "log", "dream", "cherry", "tree", "fog",
|
||||||
|
"frost", "voice", "paper", "frog", "smoke", "star"
|
||||||
|
]
|
||||||
|
|
||||||
|
adjective = secrets.choice(adjectives)
|
||||||
|
noun = secrets.choice(nouns)
|
||||||
|
number = secrets.randbelow(10_000)
|
||||||
|
|
||||||
|
return f"{adjective}-{noun}-{number}"
|
||||||
|
|
||||||
configuration_head = """
|
configuration_head = """
|
||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
@ -33,7 +64,6 @@ configuration_body = """
|
|||||||
boot.loader.systemd-boot.enable = true;
|
boot.loader.systemd-boot.enable = true;
|
||||||
boot.loader.efi.canTouchEfiVariables = true;
|
boot.loader.efi.canTouchEfiVariables = true;
|
||||||
|
|
||||||
networking.hostName = "@@hostname@@";
|
|
||||||
networking.networkmanager.enable = true;
|
networking.networkmanager.enable = true;
|
||||||
|
|
||||||
services.xserver.enable = true;
|
services.xserver.enable = true;
|
||||||
@ -71,6 +101,10 @@ configuration_body = """
|
|||||||
nixpkgs.config.allowUnfree = true;
|
nixpkgs.config.allowUnfree = true;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
cfghostname = f"""
|
||||||
|
networking.hostName = "{random_hostname()}";
|
||||||
|
"""
|
||||||
|
|
||||||
cfgtime = """
|
cfgtime = """
|
||||||
time.timeZone = "@@timezone@@";
|
time.timeZone = "@@timezone@@";
|
||||||
"""
|
"""
|
||||||
@ -139,6 +173,7 @@ def catenate(d, key, *values):
|
|||||||
|
|
||||||
d[key] = "".join(values)
|
d[key] = "".join(values)
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
"""Desk OS Configuration."""
|
"""Desk OS Configuration."""
|
||||||
|
|
||||||
@ -168,10 +203,7 @@ def run():
|
|||||||
status = _("Configuring Desk OS")
|
status = _("Configuring Desk OS")
|
||||||
libcalamares.job.setprogress(0.18)
|
libcalamares.job.setprogress(0.18)
|
||||||
|
|
||||||
if (gs.value("hostname") is None):
|
cfg += cfghostname
|
||||||
catenate(variables, "hostname", "desk-os")
|
|
||||||
else:
|
|
||||||
catenate(variables, "hostname", gs.value("hostname"))
|
|
||||||
|
|
||||||
if (gs.value("locationRegion") is not None and gs.value("locationZone") is not None):
|
if (gs.value("locationRegion") is not None and gs.value("locationZone") is not None):
|
||||||
cfg += cfgtime
|
cfg += cfgtime
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user