feat: configure RGB colors and flash timing
This commit is contained in:
+34
@@ -47,6 +47,40 @@ if [ -f /etc/pigway-pi-control.conf ]; then
|
||||
else
|
||||
install -m 0644 config/pigway-pi-control.conf /etc/pigway-pi-control.conf
|
||||
fi
|
||||
|
||||
# Preserve the existing file verbatim while exposing newly configurable RGB
|
||||
# defaults. Missing keys are inserted into [led]; existing user values win.
|
||||
python3 - /etc/pigway-pi-control.conf <<'PY'
|
||||
import re,sys
|
||||
from pathlib import Path
|
||||
|
||||
path=Path(sys.argv[1])
|
||||
text=path.read_text()
|
||||
defaults=(
|
||||
("cpu_r",255),("cpu_g",0),("cpu_b",0),
|
||||
("power_r",255),("power_g",40),("power_b",0),
|
||||
("memory_r",255),("memory_g",0),("memory_b",255),
|
||||
("storage_r",255),("storage_g",255),("storage_b",255),
|
||||
("network_r",0),("network_g",0),("network_b",255),
|
||||
("service_r",0),("service_g",255),("service_b",96),
|
||||
("warning_flash_on_ms",1500),("warning_flash_off_ms",1500),
|
||||
("critical_flash_on_ms",750),("critical_flash_off_ms",750),
|
||||
("emergency_flash_on_ms",300),("emergency_flash_off_ms",300),
|
||||
)
|
||||
missing=[(key,value) for key,value in defaults
|
||||
if not re.search(rf"(?m)^\s*{re.escape(key)}\s*=",text)]
|
||||
if missing:
|
||||
block="\n# RGB object colors (0..255) and flash timing (milliseconds).\n"
|
||||
block+="".join(f"{key} = {value}\n" for key,value in missing)
|
||||
match=re.search(r"(?m)^\[led\]\s*$",text)
|
||||
if match:
|
||||
next_section=re.search(r"(?m)^\[.+\]\s*$",text[match.end():])
|
||||
pos=match.end()+(next_section.start() if next_section else len(text)-match.end())
|
||||
text=text[:pos].rstrip()+"\n"+block+"\n"+text[pos:].lstrip("\n")
|
||||
else:
|
||||
text=text.rstrip()+"\n\n[led]\n"+block
|
||||
path.write_text(text)
|
||||
PY
|
||||
install -m 0644 systemd/pigway-pi-control.service /etc/systemd/system/pigway-pi-control.service
|
||||
|
||||
echo "[6/8] 启用/重启服务..."
|
||||
|
||||
Reference in New Issue
Block a user