mirror of
https://github.com/kevinveenbirkenbach/linux-image-manager.git
synced 2025-04-01 14:44:15 +02:00
Overall optimations
This commit is contained in:
parent
94fdcf5758
commit
e60b3cf2a7
14
main.py
14
main.py
@ -2,6 +2,7 @@
|
||||
import subprocess
|
||||
import os
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
def run_script(script_path, extra_args):
|
||||
if not os.path.exists(script_path):
|
||||
@ -9,14 +10,15 @@ def run_script(script_path, extra_args):
|
||||
exit(1)
|
||||
command = ["sudo", "bash", script_path] + extra_args
|
||||
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:
|
||||
print(f"[ERROR] Script exited with code {result.returncode}")
|
||||
exit(result.returncode)
|
||||
print("[SUCCESS] Script executed successfully.")
|
||||
|
||||
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__))
|
||||
|
||||
# Define available scripts along with their descriptions.
|
||||
@ -100,9 +102,17 @@ def main():
|
||||
print("[INFO] No extra parameters provided.")
|
||||
|
||||
if not args.auto_confirm:
|
||||
try:
|
||||
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)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
print("\n[ERROR] Execution aborted by user.")
|
||||
exit(1)
|
||||
|
2
requirements.yml
Normal file
2
requirements.yml
Normal file
@ -0,0 +1,2 @@
|
||||
pacman:
|
||||
- pv
|
@ -245,18 +245,28 @@ if [ -z "$image_checksum" ]; then
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ -v image_checksum ]]
|
||||
then
|
||||
if [[ -v image_checksum ]]; then
|
||||
info "A checksum is defined for the image."
|
||||
info "Checksums verify file integrity to ensure that the file was not corrupted during download."
|
||||
info "The script will try verifying the integrity using MD5, then SHA1, and finally SHA256 if needed."
|
||||
|
||||
info "Trying MD5 checksum verification..."
|
||||
(info "Checking md5 checksum..." && echo "$image_checksum $image_path" | md5sum -c -) ||
|
||||
(info "Checking sha1 checksum..." && echo "$image_checksum $image_path"| sha1sum -c -) ||
|
||||
(info "Checking sha256 checksum..." && echo "$image_checksum $image_path"| sha256sum -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."
|
||||
else
|
||||
warning "Verification is not possible. No checksum is defined."
|
||||
warning "No checksum is defined. Skipping checksum verification."
|
||||
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"
|
||||
info "Attempting to download the 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
|
||||
@ -388,7 +398,7 @@ if [ "$transfer_image" = "y" ]
|
||||
elif [ "${image_path: -4}" = ".iso" ]
|
||||
then
|
||||
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 ||
|
||||
error
|
||||
elif [ "${image_path: -3}" = ".xz" ]
|
||||
|
Loading…
x
Reference in New Issue
Block a user