99 lines
1.8 KiB
Bash
99 lines
1.8 KiB
Bash
|
#!/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
|