11# SPDX-License-Identifier: Apache-2.0
22
3+ import hashlib
34import os
45import patoolib
56import requests
2425def main (
2526 debug : bool = typer .Option (False , "--debug" , help = "Enable debug logging" ),
2627 upload : bool = typer .Option (True , "--upload/--no-upload" , help = "Upload images" ),
28+ checksum : bool = typer .Option (
29+ True , "--checksum/--no-checksum" , help = "Calculate and compare the checksum"
30+ ),
2731 download : bool = typer .Option (
2832 True , "--download/--no-download" , help = "Download images"
2933 ),
@@ -97,11 +101,12 @@ def main(
97101 "almalinux" ,
98102 "centos" ,
99103 "debian" ,
100- "rocky" ,
101- "ubuntu" ,
104+ "flatcar" ,
102105 "gardenlinux" ,
106+ "opnsense" ,
107+ "rocky" ,
103108 "talos" ,
104- "flatcar " ,
109+ "ubuntu " ,
105110 )
106111 ):
107112 continue
@@ -121,7 +126,9 @@ def main(
121126 )
122127 _ , mirror_fileextension2 = os .path .splitext (mirror_filename )
123128
124- if not image ["shortname" ].startswith (("gardenlinux" , "talos" , "flatcar" )):
129+ if not image ["shortname" ].startswith (
130+ ("gardenlinux" , "talos" , "flatcar" , "opnsense" )
131+ ):
125132 mirror_filename = f"{ version ['version' ]} -{ image ['shortname' ]} "
126133
127134 if mirror_fileextension not in [".bz2" , ".zip" , ".xz" , ".gz" ]:
@@ -187,6 +194,15 @@ def main(
187194 )
188195 else :
189196 os .rename (source_filename , mirror_filename )
197+
198+ if checksum :
199+ h = hashlib .new ("sha512" )
200+ with open (mirror_filename , "rb" ) as fp :
201+ while c := fp .read (8192 ):
202+ h .update (c )
203+
204+ logger .info (f"SHA512 of { mirror_filename } : { h .hexdigest ()} " )
205+
190206 else :
191207 logger .info (
192208 f"Not downloading { source_filename } to local filesystem (download disabled)"
0 commit comments