Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apt-sync.py增加跳过SHA-256 验证参数 #179

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions apt-sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def apt_mirror(
arch: str,
dest_base_dir: Path,
deb_set: Dict[str, int],
skip_checksum: bool
) -> int:
if not dest_base_dir.is_dir():
print("Destination directory is empty, cannot continue")
Expand Down Expand Up @@ -229,7 +230,7 @@ def apt_mirror(
)
pkgidx_file.unlink()
continue
if hashlib.sha256(content).hexdigest() != checksum:
if not skip_checksum and hashlib.sha256(content).hexdigest() != checksum:
print(
f"Invalid checksum of {pkgidx_file}, expected {checksum}, skipped"
)
Expand Down Expand Up @@ -331,7 +332,7 @@ def collect_tmp_dir():
with dest_tmp_filename.open("rb") as f:
for block in iter(lambda: f.read(1024**2), b""):
sha.update(block)
if sha.hexdigest() != pkg_checksum:
if not skip_checksum and sha.hexdigest() != pkg_checksum:
print(f"Invalid checksum of {dest_filename}, expected {pkg_checksum}")
dest_tmp_filename.unlink()
continue
Expand Down Expand Up @@ -383,6 +384,8 @@ def main():
action="store_true",
help="print package files to be deleted only",
)
parser.add_argument("--skip-checksum", action='store_true',
help='skip checksum validation')
args = parser.parse_args()

# generate lists of os codenames
Expand Down Expand Up @@ -420,7 +423,7 @@ def generate_list_for_oses(raw: str, name: str) -> List[List[str]]:
for arch in arch_list:
if (
apt_mirror(
args.base_url, os, comp, arch, args.working_dir, deb_set=deb_set
args.base_url, os, comp, arch, args.working_dir, deb_set=deb_set, skip_checksum=args.skip_checksum
)
!= 0
):
Expand All @@ -438,4 +441,4 @@ def generate_list_for_oses(raw: str, name: str) -> List[List[str]]:


if __name__ == "__main__":
main()
main()