-
Notifications
You must be signed in to change notification settings - Fork 1
/
fupdate.py
838 lines (669 loc) · 30.2 KB
/
fupdate.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
import os
import re
import semver
import requests
import json
from termcolor import colored
import urllib.parse
import subprocess
import argparse
#https://gist.github.com/sylvainpelissier/ff072a6759082590a4fe8f7e070a4952
import pyuac
"""
1. Get list of all outdated packages
2. If a package has upgraded a major version number, show changelog
3. "Do you want to updated X packages? [Y/n]: "
4. Update everything
"""
parser = argparse.ArgumentParser(
prog = 'fupdate.py',
description = 'Updates packages and gets their changelogs. Supports Chocolatey, pip, python venvs, gup and git clones.'
)
parser.add_argument("--dev-mode", action='store_true')
args = parser.parse_args()
devMode = args.dev_mode
######################################################################################
# USER CUSTOMIZABLE SETTINGS
######################################################################################
versionNotificationSettings={
"Major Versions": True,
"Minor Versions": True,
"Patch Versions": False
}
colorSettings = {
"Major Versions": "green",
"Minor Versions": "cyan",
}
generalUpgradeSettings={
"gup": True,
"pip": True,
"pipVenvs": True,
"git": True,
"choco": True
# "npm": True
}
######################################################################################
# USER MODIFIYABLE FUNCTIONS ARE AT THE BOTTOM OF THE FILE
######################################################################################
# npm support is disabled until they fix `npm outdated -g`
# https://github.com/npm/cli/issues/6098
numberOfMajorUpgrades = 0
numberOfMinorUpgrades = 0
numberOfPatchUpgrades = 0
def error(message):
print(colored("\tERROR: ", "red") + message + "\n")
def warning(message):
print(colored("\tWARNING: ", "yellow") + message +"\n")
def info(message):
print("[+] " + message)
if not pyuac.isUserAdmin():
error("Admin privileges are needed!")
exit()
# Setup githubtoken
try:
githubToken = os.environ["fupdate-github-token"]
except KeyError:
warning("No github token detected. Please set the environment variable " + colored("fupdate-github-token", "yellow") + " to your github personal access token. Without it, we can't fetch the changelogs.")
githubToken = ""
def stripLeadingV(version):
"""Receives a function like \"v1.0.0\" and removes the trailing v\n
EXAMPLE: \"v1.0.0\" -> \"1.0.0\""""
if version.startswith("v"):
return version[1:]
else:
return version
def forceSemver(version: str):
"""Recieves a string that should ressemble a semver. This function would convert:
\"v3.5\" -> \"3.5.0\"
\"3.0\" -> \"3.0.0\""""
try:
version = semver.VersionInfo.parse(version)
return [version, False]
except ValueError:
#Strip leading v
if version.startswith("v"):
version = version[1:]
versionSplit = version.split(".")
for index, versionSegment in enumerate(versionSplit):
try:
number = int(versionSegment)
#This is done to deal with the edge case of individual versions having leading ceros and other non-int shenanigans
versionSplit[index] = str(number)
except ValueError:
error("Unable to parse " + colored(version, "yellow") + " as a Semantic Version (See: https://semver.org)")
return [None, Exception]
#Join the version fragments putting a dot between each item
version = ".".join(versionSplit)
if len(versionSplit) == 2:
version = version + ".0"
version = semver.VersionInfo.parse(version)
elif len(versionSplit) != 3:
return [None, Exception]
version = semver.VersionInfo.parse(version)
return [version, True]
def parseVersions(newVersion: str, oldVersion: str, package: str, manager: str) -> list[bool, bool]:
"""Recieves the raw version strings, parses them, outputs a fancy message depending on the notificationSettings\n
First bool: if the newVersion is newer than oldVersion\n
Second bool: if newVersion is newer than oldVersion, but depending on the notificationSettings"""
global numberOfMajorUpgrades
global numberOfMinorUpgrades
global numberOfPatchUpgrades
newVersion = stripLeadingV(newVersion)
oldVersion = stripLeadingV(oldVersion)
# Parse versions that don't comply with semantic versioning
semverNewVersion = forceSemver(newVersion)
semverOldVersion = forceSemver(oldVersion)
if semverNewVersion[1] == Exception or semverOldVersion[1] == Exception:
return [False, False]
semverNewVersion = semverNewVersion[0]
semverOldVersion = semverOldVersion[0]
if(semverNewVersion > semverOldVersion):
if(semverNewVersion.major > semverOldVersion.major):
print(colored("NEW MAJOR VERSION: ", colorSettings["Major Versions"]) + colored("(" + manager + ") ", "yellow") + package + " (" + oldVersion + " to " + newVersion + ")")
numberOfMajorUpgrades += 1
return [True, versionNotificationSettings["Major Versions"]]
elif(semverNewVersion.minor > semverOldVersion.minor):
print(colored("New minor version: ", colorSettings["Minor Versions"]) + colored("(" + manager + ") ", "yellow") + package + " (" + oldVersion + " to " + newVersion + ")")
numberOfMinorUpgrades += 1
return [True, versionNotificationSettings["Minor Versions"]]
else:
print("New patch version: " + colored("(" + manager + ") ", "yellow") + package + " (" + oldVersion + " to " + newVersion + ")")
numberOfPatchUpgrades += 1
return [True, versionNotificationSettings["Patch Versions"]]
elif devMode:
print(package + " " + oldVersion + "==" + newVersion)
return [False,False]
def getLatestGithubRelease(repoURL: urllib.parse.ParseResult | str) -> str:
if not isinstance(repoURL, urllib.parse.ParseResult):
try:
repoURL = urllib.parse.urlparse(repoURL)
except:
return colored("\tFATAL ERROR [001]: ", "red") + "The github source code URL " + colored(repoURL, "yellow") + " was malformed.\n"
if githubToken != "":
pathList = (repoURL.path[1:]).split("/")
pathListLen = len(pathList)
if pathList[1].endswith(".git"):
pathList[1] = (pathList[1])[:-4]
#Normally pathListLen would always be equal to 2, but in the rare case where someone put the URL as (for example) "https://github.com/username/repo/", the len will be three, because of that extra slash at the end. This is also done to prevent potential CSRF or token leaks
if (pathListLen == 2 or
(pathListLen == 3 and (pathList[2] == "json" or (pathList[2]).startswith("v"))) or #Idk what this is for
(pathListLen == 4 and pathList[3] == "latest") #Some go packages end with v2, v3, etc.
):
#/repos/{owner}/{repo}/releases/latest
url = "https://api.github.com/repos/" + pathList[0] + "/" + pathList[1] + "/releases/latest"
else:
error = colored("\tFATAL ERROR [002]: ", "red") + "The github source code URL " + colored(repoURL, "yellow") + " was malformed.\n"
print(error)
return error
headers = {"Accept": "application/vnd.github+json", "Authorization": "Bearer " + githubToken, "X-GitHub-Api-Version": "2022-11-28"}
#TODO: Error handling and throttling
response = requests.get(url, headers=headers)
responseJSON = json.loads(response.text)
try:
return (responseJSON["tag_name"])
except:
return colored("ERROR: ", "red") + "This version does not exist: " + colored(url,"yellow")
def getGithubChangelog(repoURL: urllib.parse.ParseResult | str, version):
if githubToken != "":
version = stripLeadingV(version)
if not isinstance(repoURL, urllib.parse.ParseResult):
try:
originalRepoURL = repoURL
repoURL = urllib.parse.urlparse(repoURL)
except:
return colored("\tFATAL ERROR [003]: ", "red") + "The github source code URL " + colored(repoURL, "yellow") + " was malformed.\n"
pathList = (repoURL.path[1:]).split("/")
pathListLen = len(pathList)
#Normally pathListLen would always be equal to 2, but in the rare case where someone put the URL as (for example) "https://github.com/username/repo/", the len will be three, because of that extra slash at the end. This is also done to prevent potential CSRF or token leaks
if (pathListLen == 2 or
(pathListLen == 3 and (pathList[2] == "json" or (pathList[2]).startswith("v")) or #Idk what this is for
(pathListLen == 4 and pathList[3] == "latest") or #Some go packages end with v2, v3, etc.
(pathListLen >= 3 and pathList[2] == "releases")) # Deal with "https://github.com/Ryochan7/DS4Windows/releases/tag/3.3.3"
):
latestVersion = getLatestGithubRelease("https://github.com/" + pathList[0] + "/" + pathList[1])
if latestVersion.startswith("v"):
version = "v" + version
#Strip the ".git" from the end of the url
if pathList[1].endswith(".git"):
pathList[1] = (pathList[1])[:-4]
url = "https://api.github.com/repos/" + pathList[0] + "/" + pathList[1] + "/releases/tags/" + version
else:
return colored("\tFATAL ERROR [004]: ", "red") + "The github source code URL " + colored(repoURL, "yellow") + " was malformed.\n"
headers = {"Accept": "application/vnd.github+json", "Authorization": "Bearer " + githubToken, "X-GitHub-Api-Version": "2022-11-28"}
#TODO: Error handling and throttling
response = requests.get(url, headers=headers)
responseJSON = json.loads(response.text)
try:
return responseJSON["body"]
except KeyError:
url = "https://api.github.com/repos/" + pathList[0] + "/" + pathList[1] + "/tags"
response = requests.get(url, headers=headers)
responseJSON = json.loads(response.text)
try:
if responseJSON[0]["name"] == version or (forceSemver(responseJSON[0]["name"]))[0] == version:
return colored("\tWARNING: ", "yellow") + "The repository " + colored(originalRepoURL, "yellow") + " has tags with no releases notes associated to them"
else:
return colored("\tERROR: ", "red") + colored(originalRepoURL, "yellow") + " has no associated tag/release " + colored(version, "yellow")
except KeyError:
return colored("\tERROR: ", "red") + "Unable to get changelog API URL: " + colored(url,"yellow")
def fancyChangelogPrint(changelog: str):
changelog = changelog.strip()
for line in changelog.splitlines():
print("\t| " + line)
print("")
def getPypiChangelog(package, newVersion):
url = "https://pypi.org/pypi/" + package + "/json"
#TODO: Error handling and throttling
response = requests.get(url)
responseJSON = json.loads(response.text)
if response.status_code != 200:
error("Pypi API error. Got status code " + colored(str(response.status_code), "yellow") + " for URL " + colored(url, "yellow"))
else:
try:
sourceCodeURL = responseJSON["info"]["project_urls"]["Source"]
sourceCodeURL = urllib.parse.urlparse(sourceCodeURL)
if sourceCodeURL.hostname == "github.com":
return getGithubChangelog(sourceCodeURL, newVersion)
else:
return "\t" + warning("Unable to fetch changelog for " + colored(package, "yellow") + ". The source code was not hosted on github.")
except KeyError:
#TODO: Add an option to allow the user to fill in the source code site
return "\t" + warning("Unable to get source code site for the " + colored(package, "yellow") + " pypi package.")
def gupCheckForUpgrades(gupOutput):
"""gupOutput = The output of \"gup check\""""
packages = []
for line in gupOutput:
line = line.strip()
if ("check binary under $GOPATH/bin or $GOBIN" not in line
and line != "\n"
and "$ gup update" not in line
and "If you want to update binaries, run the following command." not in line
and len(line) != 0):
if "ERROR" in line:
error("Unable to get gup updates")
exit()
elif "Already up-to-date" not in line:
packagelist = re.findall(r"\].+\(", line)
package = packagelist[0]
package = package[2:-2]
versionList = re.findall(r"\(.*\)", line)
newVersion = ((re.findall(r"latest: .*\)", versionList[0]))[0])[8:-1]
oldVersion = ((re.findall(r"current: .*,", versionList[0]))[0])[9:-1]
# If a new version is available...
result = parseVersions(newVersion, oldVersion, package, "gup")
if result[0]:
packages.append(package)
if result[1]:
if package.startswith("github.com"):
changelog = getGithubChangelog("https://" + package, newVersion)
if changelog.startswith("\tERROR"):
print(changelog)
else:
fancyChangelogPrint(changelog)
else:
print("You must manually check the release notes for: " + package)
return packages
# This function receives the output of "pip list --outdated" and a whitelist of which programs to update
def pipIsUpdateAvailable(pipOutput, pipWhitelistedPackages):
"""pipOutput is the output of \"pip list --outdated\"\n
pipWhitelistedPackages is the list of packages that will be updated\n
This function returns an array of the upgradeable packages
"""
upgradeablePackages=[]
for line in pipOutput[2:]:
package = re.findall(r"^([^\s]+)", line)
package = package[0]
if package in pipWhitelistedPackages:
# Regex magic
oldVersion = re.sub(package + "( )+", "", line)
newVersion = oldVersion
oldVersion = re.findall("^([^\s]+)", oldVersion)
newVersion = re.sub(oldVersion[0] + "( )+", "", newVersion)
newVersion = re.findall("^([^\s]+)", newVersion)
# List to string
newVersion = newVersion[0]
oldVersion = oldVersion[0]
# If a new version is available...
result = parseVersions(newVersion, oldVersion, package, "pip")
if result[0]:
upgradeablePackages.append(package)
if result[1]:
try:
changelog = getPypiChangelog(package, newVersion)
if changelog.startswith("\tWARNING"):
print(changelog)
else:
fancyChangelogPrint(changelog)
except:
# If getPypiChangelog returned an error...
continue
return upgradeablePackages
def pipUpgradeVenvs(pathToVenv, packageToUpgrade):
stream = os.popen("cd " + pathToVenv +"\Scripts & activate & pip list --outdated")
pipOutput = stream.readlines()
pipWhitelistedPackages = [packageToUpgrade]
upgradeable = pipIsUpdateAvailable(pipOutput, pipWhitelistedPackages)
if len(upgradeable) == 1:
return [pathToVenv, packageToUpgrade]
else:
return []
def checkGitRepoUpgrade(path: str) -> bool:
"""Recieves the folder path of a github cloned repo.\n
Returns True if an update is available for the supplied repo"""
stream = os.popen("cd " + path + " && git describe --tags")
oldVersion = stream.readlines()
oldVersion = (oldVersion[0]).strip()
oldVersion = re.sub(r"-[0-9]+-([A-z]|[0-9])+", "", oldVersion)
stream = os.popen("cd " + path + " && git config --get remote.origin.url")
remote = stream.readlines()
remote = (remote[0]).strip()
remote = urllib.parse.urlparse(remote)
# Parse URL
pathList = (remote.path[1:]).split("/")
pathListLen = len(pathList)
#Normally pathListLen would always be equal to 2, but in the rare case where someone put the URL as (for example) "https://github.com/username/repo/", the len will be three, because of that extra slash at the end. This is also done to prevent potential CSRF or token leaks
if pathListLen == 2 or (pathListLen == 3 and pathList[2] == ""):
package = pathList[0] + "/" + pathList[1]
if githubToken != "":
newVersion = getLatestGithubRelease(remote)
result = parseVersions(newVersion, oldVersion, package, "git")
if result[1]:
package = pathList[0] + "/" + pathList[1]
url = "https://github.com/" + pathList[0] + "/" + pathList[1]
changelog = getGithubChangelog(url, newVersion)
print(changelog + "\n")
return result[0]
else:
warning("The github remote URL for " + colored(package, "yellow") + " is in an unsupported format: " + colored(remote, "yellow"))
# Given `choco info package-name-here` output like:
""" Chocolatey v1.3.1
dotnet-desktopruntime 8.0.0 [Approved]
Title: Microsoft .NET Desktop Runtime | Published: 2023-11-14
Package approved as a trusted package on Nov 15 2023 12:48:59.
Package testing status: Passing on Nov 14 2023 19:24:22.
Number of Downloads: 566052 | Downloads for this version: 43176
Package url
Chocolatey Package Source: https://github.com/dotnetcore-chocolatey/dotnetcore-chocolateypackages/tree/master/dotnet-desktopruntime
Package Checksum: 'nP759FPhd4FKlu1S0fDOoopSPK62qbi4LB23FQA+P2IBuaqVSc1okMThVKLFz/RbzpNo5bQsISbzXEGFhY6gUw==' (SHA512)
Tags: microsoft .net core runtime redistributable
Software Site: https://dot.net/core
Software License: https://rawcdn.githack.com/dotnet/core/290743955c7dec3315e72da5dcd589b2bd177e71/LICENSE
Documentation: https://docs.microsoft.com/dotnet
Issues: https://www.microsoft.com/net/support
Summary: This package is required to run Windows Desktop applications with the .NET Runtime.
Description: .NET Core is a general purpose development platform maintained by Microsoft and the .NET community on GitHub. It is cross-platform, supporting Windows, macOS and Linux, and can be used in device, cloud, and embedded/IoT scenarios.
This package is required to run Windows Desktop applications with the .NET Runtime.
This is a *metapackage*, which installs the latest release of .NET Desktop Runtime across all versions.
Release Notes: ##### Software
[.NET 8.0.0 Release Notes](https://github.com/dotnet/core/blob/main/release-notes/8.0/8.0.0/8.0.0.md)
1 packages found. """
# This function would return only the text:
""" Release Notes: ##### Software
[.NET 8.0.0 Release Notes](https://github.com/dotnet/core/blob/main/release-notes/8.0/8.0.0/8.0.0.md)
1 packages found. """
def extractReleaseNotesFromChocoInfo(packageInfo: list[str], titleLineIndex: int) -> str:
changelog = "\n".join(packageInfo[titleLineIndex:-1])
return changelog
def chocoCheckForUpgrades(chocoOutput: str) -> list[str]:
"""Receives the raw output of \"choco outdated\""""
chocoUpgradeablePackages = []
chocoOutput = chocoOutput[4:-3]
for line in chocoOutput:
line = line.split("|")
if not line[0].endswith(".install"):
try:
result = parseVersions(line[2], line[1], line[0], "choco")
except IndexError:
error("Unable to parse chocolatey output")
error(line)
exit()
if result[0]:
chocoUpgradeablePackages.append(line[0])
if result[1]:
stream = os.popen("choco info " + line[0])
packageInfo = stream.readlines()
#Found the release notes,
#[True|False, url|]
releaseNotes=[False, ""]
titles=["Release Notes", " Software Source", "Software Site"]
for title in titles:
# If we haven't found the release notes yet...
if not releaseNotes[0]:
title = " " + title +": "
for index, packageInfoLine in enumerate(packageInfo):
if packageInfoLine.startswith(title):
releaseNotesURL = (packageInfoLine[len(title):]).strip()
try:
releaseNotesURLParsed = urllib.parse.urlparse(releaseNotesURL)
if releaseNotesURLParsed.hostname == "github.com":
releaseNotes[0] = True
releaseNotes[1] = getGithubChangelog(releaseNotesURLParsed, line[2])
else:
releaseNotes[0] = True
releaseNotes[1] = extractReleaseNotesFromChocoInfo(packageInfo, index)
break
except:
releaseNotes[0] = True
releaseNotes[1] = extractReleaseNotesFromChocoInfo(packageInfo, index)
break
if not releaseNotes[0]:
print("\tRelease notes were not included in the nuspec.")
else:
fancyChangelogPrint(releaseNotes[1])
return chocoUpgradeablePackages
# def npmIsUpdateAvailable(npmWhitelistedPackages: list[str]) -> list[str]:
# npmOutput = npmOutput.strip()
# npmOutputJSON = json.loads(npmOutput)
# if len(npmOutputJSON) == 0:
# return
# npmUpgradeablePackages = []
# for key in npmOutputJSON.keys():
# package = str(key)
# if package in npmWhitelistedPackages:
# oldVersion = npmOutputJSON[key]["current"]
# newVersion = npmOutputJSON[key]["wanted"]
# # Parse versions that don't comply with semantic versioning
# semverNewVersion = forceSemver(newVersion)
# semverOldVersion = forceSemver(oldVersion)
# if semverNewVersion[1] == Exception or semverOldVersion[1] == Exception:
# return False
# semverNewVersion = semverNewVersion[0]
# semverOldVersion = semverOldVersion[0]
# if(semverNewVersion > semverOldVersion):
# npmUpgradeablePackages.append(package)
# parseVersions(newVersion, oldVersion, package, "npm")
# return npmUpgradeablePackages
def runCommand(command: str):
"""Runs a command and prints out its live output"""
process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
while process.stdout.readable():
line = process.stdout.readline()
if not line:
break
print(str(line.strip())[1:])
def upgradeGitClone(path: str):
if not devMode:
command = "cd " + path + " & git pull"
print(colored("Running \"" + command + "\"...", "green"))
else:
command = "cd " + path + " & git pull --dry-run"
print(colored("devMode: ", "yellow") + colored("Running \"" + command +"\"...", "green"))
runCommand(command)
############################ END OF FUNCTIONS ##########################
upgradeablePackages = []
# Update gup packages
if generalUpgradeSettings["gup"]:
info("Getting " + colored("gup", "yellow") + " packages...")
if not devMode:
stream = os.popen("gup check")
gupOutput = stream.readlines()
else:
gupOutput=['gup:INFO : check binary under $GOPATH/bin or $GOBIN\n',
'gup:INFO : [ 1/13] golang.org/x/tools/gopls (Already up-to-date: v0.11.0)\n',
'gup:INFO : [ 2/13] github.com/OJ/gobuster/v3 (current: v3.4.0, latest: v3.5.0)\n',
'gup:INFO : [ 3/13] github.com/haya14busa/goplay (Already up-to-date: v1.0.0)\n',
'gup:INFO : [ 4/13] golang.org/dl (Already up-to-date: v0.0.0-20230201184804-2d6232701089)\n',
'gup:INFO : [ 5/13] github.com/go-delve/delve (Already up-to-date: v1.20.1)\n',
'gup:INFO : [ 6/13] honnef.co/go/tools (current: v0.3.3, latest: v0.4.0)\n',
'gup:INFO : [ 7/13] golang.org/dl (Already up-to-date: v0.0.0-20230201184804-2d6232701089)\n',
'gup:INFO : [ 8/13] github.com/josharian/impl (current: v1.1.0, latest: v1.2.0)\n',
'gup:INFO : [ 9/13] github.com/gwen001/github-subdomains (current: v1.2.0, latest: v1.2.2)\n',
'gup:INFO : [10/13] github.com/nao1215/gup (current: v0.15.1, latest: v0.16.0)\n',
'gup:INFO : [11/13] github.com/j3ssie/metabigor (Already up-to-date: v1.12.1)\n',
'gup:INFO : [12/13] github.com/ossf/criticality_score (Already up-to-date: v1.0.7)\n',
'gup:INFO : [13/13] github.com/fatih/gomodifytags (Already up-to-date: v1.16.0)\n',
'\n',
'gup:INFO : If you want to update binaries, run the following command.\n',
' $ gup update staticcheck.exe impl.exe github-subdomains.exe gup.exe \n']
gupUpgradeablePackages = gupCheckForUpgrades(gupOutput)
upgradeablePackages += gupUpgradeablePackages
if generalUpgradeSettings["pip"]:
# Update pip packages
pipUpgradeablePackages = []
info("Getting " + colored("pip", "yellow") + " packages...")
if not devMode:
stream = os.popen("pip list --outdated")
pipOutput = stream.readlines()
pipWhitelistedPackages = ["pip_audit",
"safety",
"guessit",
"srt"]
else:
pipOutput = ["Package Version Latest Type",
"---------- ------- ------ -----",
"pip_audit 1.1.2 2.4.14 wheel",
"minorPackage 2.4.0 2.5.0 wheel",
"patchPackage 2.5.0 2.5.1 wheel",
"rich 13.0.1 13.2.0 wheel",
"setuptools 65.5.0 66.1.1 wheel"]
pipWhitelistedPackages = ["pip_audit", "minorPackage", "patchPackage"]
# Check pip upgrades
pipUpgradeablePackages = pipIsUpdateAvailable(pipOutput, pipWhitelistedPackages)
upgradeablePackages += pipUpgradeablePackages
if generalUpgradeSettings["choco"]:
info("Getting " + colored("choco", "yellow") + " packages...")
if not devMode:
stream = os.popen("choco outdated")
chocoOutput = stream.readlines()
else:
chocoOutput = ["Chocolatey v1.2.1",
"Outdated Packages",
" Output is package name | current version | available version | pinned?",
"",
"betterdiscord|1.2.1|1.3.0|false",
"scrcpy|2.3.0|2.4.0|false",
"Shotcut|23.12.15|24.02.29|false",
"shotcut.install|23.12.15|24.02.29|false",
"dotnet-7.0-desktopruntime|7.0.1|7.0.2|false",
"dotnet-desktopruntime|7.0.1|7.0.2|false",
"ds4windows|3.2.6|3.2.7|false",
"filezilla|3.62.2|3.63.0|false",
"Firefox|108.0.1|109.0|false",
"golang|1.19.4|1.19.5|false",
"imagemagick|7.1.0.56|7.1.0.57|false",
"imagemagick.app|7.1.0.56|7.1.0.58|false",
"nextcloud-client|3.6.4|3.6.6|false",
"obs-studio|28.1.2|29.0.0|false",
"obs-studio.install|28.1.2|29.0.0|false",
"openjdk|19.0.1|19.0.2|false",
"protonvpn|2.3.1|2.3.2|false",
"super-productivity|7.12.0|7.12.1|false",
"teamviewer|15.37.3|15.38.3|false",
"winscp|5.21.6|5.21.7|false",
"winscp.install|5.21.6|5.21.7|false",
"wireshark|4.0.2|4.0.3|false",
"",
"Chocolatey has determined 18 package(s) are outdated.",
""]
chocoUpgradeablePackages = chocoCheckForUpgrades(chocoOutput)
upgradeablePackages += chocoUpgradeablePackages
############################################################################################
# USER MODIFIYABLE FUNCTIONS BEGIN HERE
############################################################################################
if generalUpgradeSettings["pipVenvs"]:
pipUpgradeableVenvs = []
# Check upgrades for pip virtualenvs
safetyUpgrade = pipUpgradeVenvs("C:\Program Files\HackingSoftware\safetyPythonVenv","safety")
if len(safetyUpgrade) == 2:
pipUpgradeableVenvs.append(safetyUpgrade)
upgradeablePackages += pipUpgradeableVenvs
if generalUpgradeSettings["git"]:
# Check upgrades for git repositories
githubSearchPath = "C:\\Program Files\\HackingSoftware\\github-search"
githubSearch = checkGitRepoUpgrade(githubSearchPath)
grauditPath = "C:\\Program Files\\HackingSoftware\\graudit"
graudit = checkGitRepoUpgrade(grauditPath)
corscannerPath = "C:\\Program Files\\HackingSoftware\\CORScanner"
corscanner = checkGitRepoUpgrade(corscannerPath)
nucleiTemplatesPath = "C:\\Program Files\\HackingSoftware\\nuclei-templates"
nucleiTemplates = checkGitRepoUpgrade(nucleiTemplatesPath)
sstimapPath = "C:\\Program Files\\HackingSoftware\\SSTImap"
sstimap = checkGitRepoUpgrade(sstimapPath)
urlessPath = "C:\\Program Files\\HackingSoftware\\urless"
urless = checkGitRepoUpgrade(urlessPath)
wafw00fPath = "C:\\Program Files\\HackingSoftware\\wafw00f"
wafw00f = checkGitRepoUpgrade(wafw00fPath)
if githubSearch:
upgradeablePackages.append("githubSearch")
if graudit:
upgradeablePackages.append("graudit")
if corscanner:
upgradeablePackages.append("corscanner")
if nucleiTemplates:
upgradeablePackages.append("nuclei-templates")
if sstimap:
upgradeablePackages.append("sstimap")
if urless:
upgradeablePackages.append("urless")
if wafw00f:
upgradeablePackages.append("wafw00f")
# if generalUpgradeSettings["npm"]:
# npmWhitelistedPackages = ["calculator"]
# npmUpgradeablePackages = npmIsUpdateAvailable(npmWhitelistedPackages)
# upgradeablePackages += npmUpgradeablePackages
print("Need to upgrade " + colored(len(upgradeablePackages), "yellow") + " packages.")
print("\t" + colored(str(numberOfMajorUpgrades) + " MAJOR upgrades", colorSettings["Major Versions"]))
print("\t" + colored(str(numberOfMinorUpgrades) + " Minor upgrades", colorSettings["Minor Versions"]))
print("\t" + str(numberOfPatchUpgrades) + " Patch upgrades")
userWantsToUpdate = (input("Do you want to continue? [Y/n] ")).lower()
if userWantsToUpdate == "" or userWantsToUpdate.startswith("y"):
# Upgrade go packages
# Putting a list in an if checks if its empty
if generalUpgradeSettings["gup"] and gupUpgradeablePackages:
if not devMode:
print(colored("Running \"gup update\"...", "green"))
command = "gup update"
else:
print(colored("devMode: ", "yellow") + colored("Running \"gup update --dry-run\"...", "green"))
command = "gup update --dry-run"
runCommand(command)
# Upgrade whitelisted pip packages
# Putting a list in an if checks if its empty
if generalUpgradeSettings["pip"] and pipUpgradeablePackages:
pipUpgradeablePackages = " ".join(pipUpgradeablePackages)
if not devMode:
command = "pip install --upgrade " + pipUpgradeablePackages
print(colored("Running \"" + command + "\"...", "green"))
else:
command = "pip install --upgrade --dry-run " + pipUpgradeablePackages
print(colored("devMode: ", "yellow") + colored("Running \"" + command +"\"...", "green"))
runCommand(command)
# Upgrade python venvs
if generalUpgradeSettings["pipVenvs"]:
for venv in pipUpgradeableVenvs:
pathToVenv = venv[0]
package = venv[1]
if not devMode:
command = "cd " + pathToVenv + "\Scripts & activate & pip install --upgrade " + package
print(colored("Running \"" + command + "\"...", "green"))
else:
command = "cd " + pathToVenv + "\Scripts & activate & pip install --upgrade --dry-run " + package
print(colored("devMode: ", "yellow") + colored("Running \"" + command +"\"...", "green"))
runCommand(command)
# Upgrade git clones
if generalUpgradeSettings["git"]:
if githubSearch:
upgradeGitClone(githubSearchPath)
if graudit:
upgradeGitClone(grauditPath)
if corscanner:
upgradeGitClone(corscannerPath)
# This lazy mf doesn't tag versions for his project
upgradeGitClone("C:\\Program Files\\HackingSoftware\\lfimap")
if nucleiTemplates:
upgradeGitClone(nucleiTemplatesPath)
# This lazy mf doesn't tag versions for his project
upgradeGitClone("C:\\Program Files\\HackingSoftware\\phpunit-brute")
if sstimap:
upgradeGitClone(sstimapPath)
if urless:
upgradeGitClone(urlessPath)
if wafw00f:
upgradeGitClone(wafw00fPath)
runCommand("python " + wafw00fPath + "\\setup.py install")
# Upgrade chocolatey packages
if generalUpgradeSettings["choco"]:
if not devMode:
command = "choco upgrade all"
print(colored("Running \"" + command + "\"...", "green"))
else:
command = "choco upgrade --noop all"
print(colored("devMode: ", "yellow") + colored("Running \"" + command +"\"...", "green"))
runCommand(command)
# # Upgrade npm packages
# if generalUpgradeSettings["npm"]:
# for package in npmUpgradeablePackages:
# if not devMode:
# command = "npm update " + package
# print(colored("Running \"" + command + "\"...", "green"))
# else:
# command = "npm update --dry-run " + package
# print(colored("devMode: ", "yellow") + colored("Running \"" + command +"\"...", "green"))
# runCommand(command)
print(colored("==================================================", "green"))
print(colored(" ALL DONE! ", "green"))
print(colored("==================================================", "green"))
else:
print(colored("==================================================", "yellow"))
print(colored(" UPGRADE CANCELED ", "yellow"))
print(colored("==================================================", "yellow"))