a ship of wol

This commit is contained in:
alisceon 2026-01-30 18:56:08 +01:00
parent 74b7ff99d5
commit f4227ee3bd
3 changed files with 54 additions and 4 deletions

View file

@ -409,7 +409,7 @@
};
"bluetooth" = {
format-connected = "| ";
format-disconnected = "| ";
format-on = "| ";
format-no-controllers = "";
interval = 15;
on-click = "${uwsm} ${term} -e bluetui";

View file

@ -28,5 +28,29 @@
networking.firewall.allowedUDPPorts = [
53
];
systemd = {
timers = {
"autowin" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "Wed *-*-21..28 02:00:00";
Unit = "autowin.service";
};
};
}; # end timers
services = {
"autowin" = {
script = ''
${pkgs.python3Packages.python}/bin/python /home/alisceon/.nixos_config/util/wol_man.py autowin
'';
serviceConfig = {
Type = "oneshot";
TimeoutStartSec = "3600";
User = "alisceon";
};
}; # end "hello-world"
}; # end services
}; # end systemd
} # end file

View file

@ -12,7 +12,7 @@ TARGET_IP = socket.gethostbyname(TARGET_HOSTNAME)
def remote_cmd(command):
print(f"Executing: ssh alisceon@tower.home.the.malice.zone '{command}'")
response = subprocess.run(f"ssh tower '{command}'", shell=True, capture_output=True, text=True)
response = subprocess.run(f"ssh tower -o 'StrictHostKeyChecking no' '{command}'", shell=True, capture_output=True, text=True)
return (response.returncode, response.stdout, response.stderr)
def weboot():
@ -123,6 +123,29 @@ def shutdown():
print("Failed to shut down target")
return False
def winupdate() :
print("Starting Windows Update process")
if get_os() != "windows":
print("Target is not running Windows, cannot update")
return False
code, stdout, stderr = remote_cmd('powershell -Command "Start-Service wuauserv"')
if code != 0:
raise RuntimeError(f"Failed to start Windows Update service: {stderr}")
time.sleep(30)
code, stdout, stderr = remote_cmd('powershell -Command "UsoClient StartScan"')
if code != 0:
raise RuntimeError(f"Failed to start Windows Update scan: {stderr}")
time.sleep(300)
code, stdout, stderr = remote_cmd('powershell -Command "UsoClient StartDownload"')
if code != 0:
raise RuntimeError(f"Failed to start Windows Update download: {stderr}")
time.sleep(600)
code, stdout, stderr = remote_cmd('powershell -Command "UsoClient StartInstall"')
if code != 0:
raise RuntimeError(f"Failed to start Windows Update installation: {stderr}")
time.sleep(1800)
return True
def action_do(action):
match action:
case "get_os":
@ -154,6 +177,9 @@ def action_do(action):
else:
print("Failed to shutdown")
case "winupdate":
if winupdate():
print("Windows update commands sent successfully")
case "autowin":
if get_os() != "offline":
print("Target is in use, belaying update 1h")
time.sleep(3600)
@ -163,7 +189,7 @@ def action_do(action):
else:
print("Failed to boot Windows for update")
return
code, stdout, stderr = remote_cmd("powershell -Command \"& {Install-WindowsUpdate -AcceptAll -AutoReboot}\"")
winupdate()
if code == 0:
print("Windows update initiated successfully")
else:
@ -180,7 +206,7 @@ def action_do(action):
def main():
parser = argparse.ArgumentParser(description="WOL and reboot utility")
parser.add_argument("action", choices=["get_os", "boot_linux", "boot_windows", "swap_os", "reboot", "shutdown", "winupdate"], help="Action to perform")
parser.add_argument("action", choices=["get_os", "boot_linux", "boot_windows", "swap_os", "reboot", "shutdown", "winupdate", "autowin"], help="Action to perform")
action_do(parser.parse_args().action)
if __name__ == "__main__":