-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_upgrade_input.py
More file actions
80 lines (67 loc) · 3.82 KB
/
cli_upgrade_input.py
File metadata and controls
80 lines (67 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# CLI Upgrade Script (Input Version)
# Initially written by Jacob F. (https://www.github.com/FiveEyeTea) on 1/5/2026.
# This Python script allows a user to check for upgrades with either Winget or Chocolatey (or both). If any updates are detected in the checks, the script will run the full upgrade commands for whichever package manager(s) the user selected.
# NOTE: Winget and Chocolatey must be installed and properly set up before using.
# Chocolatey portion of the script only upgrades software installed with Chocolatey.
# Winget portion will attempt to upgrade all software on the system, provided it's compatible with Winget.
# Script header
print("CLI Upgrade Script by Jacob F. (https://www.github.com/FiveEyeTea)")
# Checks user input to determine which of the package managers should be used.
while True:
user_choice = input("\nWhich package manager do you want to use? Select a number... \n\n[1] Winget\n[2] Chocolatey\n[3] Both\n[X] Cancel upgrade\n\n")
# Initiates the subprocess module for the run statements. Crucial for running all the winget/choco commands within the CLI itself.
from asyncio import subprocess
from subprocess import run
# These variables are the commands for the initial checks. Later in the script, they run those commands and store a return code that is used to decide if the full upgrade variables will initiate.
winget_check = ["winget", "upgrade"]
choco_check = ["choco", "upgrade", "all", "-n"]
# These variables are the upgrade command processes for the package managers. They only activate if updates are found.
winget_upgrade = ["winget", "upgrade", "--all"]
choco_upgrade = ["choco", "upgrade", "all", "-y"]
# This portion of the script first initiates a "dry run", which doesn't actually upgrade anything.
# The checks are run based on what the user selected in the initial user_choice input prompt.
# If updates are found with the selected package manager(s), the correct upgrade variable(s) will initiate.
if user_choice == "1":
winget_check = run(winget_check, text=True)
if winget_check.returncode == 0:
print("\nWinget upgrades available. Running now...\n")
run(winget_upgrade, text=True)
elif winget_check.returncode == 1:
print("\nNo applicable Winget upgrades found.\n")
else:
print("ERROR: No return code specified.")
break
elif user_choice == "2":
choco_check = run(choco_check, text=True)
if choco_check.returncode == 1:
print("\nChocolatey upgrades available. Running now...\n")
run(choco_upgrade, text=True)
elif choco_check.returncode == 0:
print("\nNo applicable Chocolatey upgrades found.\n")
else:
print("ERROR: No return code specified.")
break
elif user_choice == "3":
winget_check = run(winget_check, text=True)
choco_check = run(choco_check, text=True)
if winget_check.returncode == 0:
print("\nWinget upgrades available. Running now...\n")
run(winget_upgrade, text=True)
elif winget_check.returncode == 1:
print("\nNo applicable Winget upgrades found.\n")
else:
print("ERROR: No return code specified.")
if choco_check.returncode == 1:
print("\nChocolatey upgrades available. Running now...\n")
run(choco_upgrade, text=True)
elif choco_check.returncode == 0:
print("\nNo applicable Chocolatey upgrades found.\n")
else:
print("ERROR: No return code specified.")
break
elif user_choice == "X" or user_choice == "x":
print("Upgrade canecelled. You may exit this terminal.")
break
else:
print("Invalid input. Please respond with [1], [2], [3], or [X].")
continue