mirror of
https://github.com/the-sane/lug-helper.git
synced 2024-12-29 09:14:19 +00:00
Merge pull request #6 from Termuellinator/patch-1
Added option to download and delete runners
This commit is contained in:
commit
fa14c6d9de
245
lug-helper.sh
245
lug-helper.sh
@ -45,6 +45,20 @@ user_subdir_name="USER"
|
||||
keybinds_export_path="Controls/Mappings"
|
||||
|
||||
dxvk_cache_file="StarCitizen.dxvk-cache"
|
||||
|
||||
# Lutris wine runners directory
|
||||
if [ -z "$XDG_DATA_HOME" ]; then
|
||||
runner_dir="$HOME/.local/share/lutris/runners/wine"
|
||||
else
|
||||
runner_dir="$XDG_DATA_HOME/lutris/runners/wine"
|
||||
fi
|
||||
# URLs for downloading Lutris runners
|
||||
rawfox_url="https://api.github.com/repos/rawfoxDE/raw-wine/releases"
|
||||
snatella_url="https://api.github.com/repos/snatella/wine-runner-sc/releases"
|
||||
|
||||
# Set a maximum number of runners
|
||||
max_runners=20
|
||||
|
||||
############################################################################
|
||||
############################################################################
|
||||
|
||||
@ -78,7 +92,7 @@ message() {
|
||||
;;
|
||||
"question")
|
||||
# question
|
||||
# call format: message question "question to ask?"
|
||||
# call format: if message question "question to ask?"; then...
|
||||
margs=("--question" "--text=")
|
||||
;;
|
||||
*)
|
||||
@ -111,7 +125,7 @@ message() {
|
||||
;;
|
||||
"question")
|
||||
# question
|
||||
# call format: message question "question to ask?"
|
||||
# call format: if message question "question to ask?"; then...
|
||||
clear
|
||||
echo -e "$2"
|
||||
while read -p "[y/n]: " yn; do
|
||||
@ -512,8 +526,8 @@ mapcount_set() {
|
||||
fi
|
||||
|
||||
# Configure the menu
|
||||
menu_text_zenity="<b>This helper can change vm.max_map_count for you.</b>\n\nChoose from the following options:"
|
||||
menu_text_terminal="This helper can change vm.max_map_count for you.\n\nChoose from the following options:"
|
||||
menu_text_zenity="<b>This helper can change vm.max_map_count for you</b>\n\nChoose from the following options:"
|
||||
menu_text_terminal="This helper can change vm.max_map_count for you\n\nChoose from the following options:"
|
||||
menu_height="200"
|
||||
|
||||
# Configure the menu options
|
||||
@ -626,6 +640,216 @@ rm_vidcache() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Restart lutris
|
||||
lutris_restart() {
|
||||
if [ "$lutris_needs_restart" = "true" ]; then
|
||||
if message question "Lutris must be restarted to detect runner changes.\nWould you like this helper to restart it for you?"; then
|
||||
if [ "$(pgrep lutris)" ]; then
|
||||
echo -e "\nRestarting Lutris...\n"
|
||||
pkill -SIGTERM lutris && nohup lutris </dev/null &>/dev/null &
|
||||
else
|
||||
message info "Lutris does not appear to be running."
|
||||
fi
|
||||
fi
|
||||
lutris_needs_restart="false"
|
||||
fi
|
||||
}
|
||||
|
||||
# Delete the selected runner
|
||||
runner_delete() {
|
||||
# This function expects an index number for the array installed_runners to be passed in as an argument
|
||||
if [ -z "$1" ]; then
|
||||
echo -e "\nScript error: The runner_delete function expects an argument. Aborting."
|
||||
read -n 1 -s -p "Press any key..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
runner_to_delete="$1"
|
||||
if message question "Are you sure you want to delete the following runner?\n\n${installed_runners[$runner_to_delete]}"; then
|
||||
rm -r "${installed_runners[$runner_to_delete]}"
|
||||
echo -e "\nDeleted ${installed_runners[$runner_to_delete]}\n"
|
||||
lutris_needs_restart="true"
|
||||
fi
|
||||
}
|
||||
|
||||
# List installed runners for deletion
|
||||
runner_select_delete() {
|
||||
# Configure the menu
|
||||
menu_text_zenity="Select the Lutris runner you want to delete:"
|
||||
menu_text_terminal="Select the Lutris runner you want to delete:"
|
||||
menu_height="300"
|
||||
goback="Return to the runner management menu"
|
||||
unset installed_runners
|
||||
unset menu_options
|
||||
unset menu_actions
|
||||
|
||||
# Create an array containing all directories in the runner_dir
|
||||
for runners_list in "$runner_dir"/*; do
|
||||
if [ -d "$runners_list" ]; then
|
||||
installed_runners+=("$runners_list")
|
||||
fi
|
||||
done
|
||||
|
||||
# Create menu options for the installed runners
|
||||
for (( i=0; i<"${#installed_runners[@]}"; i++ )); do
|
||||
menu_options+=("$(basename "${installed_runners[i]}")")
|
||||
menu_actions+=("runner_delete $i")
|
||||
done
|
||||
|
||||
# Complete the menu by adding the option to go back to the previous menu
|
||||
menu_options+=("$goback")
|
||||
menu_actions+=(":") # no-op
|
||||
|
||||
# Call the menu function. It will use the options as configured above
|
||||
menu
|
||||
}
|
||||
|
||||
# Download and install the selected runner
|
||||
runner_install() {
|
||||
# This function expects an index number for the array runner_versions to be passed in as an argument
|
||||
if [ -z "$1" ]; then
|
||||
echo -e "\nScript error: The runner_install function expects an argument. Aborting."
|
||||
read -n 1 -s -p "Press any key..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Store the selected runner name and url
|
||||
runner_name="${runner_versions[$1]}"
|
||||
if [ "$latest_url" = "$snatella_url" ]; then
|
||||
# Runners with .tgz file extension
|
||||
runner_url="$(curl -s "$latest_url" | grep "browser_download_url.*$runner_name.tgz" | cut -d \" -f4)"
|
||||
else
|
||||
# Runners with .tar.gz file extension
|
||||
runner_url="$(curl -s "$latest_url" | grep "browser_download_url.*$runner_name.tar.gz" | cut -d \" -f4)"
|
||||
fi
|
||||
|
||||
# Sanity check
|
||||
if [ -z "$runner_url" ]; then
|
||||
message warning "Could not find the requested runner. The Github API may be down or rate limited."
|
||||
return 1
|
||||
fi
|
||||
|
||||
message info "The selected runner will now be downloaded.\nThis might take a moment."
|
||||
|
||||
# Download and extract the runner
|
||||
if [ "$latest_url" = "$snatella_url" ]; then
|
||||
# Runners without a subdirectory in the archive
|
||||
echo -e "\nDownloading $runner_url\ninto $runner_dir/$runner_name\n"
|
||||
mkdir -p "$runner_dir/$runner_name" && curl -L "$runner_url" | tar -xzf - -C "$runner_dir/$runner_name"
|
||||
lutris_needs_restart="true"
|
||||
else
|
||||
# Runners with a subdirectory in the archive
|
||||
echo -e "\nDownloading $runner_url\ninto $runner_dir\n"
|
||||
mkdir -p "$runner_dir" && curl -L "$runner_url" | tar -xzf - -C "$runner_dir"
|
||||
lutris_needs_restart="true"
|
||||
fi
|
||||
}
|
||||
|
||||
# List available runners for download
|
||||
runner_select_install() {
|
||||
# This function expects the name of the runner contributor to be passed in as an argument
|
||||
if [ -z "$1" ]; then
|
||||
echo -e "\nScript error: The runner_select_install function expects an argument. Aborting."
|
||||
read -n 1 -s -p "Press any key..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# set download urls
|
||||
case "$1" in
|
||||
"snatella")
|
||||
latest_url="$snatella_url"
|
||||
runner_versions=($(curl -s "$latest_url" | grep "browser_download_url" | awk '{print $2}' | xargs basename -as .tgz))
|
||||
;;
|
||||
"rawfox")
|
||||
latest_url="$rawfox_url"
|
||||
runner_versions=($(curl -s "$latest_url" | grep "browser_download_url" | awk '{print $2}' | xargs basename -as .tar.gz))
|
||||
;;
|
||||
*)
|
||||
echo -e "\nScript Error: Invalid parameter passed to the runner version function. Aborting."
|
||||
read -n 1 -s -p "Press any key..."
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
# Sanity check
|
||||
if [ "${#runner_versions[@]}" -eq 0 ]; then
|
||||
message warning "No runner versions were found. The Github API may be down or rate limited."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Configure the menu
|
||||
menu_text_zenity="Select the Lutris runner you want to install:"
|
||||
menu_text_terminal="Select the Lutris runner you want to install:"
|
||||
menu_height="500"
|
||||
goback="Return to the runner management menu"
|
||||
unset menu_options
|
||||
unset menu_actions
|
||||
|
||||
# Allow up to max_runners to be displayed in the list
|
||||
if [ "${#runner_versions[@]}" -gt "$max_runners" ]; then
|
||||
runner_count="$max_runners"
|
||||
else
|
||||
runner_count="${#runner_versions[@]}"
|
||||
fi
|
||||
|
||||
# Iterate through the versions, check if they are installed, and add them to the menu options
|
||||
for (( i=0; i<"$runner_count"; i++ )); do
|
||||
if [ -d "$runner_dir/${runner_versions[i]}" ]; then
|
||||
menu_options+=("${runner_versions[i]} [installed]")
|
||||
else
|
||||
menu_options+=("${runner_versions[i]}")
|
||||
fi
|
||||
menu_actions+=("runner_install $i")
|
||||
done
|
||||
|
||||
# Complete the menu by adding the option to go back to the previous menu
|
||||
menu_options+=("$goback")
|
||||
menu_actions+=(":") # no-op
|
||||
|
||||
# Call the menu function. It will use the options as configured above
|
||||
menu
|
||||
}
|
||||
|
||||
# Called when the user is done managing runners. Causes a return to the main menu
|
||||
runner_manage_done() {
|
||||
managing_runners="false"
|
||||
}
|
||||
|
||||
# Manage Lutris runners
|
||||
runner_manage() {
|
||||
# Check if Lutris is installed
|
||||
if [ ! -x "$(command -v lutris)" ]; then
|
||||
message info "Lutris does not appear to be installed."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# The runner management menu will loop until the user cancels
|
||||
managing_runners="true"
|
||||
|
||||
while [ "$managing_runners" = "true" ]; do
|
||||
# Configure the menu
|
||||
menu_text_zenity="<b>This helper can manage your Lutris runners</b>\n\nChoose from the following options:"
|
||||
menu_text_terminal="This helper can manage your Lutris runners<\n\nChoose from the following options:"
|
||||
menu_height="200"
|
||||
|
||||
# Configure the menu options
|
||||
rawfox="Install a runner from RawFox"
|
||||
snatella="Install a runner from Molotov/Snatella"
|
||||
delete="Delete an installed runner"
|
||||
back="Return to the main menu"
|
||||
# Set the options to be displayed in the menu
|
||||
menu_options=("$rawfox" "$snatella" "$delete" "$back")
|
||||
# Set the corresponding functions to be called for each of the options
|
||||
menu_actions=("runner_select_install rawfox" "runner_select_install snatella" "runner_select_delete" "runner_manage_done")
|
||||
|
||||
# Call the menu function. It will use the options as configured above
|
||||
menu
|
||||
done
|
||||
|
||||
# Check if lutris needs to be restarted after making changes
|
||||
lutris_restart
|
||||
}
|
||||
|
||||
# Toggle between targeting the LIVE and PTU game directories for all helper functions
|
||||
set_version() {
|
||||
if [ "$live_or_ptu" = "LIVE" ]; then
|
||||
@ -644,6 +868,7 @@ quit() {
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
############################################################################
|
||||
# MAIN
|
||||
############################################################################
|
||||
@ -654,29 +879,31 @@ if [ -x "$(command -v zenity)" ]; then
|
||||
has_zen=1
|
||||
fi
|
||||
|
||||
# Default to LIVE
|
||||
# Set some defaults
|
||||
live_or_ptu="LIVE"
|
||||
lutris_needs_restart="false"
|
||||
|
||||
# Loop the main menu until the user selects quit
|
||||
while true; do
|
||||
# Configure the menu
|
||||
menu_text_zenity="<b><big>Welcome, fellow Penguin, to the Star Citizen LUG Helper!</big>\n\nThis helper is designed to help optimize your system for Star Citizen</b>\n\nYou may choose from the following options:"
|
||||
menu_text_terminal="Welcome, fellow Penguin, to the Star Citizen Linux Users Group Helper!\n\nThis helper is designed to help optimize your system for Star Citizen\nYou may choose from the following options:"
|
||||
menu_height="315"
|
||||
menu_height="340"
|
||||
|
||||
# Configure the menu options
|
||||
runners_msg="Manage Lutris Runners"
|
||||
sanitize_msg="Delete my Star Citizen USER folder and preserve my keybinds"
|
||||
mapcount_msg="Check vm.max_map_count for optimal performance"
|
||||
filelimit_msg="Check my open file descriptors limit"
|
||||
sanitize_msg="Delete my Star Citizen USER folder and preserve my keybinds"
|
||||
shaders_msg="Delete my shaders only"
|
||||
vidcache_msg="Delete my DXVK cache"
|
||||
version_msg="Switch the helper between LIVE and PTU (default is LIVE)"
|
||||
quit_msg="Quit"
|
||||
|
||||
# Set the options to be displayed in the menu
|
||||
menu_options=("$mapcount_msg" "$filelimit_msg" "$sanitize_msg" "$shaders_msg" "$vidcache_msg" "$version_msg" "$quit_msg")
|
||||
menu_options=("$runners_msg" "$sanitize_msg" "$mapcount_msg" "$filelimit_msg" "$shaders_msg" "$vidcache_msg" "$version_msg" "$quit_msg")
|
||||
# Set the corresponding functions to be called for each of the options
|
||||
menu_actions=("mapcount_set" "filelimit_set" "sanitize" "rm_shaders" "rm_vidcache" "set_version" "quit")
|
||||
menu_actions=("runner_manage" "sanitize" "mapcount_set" "filelimit_set" "rm_shaders" "rm_vidcache" "set_version" "quit")
|
||||
|
||||
# Call the menu function. It will use the options as configured above
|
||||
menu
|
||||
|
Loading…
Reference in New Issue
Block a user