Compare commits

..

4 Commits

Author SHA1 Message Date
the-sane
6ddf8e6532 Add official doitsujin dxvk releases 2023-01-27 11:44:22 -05:00
the-sane
e9390c5182 Add more sanity checks 2023-01-27 11:12:30 -05:00
the-sane
7ee873d2bb Add error message type
Does not clear the screen in terminal mode so stderr is preserved
2023-01-27 09:53:10 -05:00
the-sane
f7580b8fdc Add xargs/findutils dependency check 2023-01-27 09:26:49 -05:00

View File

@ -72,11 +72,20 @@ fi
# exit 1
#fi
if [ ! -x "$(command -v mktemp)" ] || [ ! -x "$(command -v sort)" ] || [ ! -x "$(command -v basename)" ] || [ ! -x "$(command -v realpath)" ] || [ ! -x "$(command -v dirname)" ]; then
# coreutils
# Print to stderr and also try warning the user through notify-send
printf "lug-helper.sh: One or more required packages were not found on this system.\nPlease check that the following coreutils packages are installed:\n- mktemp\n- sort\n- basename\n- realpath\n- dirname\n" 1>&2
notify-send "lug-helper" "One or more required packages were not found on this system.\nPlease check that the following coreutils packages are installed:\n- mktemp\n- sort\n- basename\n- realpath\n- dirname\n" --icon=dialog-warning
exit 1
fi
if [ ! -x "$(command -v xargs)" ]; then
# findutils
# Print to stderr and also try warning the user through notify-send
printf "lug-helper.sh: One or more required packages were not found on this system.\nPlease check that the following findutils packages are installed:\n- xargs\n" 1>&2
notify-send "lug-helper" "One or more required packages were not found on this system.\nPlease check that the following findutils packages are installed:\n- xargs\n" --icon=dialog-warning
exit 1
fi
######## Config ############################################################
@ -151,9 +160,9 @@ runners_dir_flatpak="$lutris_flatpak_dir/data/lutris/runners/wine"
# The second is expected to contain the github api releases url
# ie. "RawFox" "https://api.github.com/repos/rawfoxDE/raw-wine/releases"
runner_sources=(
"GloriousEggroll" "https://api.github.com/repos/GloriousEggroll/wine-ge-custom/releases"
"RawFox" "https://api.github.com/repos/starcitizen-lug/raw-wine/releases"
"/dev/null" "https://api.github.com/repos/gort818/wine-sc-lug/releases"
"GloriousEggroll" "https://api.github.com/repos/GloriousEggroll/wine-ge-custom/releases"
)
######## DXVK ##############################################################
@ -169,9 +178,10 @@ dxvk_dir_flatpak="$lutris_flatpak_dir/data/lutris/runtime/dxvk"
# The second is expected to contain the github api releases url
# ie. "Sporif Async" "https://api.github.com/repos/Sporif/dxvk-async/releases"
dxvk_sources=(
"doitsujin (official dxvk)" "https://api.github.com/repos/doitsujin/dxvk/releases"
"Sporif Async" "https://api.github.com/repos/Sporif/dxvk-async/releases"
"/dev/null" "https://api.github.com/repos/gort818/dxvk/releases"
"gnusenpai" "https://api.github.com/repos/gnusenpai/dxvk/releases"
"/dev/null" "https://api.github.com/repos/gort818/dxvk/releases"
)
######## Bundled Files #####################################################
@ -305,6 +315,12 @@ message() {
margs=("--warning" "--window-icon=\"$lug_logo\"" "--text=")
shift 1 # drop the message type argument and shift up to the text
;;
"error")
# error message
# call format: message error "text to display"
margs=("--error" "--window-icon=\"$lug_logo\"" "--text=")
shift 1 # drop the message type argument and shift up to the text
;;
"question")
# question
# call format: if message question "question to ask?"; then...
@ -345,6 +361,12 @@ message() {
printf "\n$2\n\n"
read -n 1 -s -p "Press any key..."
;;
"error")
# error message. Does not clear the screen
# call format: message error "text to display"
printf "\n$2\n\n"
read -n 1 -s -p "Press any key..."
;;
"question")
# question
# call format: if message question "question to ask?"; then...
@ -529,7 +551,7 @@ menu_loop_done() {
getdirs() {
# Sanity checks
if [ ! -d "$conf_dir" ]; then
message warning "Config directory not found. The Helper is unable to proceed.\n\n$conf_dir"
message error "Config directory not found. The Helper is unable to proceed.\n\n$conf_dir"
return 1
fi
if [ ! -d "$conf_dir/$conf_subdir" ]; then
@ -562,7 +584,7 @@ getdirs() {
if [ -z "$wine_prefix" ]; then
wine_prefix="$(zenity --file-selection --directory --title="Select your Star Citizen WINE prefix directory" --filename="$HOME/Games/star-citizen" 2>/dev/null)"
if [ "$?" -eq -1 ]; then
message warning "An unexpected error has occurred. The Helper is unable to proceed."
message error "An unexpected error has occurred. The Helper is unable to proceed."
return 1
elif [ -z "$wine_prefix" ]; then
# User clicked cancel
@ -579,7 +601,7 @@ getdirs() {
else
while game_path="$(zenity --file-selection --directory --title="Select your Star Citizen directory" --filename="$wine_prefix/$install_path" 2>/dev/null)"; do
if [ "$?" -eq -1 ]; then
message warning "An unexpected error has occurred. The Helper is unable to proceed."
message error "An unexpected error has occurred. The Helper is unable to proceed."
return 1
elif [ "$(basename "$game_path")" != "$sc_base_dir" ]; then
message warning "You must select the base game directory named '$sc_base_dir'\n\nie. [prefix]/drive_c/Program Files/Roberts Space Industries/StarCitizen"
@ -983,7 +1005,7 @@ preflight_check() {
# Try to execute the actions as root
try_exec "$preflight_actions_string"
if [ "$?" -eq 1 ]; then
message info "Authentication failed or there was an error.\nSee terminal for more information.\n\nReturning to main menu."
message error "Authentication failed or there was an error.\nSee terminal for more information.\n\nReturning to main menu."
return 0
fi
fi
@ -1038,10 +1060,10 @@ lutris_restart() {
fi
}
# Get an array of directories used by Lutris
# Create an array of directories used by Lutris
# Array will be formatted in pairs of ("[type]" "[directory]")
# Supports native install and flatpak
# Array must be formatted in pairs of ("[type]" "[directory]")
# Takes an argument to specify the type to return, ie "runner" or "dxvk"
# Takes an argument to specify the type to return: "runner" or "dxvk"
get_lutris_dirs() {
# Sanity check
if [ "$#" -lt 1 ]; then
@ -1084,13 +1106,14 @@ get_lutris_dirs() {
# Perform post-download actions or display a message/instructions
#
# Expects the following variables to be set:
# post_download_type ("info", or "configure-lutris")
# post_download_msg_heading
# post_download_msg
# post_download_sed_string (for type question only)
# downloaded_item_name (set in download_install function)
# deleted_item_names (set in download_delete function)
# The following variables are expected to be set before calling this function:
# - post_download_type (string. "none", "info", or "configure-lutris")
# - post_download_msg_heading (string)
# - post_download_msg (string)
# - post_download_sed_string (string. For type configure-lutris)
# - download_action_success (string. Set automatically in install/delete functions)
# - downloaded_item_name (string. For installs only. Set automatically in download_install function)
# - deleted_item_names (array. For deletions only. Set automatically in download_delete function)
#
# Details for post_download_sed_string:
# This is the string sed will match against when editing Lutris yml configs
@ -1101,6 +1124,17 @@ get_lutris_dirs() {
# A header is automatically displayed that reads: Download Complete
# post_download_msg is displayed below the header
post_download() {
# Sanity checks
if [ -z "$post_download_type" ]; then
debug_print exit "Script error: The string 'post_download_type' was not set\nbefore calling the post_download function. Aborting."
elif [ -z "$post_download_msg_heading" ]; then
debug_print exit "Script error: The string 'post_download_msg_heading' was not set\nbefore calling the post_download function. Aborting."
elif [ -z "$post_download_msg" ]; then
debug_print exit "Script error: The string 'post_download_msg' was not set\nbefore calling the post_download function. Aborting."
elif [ -z "$post_download_sed_string" ] && [ "$post_download_type" = "configure-lutris" ]; then
debug_print exit "Script error: The string 'post_download_sed_string' was not set\nbefore calling the post_download function. Aborting."
fi
# Configure the message heading and format it for zenity
if [ "$use_zenity" -eq 1 ]; then
post_download_msg_heading="<b>$post_download_msg_heading</b>"
@ -1162,14 +1196,28 @@ post_download() {
fi
}
# Uninstall the selected item. Called by download_select_install()
# Note: The arrays installed_items and installed_item_names are expected to be set before calling this function
# Uninstall the selected item(s). Called by download_select_install()
# Accepts array index numbers as an argument
#
# The following variables are expected to be set before calling this function:
# - download_type (string)
# - installed_items (array)
# - installed_item_names (array)
download_delete() {
# This function expects an index number for the array installed_items to be passed in as an argument
# This function expects at least one index number for the array installed_items to be passed in as an argument
if [ -z "$1" ]; then
debug_print exit "Script error: The download_delete function expects an argument. Aborting."
fi
# Sanity checks
if [ -z "$download_type" ]; then
debug_print exit "Script error: The string 'download_type' was not set\nbefore calling the download_delete function. Aborting."
elif [ "${#installed_items[@]}" -eq 0 ]; then
debug_print exit "Script error: The array 'installed_items' was not set\nbefore calling the download_delete function. Aborting."
elif [ "${#installed_item_names[@]}" -eq 0 ]; then
debug_print exit "Script error: The array 'installed_item_names' was not set\nbefore calling the download_delete function. Aborting."
fi
# Capture arguments and format a list of items
item_to_delete=("$@")
unset list_to_delete
@ -1193,7 +1241,18 @@ download_delete() {
}
# List installed items for deletion. Called by download_manage()
#
# The following variables are expected to be set before calling this function:
# - download_type (string)
# - download_dirs (array)
download_select_delete() {
# Sanity checks
if [ -z "$download_type" ]; then
debug_print exit "Script error: The string 'download_type' was not set\nbefore calling the download_select_delete function. Aborting."
elif [ "${#download_dirs[@]}" -eq 0 ]; then
debug_print exit "Script error: The array 'download_dirs' was not set\nbefore calling the download_select_delete function. Aborting."
fi
# Configure the menu
menu_text_zenity="Select the $download_type(s) you want to remove:"
menu_text_terminal="Select the $download_type you want to remove:"
@ -1247,7 +1306,13 @@ download_select_delete() {
}
# Download and install the selected item. Called by download_select_install()
# Note: The variables download_versions, contributor_url, and download_url_type are expected to be set before calling this function
#
# The following variables are expected to be set before calling this function:
# - download_versions (array)
# - contributor_url (string)
# - download_url_type (string)
# - download_type (string)
# - download_dirs (array)
download_install() {
# This function expects an index number for the array
# download_versions to be passed in as an argument
@ -1255,6 +1320,19 @@ download_install() {
debug_print exit "Script error: The download_install function expects a numerical argument. Aborting."
fi
# Sanity checks
if [ "${#download_versions[@]}" -eq 0 ]; then
debug_print exit "Script error: The array 'download_versions' was not set\nbefore calling the download_install function. Aborting."
elif [ -z "$contributor_url" ]; then
debug_print exit "Script error: The string 'contributor_url' was not set\nbefore calling the download_install function. Aborting."
elif [ -z "$download_url_type" ]; then
debug_print exit "Script error: The string 'download_url_type' was not set\nbefore calling the download_install function. Aborting."
elif [ -z "$download_type" ]; then
debug_print exit "Script error: The string 'download_type' was not set\nbefore calling the download_install function. Aborting."
elif [ "${#download_dirs[@]}" -eq 0 ]; then
debug_print exit "Script error: The array 'download_dirs' was not set\nbefore calling the download_install function. Aborting."
fi
# Get the filename including file extension
download_file="${download_versions[$1]}"
@ -1419,6 +1497,11 @@ download_install() {
}
# List available items for download. Called by download_manage()
#
# The following variables are expected to be set before calling this function:
# - download_sources (array)
# - download_type (string)
# - download_dirs (array)
download_select_install() {
# This function expects an element number for the sources array
# to be passed in as an argument
@ -1426,6 +1509,15 @@ download_select_install() {
debug_print exit "Script error: The download_select_install function expects a numerical argument. Aborting."
fi
# Sanity checks
if [ "${#download_sources[@]}" -eq 0 ]; then
debug_print exit "Script error: The array 'download_sources' was not set\nbefore calling the download_select_install function. Aborting."
elif [ -z "$download_type" ]; then
debug_print exit "Script error: The string 'download_type' was not set\nbefore calling the download_select_install function. Aborting."
elif [ "${#download_dirs[@]}" -eq 0 ]; then
debug_print exit "Script error: The array 'download_dirs' was not set\nbefore calling the download_select_install function. Aborting."
fi
# Store info from the selected contributor
contributor_name="${download_sources[$1]}"
contributor_url="${download_sources[$1+1]}"
@ -1648,6 +1740,19 @@ download_manage() {
debug_print exit "Script error: The download_manage function expects a string argument. Aborting."
fi
# Sanity checks
if [ -z "$download_sources" ]; then
debug_print exit "Script error: The string 'download_sources' was not set\nbefore calling the download_manage function. Aborting."
elif [ "${#download_dirs[@]}" -eq 0 ]; then
debug_print exit "Script error: The array 'download_dirs' was not set\nbefore calling the download_manage function. Aborting."
elif [ -z "$download_menu_heading" ]; then
debug_print exit "Script error: The string 'download_menu_heading' was not set\nbefore calling the download_manage function. Aborting."
elif [ -z "$download_menu_description" ]; then
debug_print exit "Script error: The string 'download_menu_description' was not set\nbefore calling the download_manage function. Aborting."
elif [ -z "$download_menu_height" ]; then
debug_print exit "Script error: The string 'download_menu_height' was not set\nbefore calling the download_manage function. Aborting."
fi
# Get the type of item we're downloading from the function arguments
download_type="$1"
@ -1702,6 +1807,7 @@ download_manage() {
# Configure the download_manage function for runners
runner_manage() {
# Lutris will need to be configured and restarted after modifying runners
# Valid options are "none", "info", or "configure-lutris"
post_download_type="configure-lutris"
# Use indirect expansion to point download_sources
@ -1721,8 +1827,7 @@ runner_manage() {
missing_dir="false"
for (( i=1; i<"${#download_dirs[@]}"; i=i+2 )); do
if [ ! -d "${download_dirs[i]}" ]; then
message warning "The following Lutris directory was not found. Unable to continue.\n\n${download_dirs[i]}"
debug_print continue "The following Lutris directory was not found. Unable to continue.\n\n${download_dirs[i]}"
message error "The following Lutris directory was not found. Unable to continue.\n\n${download_dirs[i]}"
missing_dir="true"
fi
done
@ -1755,6 +1860,7 @@ runner_manage() {
# Configure the download_manage function for dxvks
dxvk_manage() {
# Lutris will need to be configured and restarted after modifying dxvks
# Valid options are "none", "info", or "configure-lutris"
post_download_type="configure-lutris"
# Use indirect expansion to point download_sources
@ -1774,8 +1880,7 @@ dxvk_manage() {
missing_dir="false"
for (( i=1; i<"${#download_dirs[@]}"; i=i+2 )); do
if [ ! -d "${download_dirs[i]}" ]; then
message warning "The following Lutris directory was not found. Unable to continue.\n\n${download_dirs[i]}"
debug_print continue "The following Lutris directory was not found. Unable to continue.\n\n${download_dirs[i]}"
message error "The following Lutris directory was not found. Unable to continue.\n\n${download_dirs[i]}"
missing_dir="true"
fi
done
@ -2132,7 +2237,7 @@ eac_workaround() {
# Try to modify /etc/hosts as root
try_exec "printf '\n$eac_hosts #Star Citizen EAC workaround\n' >> /etc/hosts"
if [ "$?" -eq 1 ]; then
message info "Authentication failed or there was an error modifying /etc/hosts.\nSee terminal for more information.\n\nReturning to main menu."
message error "Authentication failed or there was an error modifying /etc/hosts.\nSee terminal for more information.\n\nReturning to main menu."
return 0
fi