Overall optimations

This commit is contained in:
Kevin Veen-Birkenbach 2025-03-22 11:42:13 +01:00
parent 94fdcf5758
commit e60b3cf2a7
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
3 changed files with 37 additions and 15 deletions

16
main.py
View File

@ -2,21 +2,23 @@
import subprocess import subprocess
import os import os
import argparse import argparse
import sys
def run_script(script_path, extra_args): def run_script(script_path, extra_args):
if not os.path.exists(script_path): if not os.path.exists(script_path):
print(f"[ERROR] Script not found at {script_path}") print(f"[ERROR] Script not found at {script_path}")
exit(1) exit(1)
command = ["sudo","bash", script_path] + extra_args command = ["sudo", "bash", script_path] + extra_args
print(f"[INFO] Running command: {' '.join(command)}") print(f"[INFO] Running command: {' '.join(command)}")
result = subprocess.run(command) # Pass the parent's stdout and stderr so that progress output shows in real time.
result = subprocess.run(command, stdout=sys.stdout, stderr=sys.stderr)
if result.returncode != 0: if result.returncode != 0:
print(f"[ERROR] Script exited with code {result.returncode}") print(f"[ERROR] Script exited with code {result.returncode}")
exit(result.returncode) exit(result.returncode)
print("[SUCCESS] Script executed successfully.") print("[SUCCESS] Script executed successfully.")
def main(): def main():
# Use os.path.realpath to get the actual path of this file regardless of symlinks # Use os.path.realpath to get the actual path of this file regardless of symlinks.
repo_root = os.path.dirname(os.path.realpath(__file__)) repo_root = os.path.dirname(os.path.realpath(__file__))
# Define available scripts along with their descriptions. # Define available scripts along with their descriptions.
@ -100,9 +102,17 @@ def main():
print("[INFO] No extra parameters provided.") print("[INFO] No extra parameters provided.")
if not args.auto_confirm: if not args.auto_confirm:
try:
input("Press Enter to execute the script or Ctrl+C to cancel...") input("Press Enter to execute the script or Ctrl+C to cancel...")
except KeyboardInterrupt:
print("\n[ERROR] Execution aborted by user.")
exit(1)
run_script(script_info["path"], args.extra) run_script(script_info["path"], args.extra)
if __name__ == "__main__": if __name__ == "__main__":
try:
main() main()
except KeyboardInterrupt:
print("\n[ERROR] Execution aborted by user.")
exit(1)

2
requirements.yml Normal file
View File

@ -0,0 +1,2 @@
pacman:
- pv

View File

@ -245,18 +245,28 @@ if [ -z "$image_checksum" ]; then
done done
fi fi
if [[ -v image_checksum ]] if [[ -v image_checksum ]]; then
then info "A checksum is defined for the image."
(info "Checking md5 checksum..." && echo "$image_checksum $image_path"| md5sum -c -) || info "Checksums verify file integrity to ensure that the file was not corrupted during download."
(info "Checking sha1 checksum..." && echo "$image_checksum $image_path"| sha1sum -c -) || info "The script will try verifying the integrity using MD5, then SHA1, and finally SHA256 if needed."
(info "Checking sha256 checksum..." && echo "$image_checksum $image_path"| sha256sum -c -) ||
info "Trying MD5 checksum verification..."
(info "Checking md5 checksum..." && echo "$image_checksum $image_path" | md5sum -c -) ||
(warning "MD5 verification failed. This may indicate data corruption." &&
info "Trying SHA1 checksum verification for a secondary integrity check..." &&
info "Checking sha1 checksum..." && echo "$image_checksum $image_path" | sha1sum -c -) ||
(warning "SHA1 verification failed. Attempting SHA256 verification for thoroughness." &&
info "SHA256 provides a more robust check and is used as a final integrity measure." &&
info "Checking sha256 checksum..." && echo "$image_checksum $image_path" | sha256sum -c -) ||
error "Verification failed. HINT: Force the download of the image." error "Verification failed. HINT: Force the download of the image."
else else
warning "Verification is not possible. No checksum is defined." warning "No checksum is defined. Skipping checksum verification."
fi fi
info "Verifying signature..." info "Note: Checksums verify integrity but do not confirm authenticity."
info "Proceeding to signature verification, which ensures the file comes from a trusted source."
signature_download_url="$download_url.sig" signature_download_url="$download_url.sig"
info "Attempting to download the image signature from: $signature_download_url"
info "Try to download image signature from $signature_download_url." info "Try to download image signature from $signature_download_url."
if wget -q --method=HEAD "$signature_download_url"; then if wget -q --method=HEAD "$signature_download_url"; then
@ -388,7 +398,7 @@ if [ "$transfer_image" = "y" ]
elif [ "${image_path: -4}" = ".iso" ] elif [ "${image_path: -4}" = ".iso" ]
then then
info "Transfering .iso file..." && info "Transfering .iso file..." &&
sudo dd if="$image_path" of="$device_path" bs="$OPTIMAL_BLOCKSIZE" conv=fsync status=progress && pv "$image_path" | sudo dd of="$device_path" bs="$OPTIMAL_BLOCKSIZE" conv=fsync &&
sync || sync ||
error error
elif [ "${image_path: -3}" = ".xz" ] elif [ "${image_path: -3}" = ".xz" ]