a ship of wol
This commit is contained in:
parent
74b7ff99d5
commit
f4227ee3bd
3 changed files with 54 additions and 4 deletions
|
|
@ -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__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue