lug-helper/lug-helper.sh

661 lines
23 KiB
Bash
Raw Normal View History

#!/bin/bash
2020-08-02 18:12:02 +00:00
############################################################################
# Star Citizen's Linux Users Group Helper Script
############################################################################
#
# Greetings, fellow Penguin!
2020-08-02 18:12:02 +00:00
#
#
# This script is designed to help you optimize your system to run
# Star Citizen as smoothly as possible.
2020-08-02 18:12:02 +00:00
#
# It presents options to check your system for optimal settings
# and helps you change them as needed to prevent game crashes.
2020-08-02 18:12:02 +00:00
#
#
2020-08-22 01:24:26 +00:00
# It also gives you a fast and easy way to wipe your Star Citizen
# USER folder as is recommended by CIG after major version updates.
# It will back up your exported keybinds, delete your USER folder,
2020-08-22 01:24:26 +00:00
# then restore your keybind file(s).
2020-08-02 18:12:02 +00:00
#
# To export your keybinds from within the game, go to
# Options->Keybindings->Control Profiles->Save Control Settings
#
2020-08-22 01:24:26 +00:00
# To import your keybinds from within the game, select them from the list:
# Options->Keybindings->Control Profiles
#
2020-08-02 18:12:02 +00:00
############################################################################
2020-08-10 20:03:11 +00:00
wine_conf="winedir.conf"
game_conf="gamedir.conf"
backup_conf="backupdir.conf"
# Use the XDG config directory if defined
if [ -z "$XDG_CONFIG_HOME" ]; then
conf_dir="$HOME/.config"
else
conf_dir="$XDG_CONFIG_HOME"
fi
2020-08-02 18:12:02 +00:00
2020-08-10 20:03:11 +00:00
conf_subdir="starcitizen-lug"
2020-08-02 18:12:02 +00:00
############################################################################
############################################################################
2020-08-10 01:30:10 +00:00
# Display a message to the user. Expects a numerical argument to indicate the message type,
# followed by a string of arguments that will be passed to zenity or echoed to the user.
#
# To call this function, use the following format: message [number] [string]
# See the message types below for specific instructions on formatting the string.
message() {
2020-08-03 22:15:38 +00:00
if [ "$has_zen" -eq 1 ]; then
case "$1" in
1)
# info message
# call format: message 1 "text to display"
margs=("--info" "--no-wrap" "--text=")
;;
2)
# warning message
# call format: message 2 "text to display"
margs=("--warning" "--text=")
;;
3)
# question
# call format: message 3 "question to ask?"
margs=("--question" "--text=")
;;
4)
# radio button list
# call format: message 4 "--height=165" "TRUE" "List item 1" "FALSE" "List item 2" "FALSE" "List item 3"
# IMPORTANT: When calling, specify an appropriate height for the dialog based on the number of items in your list
margs=("--list" "--radiolist" "--text=Choose from the following options:" "--hide-header" "--column=" "--column=Option")
;;
5)
# main menu radio list
# call format: message 5 "TRUE" "List item 1" "FALSE" "List item 2" "FALSE" "List item 3"
2020-08-15 16:23:25 +00:00
# IMPORTANT: Adjust the height value below based on the number of items listed in the menu
margs=("--list" "--radiolist" "--height=320" "--text=<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:" "--hide-header" "--column=" "--column=Option")
;;
*)
2020-08-15 16:23:25 +00:00
echo -e "Invalid message format.\n\nThe message function expects a numerical argument followed by string arguments.\n"
read -n 1 -s -p "Press any key..."
;;
esac
2020-08-02 18:12:02 +00:00
2020-08-03 22:15:38 +00:00
# Display the message
2020-08-04 01:32:00 +00:00
if [ "$1" -eq 4 ] || [ "$1" -eq 5 ]; then
# requires a space between the assembled arguments
shift 1 # drop the first numerical argument and shift the remaining up one
2020-08-18 01:57:24 +00:00
zenity "${margs[@]}" "$@" --width="400" --title="Star Citizen LUG Helper"
2020-08-04 01:32:00 +00:00
else
# no space between the assmebled arguments
shift 1 # drop the first numerical argument and shift the remaining up one
2020-08-18 01:57:24 +00:00
zenity "${margs[@]}""$@" --width="400" --title="Star Citizen LUG Helper"
2020-08-04 01:32:00 +00:00
fi
else
# Text based menu. Does not work with message types 4 and 5 (zenity radio lists)
# those need to be handled specially in the code
case "$1" in
1)
# info message
# call format: message 1 "text to display"
clear
echo -e "\n$2\n"
read -n 1 -s -p "Press any key..."
;;
2)
# warning message
# call format: message 2 "text to display"
clear
echo -e "\n$2\n"
read -n 1 -s -p "Press any key..."
return 0
;;
3)
# question
# call format: message 3 "question to ask?"
clear
echo -e "$2"
while read -p "[y/n]: " yn; do
case "$yn" in
[Yy]*)
return 0
;;
[Nn]*)
return 1
;;
*)
echo "Please type 'y' or 'n'"
;;
esac
done
;;
*)
echo -e "\nInvalid message type.\n\nText menus are not compatible with message types 4 and 5 (zenity radio lists)\nand require special handling.\n"
read -n 1 -s -p "Press any key..."
;;
esac
fi
2020-08-02 18:12:02 +00:00
}
2020-08-10 20:03:11 +00:00
# Get paths to the user's wine prefix, game directory, and a backup directory
2020-08-10 01:30:10 +00:00
getdirs() {
2020-08-10 20:03:11 +00:00
# Sanity checks
if [ ! -d "$conf_dir" ]; then
2020-08-18 01:57:24 +00:00
message 2 "Config directory not found. The helper is unable to proceed.\n\n$conf_dir"
2020-08-15 02:33:04 +00:00
return 1
2020-08-10 20:03:11 +00:00
fi
if [ ! -d "$conf_dir/$conf_subdir" ]; then
mkdir "$conf_dir/$conf_subdir"
fi
# Check if the config files already exist
if [ -f "$conf_dir/$conf_subdir/$wine_conf" ]; then
2020-08-12 00:42:44 +00:00
wine_prefix="$(cat "$conf_dir/$conf_subdir/$wine_conf")"
2020-08-22 01:02:16 +00:00
if [ ! -d "$wine_prefix" ]; then
echo -e "\nThe saved wine prefix does not exist, ignoring.\n"
wine_prefix=""
fi
2020-08-10 20:03:11 +00:00
fi
if [ -f "$conf_dir/$conf_subdir/$game_conf" ]; then
2020-08-12 00:42:44 +00:00
game_path="$(cat "$conf_dir/$conf_subdir/$game_conf")"
2020-08-22 01:02:16 +00:00
if [ ! -d "$game_path" ] || [ "$(basename "$game_path")" != "Star Citizen" ]; then
2020-08-18 01:57:24 +00:00
echo -e "\nUnexpected game path found in config file, ignoring.\n"
game_path=""
fi
2020-08-10 20:03:11 +00:00
fi
if [ -f "$conf_dir/$conf_subdir/$backup_conf" ]; then
2020-08-12 00:42:44 +00:00
backup_path="$(cat "$conf_dir/$conf_subdir/$backup_conf")"
2020-08-22 01:02:16 +00:00
if [ ! -d "$backup_path" ]; then
echo -e "\nThe saved backup path does not exist, ignoring.\n"
backup_path=""
fi
2020-08-10 20:03:11 +00:00
fi
2020-08-22 01:02:16 +00:00
# If we don't have the directory paths we need yet, ask the user to provide them
2020-08-12 02:02:44 +00:00
if [ -z "$wine_prefix" ] || [ -z "$game_path" ] || [ -z "$backup_path" ]; then
2020-08-18 01:57:24 +00:00
message 1 "You will now be asked to provide some directories needed by the helper.\n\nThey will be saved for later use in:\n$conf_dir/$conf_subdir/"
2020-08-12 00:42:44 +00:00
if [ "$has_zen" -eq 1 ]; then
# Get the wine prefix directory
2020-08-12 02:02:44 +00:00
if [ -z "$wine_prefix" ]; then
wine_prefix="$(zenity --file-selection --directory --title="Select your WINE prefix directory" --filename="$HOME/.wine")"
2020-08-12 00:42:44 +00:00
if [ "$?" -eq -1 ]; then
2020-08-18 01:57:24 +00:00
message 2 "An unexpected error has occurred. The helper is unable to proceed."
2020-08-15 02:33:04 +00:00
return 1
2020-08-12 02:02:44 +00:00
elif [ -z "$wine_prefix" ]; then
# User clicked cancel
2020-08-15 02:33:04 +00:00
message 2 "Operation cancelled.\nNo changes have been made to your game."
return 1
2020-08-12 00:42:44 +00:00
fi
2020-08-10 20:03:11 +00:00
fi
2020-08-12 00:42:44 +00:00
# Get the game path
2020-08-12 02:02:44 +00:00
if [ -z "$game_path" ]; then
2020-08-18 01:57:24 +00:00
while game_path="$(zenity --file-selection --directory --title="Select your Star Citizen directory" --filename="$wine_prefix/drive_c/Program Files/Roberts Space Industries/Star Citizen")"; do
2020-08-12 00:42:44 +00:00
if [ "$?" -eq -1 ]; then
2020-08-18 01:57:24 +00:00
message 2 "An unexpected error has occurred. The helper is unable to proceed."
2020-08-15 02:33:04 +00:00
return 1
2020-08-18 01:57:24 +00:00
elif [ "$(basename "$game_path")" != "Star Citizen" ]; then
message 2 "You must select the directory named 'Star Citizen'"
2020-08-12 02:02:44 +00:00
else
# All good or cancel
2020-08-12 00:42:44 +00:00
break
fi
done
2020-08-12 02:02:44 +00:00
if [ -z "$game_path" ]; then
# User clicked cancel
2020-08-15 02:33:04 +00:00
message 2 "Operation cancelled.\nNo changes have been made to your game."
return 1
2020-08-12 02:02:44 +00:00
fi
2020-08-12 00:42:44 +00:00
fi
2020-08-10 20:03:11 +00:00
2020-08-12 00:42:44 +00:00
# Get the backup directory
2020-08-12 02:02:44 +00:00
if [ -z "$backup_path" ]; then
2020-08-12 00:42:44 +00:00
backup_path="$(zenity --file-selection --directory --title="Select a backup directory for your keybinds" --filename="$HOME/")"
if [ "$?" -eq -1 ]; then
2020-08-18 01:57:24 +00:00
message 2 "An unexpected error has occurred. The helper is unable to proceed."
2020-08-15 02:33:04 +00:00
return 1
2020-08-12 02:02:44 +00:00
elif [ -z "$backup_path" ]; then
# User clicked cancel
2020-08-15 02:33:04 +00:00
message 2 "Operation cancelled.\nNo changes have been made to your game."
return 1
2020-08-12 00:42:44 +00:00
fi
2020-08-10 20:03:11 +00:00
fi
2020-08-12 00:42:44 +00:00
else
clear
# Get the wine prefix directory
2020-08-12 02:02:44 +00:00
if [ -z "$wine_prefix" ]; then
echo -e "Enter the full path to your WINE prefix directory (case sensitive)"
2020-08-12 00:42:44 +00:00
echo -e "ie. /home/USER/.wine/"
while read -rp ": " wine_prefix; do
if [ ! -d "$wine_prefix" ]; then
echo -e "That directory is invalid or does not exist. Please try again.\n"
else
break
fi
done
2020-08-10 01:30:10 +00:00
2020-08-12 00:42:44 +00:00
# Get the game path
2020-08-12 02:02:44 +00:00
if [ -z "$game_path" ]; then
2020-08-18 01:57:24 +00:00
echo -e "\nEnter the full path to your Star Citizen installation directory\n(case sensitive)"
echo -e "ie. /home/USER/.wine/drive_c/Program Files/Roberts Space Industries/Star Citizen/"
2020-08-12 00:42:44 +00:00
while read -rp ": " game_path; do
if [ ! -d "$game_path" ]; then
echo -e "That directory is invalid or does not exist. Please try again.\n"
2020-08-18 01:57:24 +00:00
elif [ "$(basename "$game_path")" != "Star Citizen" ]; then
echo -e "You must enter the full path to the directory named 'Star Citizen'"
2020-08-12 00:42:44 +00:00
else
break
fi
done
fi
2020-08-10 01:30:10 +00:00
2020-08-12 00:42:44 +00:00
# Get the backup directory
2020-08-12 02:02:44 +00:00
if [ -z "$backup_path" ]; then
echo -e "\nEnter the full path to a backup directory for your keybinds (case sensitive)"
2020-08-12 00:42:44 +00:00
echo -e "ie. /home/USER/backups/"
while read -rp ": " backup_path; do
if [ ! -d "$backup_path" ]; then
echo -e "That directory is invalid or does not exist. Please try again.\n"
else
break
fi
done
fi
fi
fi
2020-08-10 20:03:11 +00:00
# Save the paths for later use
echo "$wine_prefix" > "$conf_dir/$conf_subdir/$wine_conf"
echo "$game_path" > "$conf_dir/$conf_subdir/$game_conf"
echo "$backup_path" > "$conf_dir/$conf_subdir/$backup_conf"
fi
# Set some remaining directory paths
2020-08-18 01:57:24 +00:00
user_dir="$game_path/$live_or_ptu/USER"
2020-08-10 20:03:11 +00:00
mappings_dir="$user_dir/Controls/Mappings"
2020-08-10 01:30:10 +00:00
}
2020-08-02 18:12:02 +00:00
# Save exported keybinds, wipe the USER directory, and restore keybinds
sanitize() {
2020-08-12 00:42:44 +00:00
# Prompt user to back up the current keybinds in the game
message 1 "Before proceeding, please be sure you have exported\nyour Star Citizen keybinds from within the game.\n\nTo do this, launch the game and go to:\nOptions->Keybindings->Control Profiles->Save Control Settings"
2020-08-10 20:03:11 +00:00
2020-08-12 00:42:44 +00:00
# Get/Set directory paths
getdirs
2020-08-15 02:33:04 +00:00
if [ "$?" -eq 1 ]; then
# User cancelled and wants to return to the main menu, or there was an error
return 0
fi
2020-08-02 18:12:02 +00:00
2020-08-12 02:46:05 +00:00
# Sanity check
if [ ! -d "$user_dir" ]; then
2020-08-22 01:02:16 +00:00
message 2 "USER directory not found. There is nothing to delete!\n\n$user_dir"
2020-08-15 02:33:04 +00:00
return 0
2020-08-12 02:46:05 +00:00
fi
2020-08-12 00:42:44 +00:00
# Check for exported keybind files
if [ ! -d "$mappings_dir" ] || [ -z "$(ls -A "$mappings_dir")" ]; then
if message 3 "Warning: No exported keybindings found.\nContinuing will erase your existing keybinds!\n\nDo you want to continue anyway?"; then
2020-08-12 02:46:05 +00:00
exported=0
else
2020-08-15 02:33:04 +00:00
# User said no
return 0
2020-08-12 02:46:05 +00:00
fi
2020-08-12 00:42:44 +00:00
else
exported=1
fi
2020-08-02 18:12:02 +00:00
2020-08-23 14:01:38 +00:00
if message 3 "This helper will delete the following directory:\n\n$user_dir\n\nDo you want to proceed?"; then
# Back up keybinds
if [ "$exported" -eq 1 ]; then
echo "Backing up all saved keybinds..."
cp -r "$mappings_dir/." "$backup_path/keybinds/"
echo -e "Done.\n"
fi
# Wipe the user directory
echo "Wiping USER directory..."
rm -r "$user_dir"
2020-08-12 00:42:44 +00:00
echo -e "Done.\n"
2020-08-02 18:12:02 +00:00
2020-08-23 14:01:38 +00:00
# Restore custom keybinds
if [ "$exported" -eq 1 ]; then
echo "Restoring keybinds..."
mkdir -p "$mappings_dir" && cp -r "$backup_path/keybinds/." "$mappings_dir/"
echo -e "Done.\n"
message 1 "To re-import your keybinds, select it in-game from the list:\nOptions->Keybindings->Control Profiles"
fi
message 1 "Your Star Citizen USER directory has been cleaned up!"
fi
2020-08-02 18:12:02 +00:00
}
# Check if setting vm.max_map_count was successful
2020-08-17 21:53:25 +00:00
check_mapcount() {
2020-08-02 18:12:02 +00:00
if [ "$(cat /proc/sys/vm/max_map_count)" -lt 16777216 ]; then
2020-08-18 01:57:24 +00:00
message 2 "As far as this helper can detect, vm.max_map_count\nwas not successfully configured on your system.\n\nYou will most likely experience crashes."
2020-08-02 18:12:02 +00:00
fi
}
# Check vm.max_map_count for the correct setting and let the user fix it if needed
2020-08-17 21:53:25 +00:00
set_mapcount() {
2020-08-02 18:12:02 +00:00
# If vm.max_map_count is already set, no need to do anything
if [ "$(cat /proc/sys/vm/max_map_count)" -ge 16777216 ]; then
message 1 "vm.max_map_count is already set to the optimal value.\nYou're all set!"
2020-08-15 02:33:04 +00:00
return 0
2020-08-02 18:12:02 +00:00
fi
2020-08-22 01:02:16 +00:00
# Otherwise, check to see if it was supposed to be set by sysctl
2020-08-02 18:12:02 +00:00
if grep -E -x -q "vm.max_map_count" /etc/sysctl.conf /etc/sysctl.d/* 2>/dev/null; then
2020-08-17 21:53:25 +00:00
if message 3 "It looks like you've already configured vm.max_map_count\nand saved the setting to persist across reboots.\nHowever, for some reason the persistence part did not work.\n\nFor now, would you like to enable the setting again until the next reboot?"; then
2020-08-02 18:12:02 +00:00
pkexec sh -c 'sysctl -w vm.max_map_count=16777216'
fi
2020-08-17 21:53:25 +00:00
check_mapcount
2020-08-15 02:33:04 +00:00
return 0
2020-08-02 18:12:02 +00:00
fi
once="Change setting until next reboot"
persist="Change setting and persist after reboot"
manual="Show me the commands; I'll handle it myself"
goback="Return to the main menu"
2020-08-15 16:23:25 +00:00
newsysctl_msg="To change the setting (a kernel parameter) until next boot, run:\n\nsudo sh -c 'sysctl -w vm.max_map_count=16777216'\n\n\nTo persist the setting between reboots, run:\n\nsudo sh -c 'echo \"vm.max_map_count = 16777216\" >> /etc/sysctl.d/20-max_map_count.conf &amp;&amp; sysctl -p'"
oldsysctl_msg="To change the setting (a kernel parameter) until next boot, run:\n\nsudo sh -c 'sysctl -w vm.max_map_count=16777216'\n\n\nTo persist the setting between reboots, run:\n\nsudo sh -c 'echo \"vm.max_map_count = 16777216\" >> /etc/sysctl.conf &amp;&amp; sysctl -p'"
2020-08-02 18:12:02 +00:00
2020-08-22 01:43:50 +00:00
message 1 "Running Star Citizen requires changing a system setting\nto give the game access to more than 8GB of memory.\n\nvm.max_map_count must be increased to at least 16777216\nto avoid crashes in areas with lots of geometry.\n\n\nAs far as this helper can detect, the setting\nhas not been changed on your system.\n\nYou will now be given the option to change it."
if [ "$has_zen" -eq 1 ]; then
# zenity menu
options_mapcount=("--height=165" "TRUE" "$once" "FALSE" "$persist" "FALSE" "$manual")
choice="$(message 4 "${options_mapcount[@]}")"
case "$choice" in
"$once")
pkexec sh -c 'sysctl -w vm.max_map_count=16777216'
check_mapcount
;;
"$persist")
if [ -d "/etc/sysctl.d" ]; then
pkexec sh -c 'echo "vm.max_map_count = 16777216" >> /etc/sysctl.d/20-max_map_count.conf && sysctl -p'
else
pkexec sh -c 'echo "vm.max_map_count = 16777216" >> /etc/sysctl.conf && sysctl -p'
fi
check_mapcount
;;
"$manual")
if [ -d "/etc/sysctl.d" ]; then
message 1 "$newsysctl_msg"
else
message 1 "$oldsysctl_msg"
fi
;;
*)
check_mapcount
return 0
;;
esac
else
# text menu
clear
echo -e "\nThis helper can change vm.max_map_count for you.\nChoose from the following options:\n"
options_mapcount=("$once" "$persist" "$manual" "$goback")
PS3="Enter selection number: "
select choice in "${options_mapcount[@]}"
do
case "$choice" in
"$once")
2020-08-22 01:43:50 +00:00
pkexec sh -c 'sysctl -w vm.max_map_count=16777216'
2020-08-17 21:53:25 +00:00
check_mapcount
2020-08-22 01:43:50 +00:00
break
;;
"$persist")
2020-08-22 01:43:50 +00:00
if [ -d "/etc/sysctl.d" ]; then
pkexec sh -c 'echo "vm.max_map_count = 16777216" >> /etc/sysctl.d/20-max_map_count.conf && sysctl -p'
else
2020-08-03 22:15:38 +00:00
pkexec sh -c 'echo "vm.max_map_count = 16777216" >> /etc/sysctl.conf && sysctl -p'
2020-08-22 01:43:50 +00:00
fi
2020-08-17 21:53:25 +00:00
check_mapcount
2020-08-22 01:43:50 +00:00
break
;;
"$manual")
2020-08-22 01:43:50 +00:00
if [ -d "/etc/sysctl.d" ]; then
message 1 "$newsysctl_msg"
else
message 1 "$oldsysctl_msg"
fi
break
;;
"$goback")
2020-08-17 21:53:25 +00:00
check_mapcount
2020-08-22 01:43:50 +00:00
break
;;
*)
echo -e "\nInvalid selection"
continue
;;
2020-08-03 22:15:38 +00:00
esac
2020-08-22 01:43:50 +00:00
done
2020-08-02 18:12:02 +00:00
fi
}
2020-09-04 00:56:53 +00:00
# Check if setting the open file descriptors limit was successful
check_filelimit() {
2020-09-04 00:56:53 +00:00
if [ "$(ulimit -Hn)" -lt 524288 ]; then
message 2 "As far as this helper can detect, the open files limit\nwas not successfully configured on your system.\nYou may experience crashes.\n\nWe recommend manually configuring this limit to at least 524288."
fi
}
# Check the open file descriptors limit for the correct setting and let the user fix it if needed
set_filelimit() {
filelimit="$(ulimit -Hn)"
2020-09-04 00:56:53 +00:00
# If the file limit is already set, no need to do anything
if [ "$filelimit" -ge 524288 ]; then
message 1 "Your open files limit is already set to the optimal value.\nYou're all set!"
2020-09-04 00:56:53 +00:00
return 0
fi
2020-09-04 01:20:06 +00:00
# Adjust the limit
2020-09-04 00:56:53 +00:00
if message 3 "We recommend setting the hard open\nfile descriptors limit to at least 524288.\n\nThe current value on your system appears to be $filelimit.\n\nWould you like this helper to change it for you?"; then
if [ -f "/etc/systed/system.conf" ]; then
# Using systemd
echo -e "Updating /etc/systemd/system.conf..."
# Append to the file
pkexec sh -c 'echo "DefaultLimitNOFILE=524288 >> /etc/systemd/system.conf && systemctl daemon-reexec'
echo -e "Done.\n"
elif [ -f "/etc/security/limits.conf" ]; then
# Using limits.conf
echo -e "Updating /etc/security/limits.conf..."
# Insert before the last line in the file
pkexec sh -c 'sed -i "\$i* hard nofile 524288" /etc/security/limits.conf'
echo -e "Done.\n"
else
2020-09-04 01:20:06 +00:00
# Don't know what method to use
2020-09-04 00:56:53 +00:00
message 2 "This helper is unable to detect the correct method of setting\nthe open file descriptors limit on your system.\n\nWe recommend manually configuring this limit to at least 524288."
2020-09-04 01:20:06 +00:00
return 0
2020-09-04 00:56:53 +00:00
fi
fi
2020-09-04 01:20:06 +00:00
# Verify that setting the limit was successful
check_filelimit
}
2020-08-17 21:53:25 +00:00
# Delete the shaders directory
rm_shaders() {
# Get/Set directory paths
getdirs
if [ "$?" -eq 1 ]; then
# User cancelled and wants to return to the main menu, or there was an error
return 0
fi
2020-08-22 01:02:16 +00:00
shaders_dir="$user_dir/Shaders"
2020-08-17 21:53:25 +00:00
# Sanity check
if [ ! -d "$shaders_dir" ]; then
message 2 "Shaders directory not found. There is nothing to delete!\n\n$shaders_dir"
return 0
fi
# Delete the shader directory
2020-08-23 14:01:38 +00:00
if message 3 "This helper will delete the following directory:\n\n$shaders_dir\n\nDo you want to proceed?"; then
echo "Deleting shaders..."
rm -r "$shaders_dir"
echo -e "Done.\n"
message 1 "Your shaders have been deleted!"
fi
2020-08-17 21:53:25 +00:00
}
2020-08-21 22:49:28 +00:00
# Delete DXVK cache
2020-08-17 21:53:25 +00:00
rm_vidcache() {
# Get/Set directory paths
getdirs
if [ "$?" -eq 1 ]; then
# User cancelled and wants to return to the main menu, or there was an error
return 0
fi
2020-08-22 01:02:16 +00:00
dxvk_cache="$game_path/$live_or_ptu/StarCitizen-dxvk.cache"
2020-08-17 21:53:25 +00:00
# Sanity check
2020-08-21 22:49:28 +00:00
if [ ! -f "$dxvk_cache" ]; then
message 2 "Unable to find the DXVK cache file. There is nothing to delete!\n\n$dxvk_cache"
2020-08-17 21:53:25 +00:00
return 0
fi
2020-08-21 22:49:28 +00:00
# Delete the cache file
2020-08-23 14:01:38 +00:00
if message 3 "This helper will delete the following file:\n\n$dxvk_cache\n\nDo you want to proceed?"; then
echo "Deleting DXVK cache..."
rm "$dxvk_cache"
echo -e "Done.\n"
message 1 "Your DXVK cache has been deleted!"
fi
2020-08-17 21:53:25 +00:00
}
2020-08-19 01:19:26 +00:00
# Toggle between targeting the LIVE and PTU game directories for all helper functions
set_version() {
if [ "$live_or_ptu" == "LIVE" ]; then
live_or_ptu="PTU"
message 1 "The helper will now target your Star Citizen PTU installation."
elif [ "$live_or_ptu" == "PTU" ]; then
live_or_ptu="LIVE"
message 1 "The helper will now target your Star Citizen LIVE installation."
else
echo -e "\nUnexpected game version provided. Defaulting to the LIVE installation."
live_or_ptu="LIVE"
fi
}
# Display the main menu
main_menu() {
# Set the menu options
2020-08-19 01:19:26 +00:00
mapcount_msg="Check vm.max_map_count for optimal performance"
filelimit_msg="Check my open file descriptors limit"
2020-08-23 14:01:38 +00:00
sanitize_msg="Delete my Star Citizen USER folder and preserve my keybinds"
2020-08-19 01:19:26 +00:00
shaders_msg="Delete my shaders only"
2020-08-21 22:49:28 +00:00
vidcache_msg="Delete my DXVK cache"
2020-08-19 01:19:26 +00:00
version_msg="Switch the helper between LIVE and PTU (default is LIVE)"
quit_msg="Quit"
2020-08-02 18:12:02 +00:00
# Use Zenity if it is available
if [ "$has_zen" -eq 1 ]; then
options_main=("TRUE" "$mapcount_msg" "FALSE" "$filelimit_msg" "FALSE" "$sanitize_msg" "FALSE" "$shaders_msg" "FALSE" "$vidcache_msg" "FALSE" "$version_msg")
2020-08-02 18:12:02 +00:00
choice="$(message 5 "${options_main[@]}")"
case "$choice" in
2020-08-19 01:19:26 +00:00
"$mapcount_msg")
2020-08-17 21:53:25 +00:00
set_mapcount
2020-08-02 18:12:02 +00:00
;;
"$filelimit_msg")
2020-09-04 00:56:53 +00:00
set_filelimit
;;
2020-08-19 01:19:26 +00:00
"$sanitize_msg")
2020-08-02 18:12:02 +00:00
sanitize
;;
2020-08-19 01:19:26 +00:00
"$shaders_msg")
2020-08-17 21:53:25 +00:00
rm_shaders
;;
2020-08-19 01:19:26 +00:00
"$vidcache_msg")
2020-08-17 21:53:25 +00:00
rm_vidcache
;;
2020-08-19 01:19:26 +00:00
"$version_msg")
set_version
2020-08-18 01:57:24 +00:00
;;
2020-08-02 18:12:02 +00:00
*)
exit 0
2020-08-02 18:12:02 +00:00
;;
esac
else
# Use a text menu if Zenity is not available
clear
2020-08-18 01:57:24 +00:00
echo -e "\nWelcome, 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:\n"
options_main=("$mapcount_msg" "$filelimit_msg" "$sanitize_msg" "$shaders_msg" "$vidcache_msg" "$version_msg" "$quit_msg")
PS3="Enter selection number: "
select choice in "${options_main[@]}"
do
case "$choice" in
2020-08-19 01:19:26 +00:00
"$mapcount_msg")
echo -e "\n"
2020-08-17 21:53:25 +00:00
set_mapcount
break
;;
"$filelimit_msg")
echo -e "\n"
2020-09-04 00:56:53 +00:00
set_filelimit
break
;;
2020-08-19 01:19:26 +00:00
"$sanitize_msg")
echo -e "\n"
sanitize
break
;;
2020-08-19 01:19:26 +00:00
"$shaders_msg")
2020-08-17 21:53:25 +00:00
echo -e "\n"
rm_shaders
break
;;
2020-08-19 01:19:26 +00:00
"$vidcache_msg")
2020-08-17 21:53:25 +00:00
echo -e "\n"
rm_vidcache
break
;;
2020-08-19 01:19:26 +00:00
"$version_msg")
2020-08-18 01:57:24 +00:00
echo -e "\n"
2020-08-19 01:19:26 +00:00
set_version
2020-08-18 01:57:24 +00:00
break
;;
2020-08-19 01:19:26 +00:00
"$quit_msg")
exit 0
;;
*)
echo -e "\nInvalid selection"
continue
;;
esac
done
fi
}
############################################################################
# MAIN
############################################################################
# Check if Zenity is available
has_zen=0
if [ -x "$(command -v zenity)" ]; then
has_zen=1
2020-08-02 18:12:02 +00:00
fi
2020-08-18 01:57:24 +00:00
# Default to LIVE
live_or_ptu="LIVE"
# Loop the main menu until the user selects quit
while true; do
main_menu
done