added project files - update readme

This commit is contained in:
Frede Hundewadt 2023-08-23 07:48:09 +02:00
parent 80d9f0ff8d
commit 4de52f19db
2 changed files with 189 additions and 1 deletions

View file

@ -1,2 +1,64 @@
# manjaro-get-iso ## Download and verify a Manjaro ISO.
When I wrote the https://forum.manjaro.org/t/root-tip-how-to-forum-mini-guide-to-verify-iso-signature/146680 I vaguely recalled a shell script in the repo **manjaro-iso-downloader** but it doesn't work - at least not for me.
So I decided to wrap up some python code.
The tool provides a convenient way of downloading and verifying an ISO as they are listed on https://manjaro.org/download.
Neither Sway nor ARM is supported, sway because the files is located elsewhere and ARM because there is no signature.
## Setup
The script relies on a single python package - python-requests.
On Manjaro you don't need to install it - it is default available as a dependency of pacman-mirrors.
Create the folder **~/.local/bin**
mkdir -p ~/.local/bin
Then create a new file in this bin folder - name the file **get-iso** - then use your favorite text editor to copy paste below code into the new file.
Make the file executable
chmod +x ~/.local/bin/get-iso
## Usage
$ get-iso -h
usage: get-iso [-h] [-f] {plasma,xfce,gnome,budgie,cinnamon,i3,mate}
This tool will download a named Manjaro ISO and verify the signature
positional arguments:
{plasma,xfce,gnome,budgie,cinnamon,i3,mate}
edition e.g. plasma or xfce
options:
-h, --help show this help message and exit
-f, --full Download full ISO
get-iso version 0.1 - License GPL v3 or later
The downloaded files is placed your home folder.
The script defaults to pull the minimal ISO
get-iso plasma
If you rather take the full
get-iso plasma -f
Example result of running the script
$ get-iso -f mate
Downloading: manjaro-mate-22.0-230104-linux61.iso
Downloading: manjaro-mate-22.0-230104-linux61.iso.sig
Wait for verification ...
gpg: assuming signed data in 'manjaro-mate-22.0-230104-linux61.iso'
gpg: Signature made ons 04 jan 2023 12:48:04 CET
gpg: using RSA key 3B794DE6D4320FCE594F4171279E7CF5D8D56EC8
gpg: Good signature from "Manjaro Build Server <build@manjaro.org>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 3B79 4DE6 D432 0FCE 594F 4171 279E 7CF5 D8D5 6EC8

126
get-iso Executable file
View file

@ -0,0 +1,126 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# @linux-aarhus - root.nix.dk
# License: GNU GPL, version 3 or later; http://www.gnu.org/licenses/gpl.html
import argparse
import subprocess
import sys
import os
import requests
import time
from typing import List
from pathlib import Path
DEF_URL = "https://gitlab.manjaro.org/webpage/iso-info/-/raw/master/file-info.json"
FOLDER = Path.home()
def download_file(url: str, folder_name: str) -> bool:
filename: str = url.split("/")[-1]
path = os.path.join("/{}/{}".format(folder_name, filename))
try:
response = requests.get(url, stream=True)
total_size_in_bytes = int(response.headers.get("content-length", 0))
block_size = 1024
if total_size_in_bytes < block_size:
block_size = total_size_in_bytes
with open(path, "wb") as f:
progress = 0
for data in response.iter_content(block_size):
f.write(data)
if len(data) < block_size:
progress += len(data)
else:
progress += block_size
print(f"Received {progress}/{total_size_in_bytes}", end="\r")
except Exception as e:
print(e)
return False
return True
def get_definitions(url: str) -> dict:
iso_def = {}
try:
resp = requests.get(url=url, timeout=10)
resp.raise_for_status()
iso_def = resp.json()
except Exception as e:
print(f"{e}")
return iso_def
def init_iso_list(url: str) -> List:
data = get_definitions(url)
data_official = data.get("official")
data_community = data.get("community")
init_iso_result = []
for ok, ov in data_official.items():
try:
init_iso_result.append({"name": ok,
"full": {"img": ov["image"], "sig": ov["signature"]},
"minimal": {"img": ov["minimal"]["image"], "sig": ov["minimal"]["signature"]}
})
except:
continue
for ck, cv in data_community.items():
try:
init_iso_result.append({"name": ck,
"full": {"img": cv["image"], "sig": cv["signature"]},
"minimal": {"img": cv["minimal"]["image"], "sig": cv["minimal"]["signature"]}
})
except:
continue
return init_iso_result
def download(url: str) -> bool:
print(f'Downloading: {url.split("/")[-1]}')
success = download_file(url, f"{FOLDER}")
return success
if __name__ == '__main__':
prog_name = os.path.basename(__file__)
prog_version = "0.1"
iso_files = init_iso_list(DEF_URL)
choices = []
for c in iso_files:
choices.append(c["name"])
parser = argparse.ArgumentParser(
prog=f"{prog_name}",
description="This tool will download a named Manjaro ISO and verify the signature",
epilog=f"{prog_name} version {prog_version} - License GPL v3 or later")
parser.add_argument("edition",
type=str,
help="edition e.g. plasma or xfce",
choices=choices)
parser.add_argument("-f", "--full",
required=False,
action="store_true",
help="Download full ISO")
args = parser.parse_args()
edition = [x for x in iso_files if args.edition == x["name"]]
for x in edition:
if args.full:
iso = x["full"]
else:
iso = x["minimal"]
iso_result = download(iso["img"])
sig_result = download(iso["sig"])
if sig_result and iso_result:
print("Wait for verification ...")
time.sleep(5)
local_filename = iso["sig"].split("/")[-1]
result = subprocess.run(["gpg", "--verify", f"{local_filename}"],
cwd=f"{FOLDER}")
else:
print("Download ISO failed")
sys.exit(0)
sys.exit(0)