| ... | @@ -7,6 +7,7 @@ import os | ... | @@ -7,6 +7,7 @@ import os |
| 7 | from pathlib import Path | 7 | from pathlib import Path |
| 8 | import re | 8 | import re |
| 9 | import secrets | 9 | import secrets |
| | 10 | import shlex |
| 10 | import shutil | 11 | import shutil |
| 11 | import signal | 12 | import signal |
| 12 | import stat | 13 | import stat |
| ... | @@ -695,7 +696,9 @@ def linux_seed(directory, username, os_name, serial="ttyS0"): | ... | @@ -695,7 +696,9 @@ def linux_seed(directory, username, os_name, serial="ttyS0"): |
| 695 | fedora = "fedora" in os_name.lower() | 696 | fedora = "fedora" in os_name.lower() |
| 696 | nixos = "nixos" in os_name.lower() | 697 | nixos = "nixos" in os_name.lower() |
| 697 | account_tool = "/run/current-system/sw/bin/" if nixos else "" | 698 | account_tool = "/run/current-system/sw/bin/" if nixos else "" |
| 698 | rename = f'''set -eu | 699 | gdm_config = "/etc/gdm/custom.conf" if fedora or nixos else "/etc/gdm3/custom.conf" |
| | 700 | gdm_content = f"[daemon]\nAutomaticLoginEnable=true\nAutomaticLogin={username}\n" |
| | 701 | personalize = f'''set -eu |
| 699 | old=$({account_tool}getent passwd 1000 | cut -d: -f1) | 702 | old=$({account_tool}getent passwd 1000 | cut -d: -f1) |
| 700 | test -n "$old" | 703 | test -n "$old" |
| 701 | if [ "$old" != {username} ]; then | 704 | if [ "$old" != {username} ]; then |
| ... | @@ -708,10 +711,13 @@ if [ "$old" != {username} ]; then | ... | @@ -708,10 +711,13 @@ if [ "$old" != {username} ]; then |
| 708 | if [ "$({account_tool}getent group 1000 | cut -d: -f1)" = "$old" ]; then {account_tool}groupmod -n {username} "$old"; fi | 711 | if [ "$({account_tool}getent group 1000 | cut -d: -f1)" = "$old" ]; then {account_tool}groupmod -n {username} "$old"; fi |
| 709 | fi | 712 | fi |
| 710 | ''' | 713 | ''' |
| 711 | gdm_config = "/etc/gdm/custom.conf" if fedora or nixos else "/etc/gdm3/custom.conf" | 714 | if fedora: |
| 712 | files = [ | 715 | personalize += "printf '%s' " + shlex.quote(gdm_content) + " > " + shlex.quote(gdm_config) + "\n" |
| 713 | {"path": gdm_config, "content": f"[daemon]\nAutomaticLoginEnable=true\nAutomaticLogin={username}\n"}, | 716 | personalize += '''for service in accounts-daemon.service display-manager.service; do |
| 714 | ] | 717 | if systemctl is-active --quiet "$service"; then systemctl restart "$service"; fi |
| | 718 | done |
| | 719 | ''' |
| | 720 | files = [] if fedora else [{"path": gdm_config, "content": gdm_content}] |
| 715 | if not nixos: | 721 | if not nixos: |
| 716 | files.insert(0, {"path": "/etc/ssh/sshd_config.d/00-snowglobe.conf", "permissions": "0600", "content": "PasswordAuthentication yes\nPermitRootLogin yes\n"}) | 722 | files.insert(0, {"path": "/etc/ssh/sshd_config.d/00-snowglobe.conf", "permissions": "0600", "content": "PasswordAuthentication yes\nPermitRootLogin yes\n"}) |
| 717 | else: | 723 | else: |
| ... | @@ -729,7 +735,8 @@ fi | ... | @@ -729,7 +735,8 @@ fi |
| 729 | computer_setup = [["/run/current-system/sw/bin/bash", "-lc", "nix-env --profile /var/lib/snowglobe/computer -if /var/lib/snowglobe/computer.nix"]] | 735 | computer_setup = [["/run/current-system/sw/bin/bash", "-lc", "nix-env --profile /var/lib/snowglobe/computer -if /var/lib/snowglobe/computer.nix"]] |
| 730 | config = { | 736 | config = { |
| 731 | "users": [], "disable_root": False, "ssh_pwauth": True, "ssh_deletekeys": True, | 737 | "users": [], "disable_root": False, "ssh_pwauth": True, "ssh_deletekeys": True, |
| 732 | "bootcmd": ([["rm", "-f", gdm_config]] if nixos else []) + [["sh", "-c", rename]], | 738 | "bootcmd": ([["rm", "-f", gdm_config]] if nixos else []) + [ |
| | 739 | (["cloud-init-per", "instance", "snowglobe-desktop"] if fedora else []) + ["sh", "-c", personalize]], |
| 733 | "chpasswd": {"expire": False, "users": [{"name": user, "password": hashed, "type": "hash"} for user in [username, "root"]]}, | 740 | "chpasswd": {"expire": False, "users": [{"name": user, "password": hashed, "type": "hash"} for user in [username, "root"]]}, |
| 734 | "write_files": files, | 741 | "write_files": files, |
| 735 | "runcmd": [["systemctl", "enable", "--now", "sshd" if fedora or nixos else "ssh"], ["systemctl", "enable", "--now", f"serial-getty@{serial}.service"]] + computer_setup, | 742 | "runcmd": [["systemctl", "enable", "--now", "sshd" if fedora or nixos else "ssh"], ["systemctl", "enable", "--now", f"serial-getty@{serial}.service"]] + computer_setup, |