a ship of wol
This commit is contained in:
parent
74b7ff99d5
commit
f4227ee3bd
3 changed files with 54 additions and 4 deletions
|
|
@ -409,7 +409,7 @@
|
||||||
};
|
};
|
||||||
"bluetooth" = {
|
"bluetooth" = {
|
||||||
format-connected = "| ᛒ";
|
format-connected = "| ᛒ";
|
||||||
format-disconnected = "| ᚧ";
|
format-on = "| ᚧ";
|
||||||
format-no-controllers = "";
|
format-no-controllers = "";
|
||||||
interval = 15;
|
interval = 15;
|
||||||
on-click = "${uwsm} ${term} -e bluetui";
|
on-click = "${uwsm} ${term} -e bluetui";
|
||||||
|
|
|
||||||
|
|
@ -28,5 +28,29 @@
|
||||||
networking.firewall.allowedUDPPorts = [
|
networking.firewall.allowedUDPPorts = [
|
||||||
53
|
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
|
} # end file
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ TARGET_IP = socket.gethostbyname(TARGET_HOSTNAME)
|
||||||
|
|
||||||
def remote_cmd(command):
|
def remote_cmd(command):
|
||||||
print(f"Executing: ssh alisceon@tower.home.the.malice.zone '{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)
|
return (response.returncode, response.stdout, response.stderr)
|
||||||
|
|
||||||
def weboot():
|
def weboot():
|
||||||
|
|
@ -123,6 +123,29 @@ def shutdown():
|
||||||
print("Failed to shut down target")
|
print("Failed to shut down target")
|
||||||
return False
|
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):
|
def action_do(action):
|
||||||
match action:
|
match action:
|
||||||
case "get_os":
|
case "get_os":
|
||||||
|
|
@ -154,6 +177,9 @@ def action_do(action):
|
||||||
else:
|
else:
|
||||||
print("Failed to shutdown")
|
print("Failed to shutdown")
|
||||||
case "winupdate":
|
case "winupdate":
|
||||||
|
if winupdate():
|
||||||
|
print("Windows update commands sent successfully")
|
||||||
|
case "autowin":
|
||||||
if get_os() != "offline":
|
if get_os() != "offline":
|
||||||
print("Target is in use, belaying update 1h")
|
print("Target is in use, belaying update 1h")
|
||||||
time.sleep(3600)
|
time.sleep(3600)
|
||||||
|
|
@ -163,7 +189,7 @@ def action_do(action):
|
||||||
else:
|
else:
|
||||||
print("Failed to boot Windows for update")
|
print("Failed to boot Windows for update")
|
||||||
return
|
return
|
||||||
code, stdout, stderr = remote_cmd("powershell -Command \"& {Install-WindowsUpdate -AcceptAll -AutoReboot}\"")
|
winupdate()
|
||||||
if code == 0:
|
if code == 0:
|
||||||
print("Windows update initiated successfully")
|
print("Windows update initiated successfully")
|
||||||
else:
|
else:
|
||||||
|
|
@ -180,7 +206,7 @@ def action_do(action):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="WOL and reboot utility")
|
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)
|
action_do(parser.parse_args().action)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue