mirror of
https://github.com/the-sane/lug-helper.git
synced 2024-12-30 22:54:19 +00:00
Rewrite download_install function
This commit is contained in:
parent
77c6fd46bb
commit
acad90a0a5
@ -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
|
||||||
|
if [ -d "$extracted_item" ]; then
|
||||||
|
num_dirs="$((num_dirs+1))"
|
||||||
|
elif [ -f "$extracted_item" ]; then
|
||||||
|
num_files="$((num_files+1))"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Create the correct directory structure and install the item
|
||||||
|
if [ "$num_dirs" -eq 0 ] && [ "$num_files" -eq 0 ]; then
|
||||||
|
# Sanity check
|
||||||
|
message warning "The downloaded archive is empty. There is nothing to do."
|
||||||
|
# Cleanup tmp download
|
||||||
|
debug_print continue "Removing $tmp_dir/$download_file..."
|
||||||
|
rm "$tmp_dir/$download_file"
|
||||||
|
return 1
|
||||||
|
elif [ "$num_dirs" -eq 1 ] && [ "$num_files" -eq 0 ]; then
|
||||||
|
# If the archive contains only one directory, install that directory
|
||||||
|
debug_print continue "Installing $download_type into $download_dir..."
|
||||||
|
if [ "$use_zenity" -eq 1 ]; then
|
||||||
|
# Use Zenity progress bar
|
||||||
|
mkdir -p "$download_dir" && cp -r "$tmp_dir"/"$download_name"/* "$download_dir" | \
|
||||||
|
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" && cp -r "$tmp_dir"/"$download_name"/* "$download_dir"
|
||||||
|
fi
|
||||||
|
lutris_needs_restart="true"
|
||||||
|
elif [ "$num_dirs" -gt 1 ] || [ "$num_files" -gt 0 ]; then
|
||||||
|
# If the archive contains more than one directory or
|
||||||
|
# one or more files, we must create a subdirectory
|
||||||
debug_print continue "Installing $download_type into $download_dir/$download_name..."
|
debug_print continue "Installing $download_type into $download_dir/$download_name..."
|
||||||
if [ "$use_zenity" -eq 1 ]; then
|
if [ "$use_zenity" -eq 1 ]; then
|
||||||
# Use Zenity progress bar
|
# 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" | \
|
||||||
zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Installing ${download_type}...\n" 2>/dev/null
|
zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Installing ${download_type}...\n" 2>/dev/null
|
||||||
else
|
else
|
||||||
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
|
fi
|
||||||
lutris_needs_restart="true"
|
lutris_needs_restart="true"
|
||||||
;;
|
|
||||||
# If a subdirectory exists and has the same name as the archive,
|
|
||||||
# extract it as is
|
|
||||||
"$download_name")
|
|
||||||
debug_print continue "Installing $download_type into $download_dir/$download_name..."
|
|
||||||
if [ "$use_zenity" -eq 1 ]; then
|
|
||||||
# Use Zenity progress bar
|
|
||||||
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir" | \
|
|
||||||
zenity --progress --pulsate --no-cancel --auto-close --title="Star Citizen LUG Helper" --text="Installing ${download_type}...\n" 2>/dev/null
|
|
||||||
else
|
else
|
||||||
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$download_dir"
|
# Some unexpected combination of directories and files
|
||||||
|
debug_print exit "Script error: Unexpected archive contents in download_install function. Aborting"
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
lutris_needs_restart="true"
|
|
||||||
;;
|
|
||||||
# If a subdirectory exists and has any other name,
|
|
||||||
# we must create the correct subdirectory
|
|
||||||
*)
|
|
||||||
debug_print continue "Installing $download_type into $download_dir/$download_name..."
|
|
||||||
if [ "$use_zenity" -eq 1 ]; then
|
|
||||||
# Use Zenity progress bar
|
|
||||||
mkdir -p "$download_dir/$download_name" && tar -xf "$tmp_dir/$download_file" -C "$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" && tar -xf "$tmp_dir/$download_file" -C "$download_dir/$download_name"
|
|
||||||
fi
|
|
||||||
lutris_needs_restart="true"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Cleanup tmp download
|
# Cleanup tmp download
|
||||||
debug_print continue "Removing $tmp_dir/$download_file..."
|
debug_print continue "Removing $tmp_dir/$download_file..."
|
||||||
|
Loading…
Reference in New Issue
Block a user