add a script

This commit is contained in:
Minecon724 2024-09-05 07:24:37 +02:00
parent 67282dbd74
commit 727501e8a6
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
2 changed files with 101 additions and 1 deletions

4
.gitignore vendored
View file

@ -35,4 +35,6 @@ build/
.vscode/ .vscode/
### Mac OS ### ### Mac OS ###
.DS_Store .DS_Store
Qt/

98
download_qt.sh Executable file
View file

@ -0,0 +1,98 @@
#!/bin/bash
gpg_exists() {
gpg --version &> /dev/null
return $?
}
download_and_verify() {
local file_url="$1"
if [ -v "$2" ]; then
local output_file="$2"
else
local output_file="${3:-$(basename "$file_url")}"
local signature_file="$2"
fi
if [ -v "$3" ]; then
local signature_file="$3"
else
local signature_file="$output_file.sig"
fi
echo
echo "Downloading from $file_url to $output_file and verifying $signature_file"
# Download the file
if ! curl -SfL "$file_url" -o "$output_file"; then
echo "Error: Failed to download the file from $file_url"
return 1
fi
echo
sha256sum $output_file
# Verify
if gpg_exists; then
if gpg --verify "$signature_file" "$output_file"; then
echo "File is valid"
else
echo "File is not valid"
rm "$output_file"
return 1
fi
else
echo "The file can't be verified because gpg is not installed"
fi
return 0
}
unpack() {
local archive_file=$1
local target_directory=$2
echo
echo "Unpacking..."
mkdir "$target_directory"
if tar -C "$target_directory" -xaf "$archive_file"; then
echo "Unpacked into $target_directory"
else
echo "Error unpacking"
return 1
fi
return 0
}
if [ -v "$1" ]; then
target="$1"
else
target="$HOME/Qt"
echo "You did not specify where to extract, so extracting to $target"
echo "Press enter to proceed, Ctrl+C to abort"
read
fi
SYSTEM="$(uname) $(uname -p)"
echo "System is $SYSTEM"
if [[ "$SYSTEM" == "Linux x86_64" ]]; then
if download_and_verify "https://lfs724.b-cdn.net/qt672.tar.zst"; then
if unpack qt672.tar.zst $target; then
echo
echo "Downloaded to $target"
else
return 1
fi
else
return 1
fi
rm qt672.tar.zst
else
echo "System is not supported"
exit 1
fi