npbackup/bin/sign_windows.py

41 lines
1.3 KiB
Python
Raw Normal View History

2023-05-04 04:12:15 +08:00
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# This file is part of npbackup
__intname__ = "npbackup.sign_windows"
__author__ = "Orsiris de Jong"
2024-01-04 03:01:03 +08:00
__copyright__ = "Copyright (C) 2023-2024 NetInvent"
2023-05-04 04:12:15 +08:00
__license__ = "GPL-3.0-only"
2024-06-04 19:44:25 +08:00
__build__ = "2024060401"
__version__ = "1.1.2"
2023-05-04 04:12:15 +08:00
import os
2023-08-29 15:56:49 +08:00
try:
from windows_tools.signtool import SignTool
except ImportError:
print("This tool needs windows_tools.signtool >= 0.3.1")
2023-05-04 04:12:15 +08:00
basepath = r"C:\GIT\npbackup\BUILDS"
audiences = ["private", "public"]
arches = ["x86", "x64"]
binaries = ["npbackup-cli", "npbackup-gui", "npbackup-viewer"]
2023-05-04 04:12:15 +08:00
signer = SignTool()
for audience in audiences:
for arch in arches:
for binary in binaries:
2024-05-02 01:30:39 +08:00
one_file_exe_path = exe_path = os.path.join(basepath, audience, "windows", arch, binary + f"-{arch}.exe")
2024-06-04 19:44:25 +08:00
standalone_exe_path = os.path.join(basepath, audience, "windows", arch, binary + ".dist", binary + f".exe")
2024-05-02 01:30:39 +08:00
for exe_file in (one_file_exe_path, standalone_exe_path):
if os.path.isfile(exe_file):
print(f"Signing {exe_file}")
result = signer.sign(exe_file, bitness=arch)
if not result:
raise EnvironmentError(
"Could not sign executable ! Is the PKI key connected ?"
)