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

@ -939,54 +939,65 @@ download_install() {
if [ ! -f "$tmp_dir/$download_file" ]; then if [ ! -f "$tmp_dir/$download_file" ]; then
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" | \
# Extract the archive zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Extracting ${download_type}...\n" 2>/dev/null
case "$first_filepath" in else
# If the files in the archive begin with ./ there is no subdirectory, mkdir "$tmp_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$tmp_dir/$download_name"
# so we must create one fi
./*)
debug_print continue "Installing $download_type into $download_dir/$download_name..." # Check the contents of the extracted archive to determine the
if [ "$use_zenity" -eq 1 ]; then # directory structure we must create upon installation
# Use Zenity progress bar num_dirs=0
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir/$download_name" | \ num_files=0
zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Installing ${download_type}...\n" 2>/dev/null for extracted_item in "$tmp_dir/$download_name"/*; do
else if [ -d "$extracted_item" ]; then
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir/$download_name" num_dirs="$((num_dirs+1))"
fi elif [ -f "$extracted_item" ]; then
lutris_needs_restart="true" num_files="$((num_files+1))"
;; fi
# If a subdirectory exists and has the same name as the archive, done
# extract it as is
"$download_name") # Create the correct directory structure and install the item
debug_print continue "Installing $download_type into $download_dir/$download_name..." if [ "$num_dirs" -eq 0 ] && [ "$num_files" -eq 0 ]; then
if [ "$use_zenity" -eq 1 ]; then # Sanity check
# Use Zenity progress bar message warning "The downloaded archive is empty. There is nothing to do."
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir" | \ # Cleanup tmp download
zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Installing ${download_type}...\n" 2>/dev/null debug_print continue "Removing $tmp_dir/$download_file..."
else rm "$tmp_dir/$download_file"
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir" return 1
fi elif [ "$num_dirs" -eq 1 ] && [ "$num_files" -eq 0 ]; then
lutris_needs_restart="true" # If the archive contains only one directory, install that directory
;; debug_print continue "Installing $download_type into $download_dir..."
# If a subdirectory exists and has any other name, if [ "$use_zenity" -eq 1 ]; then
# we must create the correct subdirectory # Use Zenity progress bar
*) mkdir -p "$download_dir" && cp -r "$tmp_dir"/"$download_name"/* "$download_dir" | \
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" && cp -r "$tmp_dir"/"$download_name"/* "$download_dir"
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$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 elif [ "$num_dirs" -gt 1 ] || [ "$num_files" -gt 0 ]; then
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir/$download_name" # If the archive contains more than one directory or
fi # one or more files, we must create a subdirectory
lutris_needs_restart="true" debug_print continue "Installing $download_type into $download_dir/$download_name..."
;; if [ "$use_zenity" -eq 1 ]; then
esac # Use Zenity progress bar
mkdir -p "$download_dir/$download_name" && cp -r "$tmp_dir"/"$download_name"/* "$download_dir"/"$download_name" | \
zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Installing ${download_type}...\n" 2>/dev/null
else
mkdir -p "$download_dir/$download_name" && cp -r "$tmp_dir"/"$download_name"/* "$download_dir"/"$download_name"
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..."