ghostbsd / issues

Issue tracker for GhostBSD
BSD 2-Clause "Simplified" License
3 stars 1 forks source link

For GBI, X keyboard was set correctly but did not set keymap correctly in /etc/rc.conf. #188

Open vimanuelt opened 1 week ago

vimanuelt commented 1 week ago

Describe the feature or enhancement.

Keyboard for console needs to be consistent with X Window keyboard setting. It seems since X Window keyboard setting is created by pc-sysinstall reading the cfg file, it would seem trivial to have pc-sysinstall to read the same file and set the keyboard setting for the console.

Here's an example.

import os import subprocess

Path to the pc-sysinstall.cfg file

CONFIG_FILE = "/path/to/pc-sysinstall.cfg"

def read_keymap(config_file): """ Reads the keymap value from the pc-sysinstall.cfg file. """ if not os.path.exists(config_file): print(f"Error: Configuration file not found at {config_file}.") return None

with open(config_file, 'r') as file:
    for line in file:
        if line.startswith("keymap="):
            return line.split('=', 1)[1].strip()
print("Error: No keymap value found in the configuration file.")
return None

def set_keymap_rcconf(keymap): """ Sets or replaces the keymap in /etc/rc.conf. """ rcconf_path = "/etc/rc.conf" keymap_entry = f'keymap="{keymap}"'

# Read the contents of /etc/rc.conf
if not os.path.exists(rcconf_path):
    print(f"Error: {rcconf_path} does not exist.")
    return

with open(rcconf_path, 'r') as file:
    lines = file.readlines()

# Check for an existing keymap line and replace it
updated = False
for i, line in enumerate(lines):
    if line.startswith("keymap="):
        lines[i] = keymap_entry + "\n"
        updated = True
        break

# If no existing keymap line, append a new one
if not updated:
    lines.append(keymap_entry + "\n")

# Write the updated lines back to /etc/rc.conf
with open(rcconf_path, 'w') as file:
    file.writelines(lines)

print(f"Keymap '{keymap}' set in /etc/rc.conf.")

def apply_keymap(keymap): """ Applies the keymap immediately using kbdcontrol. """ keymap_path = f"/usr/share/syscons/keymaps/{keymap}.kbd" if os.path.exists(keymap_path): try: subprocess.run(["kbdcontrol", "-l", keymap_path], check=True) print(f"Keymap '{keymap}' applied successfully.") except subprocess.CalledProcessError as e: print(f"Error: Failed to apply keymap: {e}") else: print(f"Warning: Keymap file '{keymap_path}' not found. Keymap not applied.")

def main(): keymap = read_keymap(CONFIG_FILE) if keymap: set_keymap_rcconf(keymap) apply_keymap(keymap)

if name == "main": main()

Why this request?

This feature improves user experience. User does not need to set this manually.