Rewrite download_install function

This commit is contained in:
the Sane 2021-10-27 22:30:39 -04:00 committed by GitHub
parent 77c6fd46bb
commit acad90a0a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -940,53 +940,64 @@ download_install() {
debug_print exit "Script error: The requested $download_type file was not downloaded. Aborting" debug_print exit "Script error: The requested $download_type file was not downloaded. Aborting"
fi fi
# Get the path of the first item listed in the archive # Extract the archive to the tmp directory
# This should either be a subdirectory or the path ./ debug_print continue "Extracting $download_type into $tmp_dir/$download_name..."
# depending on how the archive was created if [ "$use_zenity" -eq 1 ]; then
first_filepath="$(stdbuf -oL tar -tf "$tmp_dir/$download_file" | head -n 1)" # Use Zenity progress bar
mkdir "$tmp_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$tmp_dir/$download_name" | \
zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Extracting ${download_type}...\n" 2>/dev/null
else
mkdir "$tmp_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$tmp_dir/$download_name"
fi
# Extract the archive # Check the contents of the extracted archive to determine the
case "$first_filepath" in # directory structure we must create upon installation
# If the files in the archive begin with ./ there is no subdirectory, num_dirs=0
# so we must create one num_files=0
./*) for extracted_item in "$tmp_dir/$download_name"/*; do
debug_print continue "Installing $download_type into $download_dir/$download_name..." if [ -d "$extracted_item" ]; then
if [ "$use_zenity" -eq 1 ]; then num_dirs="$((num_dirs+1))"
# Use Zenity progress bar elif [ -f "$extracted_item" ]; then
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir/$download_name" | \ num_files="$((num_files+1))"
zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Installing ${download_type}...\n" 2>/dev/null fi
else done
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir/$download_name"
fi # Create the correct directory structure and install the item
lutris_needs_restart="true" if [ "$num_dirs" -eq 0 ] && [ "$num_files" -eq 0 ]; then
;; # Sanity check
# If a subdirectory exists and has the same name as the archive, message warning "The downloaded archive is empty. There is nothing to do."
# extract it as is # Cleanup tmp download
"$download_name") debug_print continue "Removing $tmp_dir/$download_file..."
debug_print continue "Installing $download_type into $download_dir/$download_name..." rm "$tmp_dir/$download_file"
if [ "$use_zenity" -eq 1 ]; then return 1
# Use Zenity progress bar elif [ "$num_dirs" -eq 1 ] && [ "$num_files" -eq 0 ]; then
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir" | \ # If the archive contains only one directory, install that directory
zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Installing ${download_type}...\n" 2>/dev/null debug_print continue "Installing $download_type into $download_dir..."
else if [ "$use_zenity" -eq 1 ]; then
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir" # Use Zenity progress bar
fi mkdir -p "$download_dir" && cp -r "$tmp_dir"/"$download_name"/* "$download_dir" | \
lutris_needs_restart="true" zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Installing ${download_type}...\n" 2>/dev/null
;; else
# If a subdirectory exists and has any other name, mkdir -p "$download_dir" && cp -r "$tmp_dir"/"$download_name"/* "$download_dir"
# we must create the correct subdirectory fi
*) lutris_needs_restart="true"
debug_print continue "Installing $download_type into $download_dir/$download_name..." elif [ "$num_dirs" -gt 1 ] || [ "$num_files" -gt 0 ]; then
if [ "$use_zenity" -eq 1 ]; then # If the archive contains more than one directory or
# Use Zenity progress bar # one or more files, we must create a subdirectory
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir/$download_name" | \ debug_print continue "Installing $download_type into $download_dir/$download_name..."
zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Installing ${download_type}...\n" 2>/dev/null if [ "$use_zenity" -eq 1 ]; then
else # Use Zenity progress bar
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir/$download_name" mkdir -p "$download_dir/$download_name" && cp -r "$tmp_dir"/"$download_name"/* "$download_dir"/"$download_name" | \
fi zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Installing ${download_type}...\n" 2>/dev/null
lutris_needs_restart="true" else
;; mkdir -p "$download_dir/$download_name" && cp -r "$tmp_dir"/"$download_name"/* "$download_dir"/"$download_name"
esac fi
lutris_needs_restart="true"
else
# Some unexpected combination of directories and files
debug_print exit "Script error: Unexpected archive contents in download_install function. Aborting"
exit 0
fi
# Cleanup tmp download # Cleanup tmp download
debug_print continue "Removing $tmp_dir/$download_file..." debug_print continue "Removing $tmp_dir/$download_file..."