Add support for text and zenity menus throughout.

Not yet tested. Likely broken.
This commit is contained in:
the-sane 2020-08-03 15:49:19 -04:00 committed by GitHub
parent 7cbe197991
commit 7002579c3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,49 +45,88 @@ if [ -x "$(command -v zenity)" ]; then
zenity=1 zenity=1
fi fi
main_dialog(){ # Display a message to the user. Expects a numerical argument followed by the string to display.
zenity "$@" --icon-name='lutris' --width="400" --title="Star Citizen LUG Helper Script" message() {
} if [ "$zenity" -eq 1 ]; then
if [ "$1" -eq 1 ]; then
# info
margs="--info --no-wrap --text="
elif [ "$1" -eq 2 ]; then
# warning
margs="--warning --no-wrap --text="
elif [ "$1" -eq 3 ]; then
# question
margs="--question --text="
elif [ "$1" -eq 4 ]; then
# radio list
margs="--list --radiolist --height=\"200\" --column=\" \" --column=\"What would you like to do?\" "
elif [ "$1" -eq 5]; then
# main menu radio list
margs="--list --radiolist --height=\"175\" --text="Welcome, fellow penguin, to the Star Citizen Linux Users Group Helper Script!" --column=\" \" --column=\"What would you like to do?\" "
else
echo -e "Invalid message format.\n\nThe message function expects a numerical argument followed by the string to display.\n"
read -n 1 -s -p "Press any key..."
fi
mem_dialog() { # Display the message
zenity "$@" --icon-name='lutris' --width="400" --title="Star Citizen memory requirements check" zenity "$margs$2" --icon-name='lutris' --width="400" --title="Star Citizen LUG Helper Script"
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
if [ "$1" -eq 1 ]; then
# info
echo -e "\n$2\n"
read -n 1 -s -p "Press any key..."
elif [ "$1" -eq 2 ]; then
# warning
echo -e "\n$2\n"
read -n 1 -s -p "Press any key..."
exit 0
elif [ "$1" -eq 3 ]; then
# question
echo -e "\n$2\n"
while true; do
read -p "[y/n]: " yn
case "$yn" in
[Yy]*)
return 0
;;
[Nn]*)
return 1
;;
*)
echo "Please type 'y' or 'n'"
;;
esac
done
else
echo -e "Invalid 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..."
fi
fi
} }
# Save exported keybinds, wipe the USER directory, and restore keybinds # Save exported keybinds, wipe the USER directory, and restore keybinds
sanitize() { sanitize() {
clear
# Display a warning to modify the default variables # Display a warning to modify the default variables
if [ "$i_changed_these" = "false" ]; then if [ "$i_changed_these" = "false" ]; then
if [ "$zenity" -eq 1 ]; then message 2 "Before this script can do its job, please edit it to change the default\nStar Citizen paths to match your configuration!\n"
main_dialog --info --text="Before you run this script, edit it and change the default Star Citizen paths to match your configuration!"
else
echo "Before you run this script, edit it and change the default"
echo -e "Star Citizen paths to match your configuration!\n"
read -n 1 -s -p "Press any key to exit..."
fi
else else
# Sanity checks # Sanity checks
if [ ! -d "$prefix" ]; then if [ ! -d "$prefix" ]; then
echo "Invalid path: $prefix" message 2 "Invalid path:\n$prefix\nAborting."
echo "Aborting"
elif [ ! -d "$path" ]; then elif [ ! -d "$path" ]; then
echo "Invalid path: $path" message 2 "Invalid path:\n$path\nAborting."
echo "Aborting"
else else
# Prompt user to back up the current keybinds in the game # Prompt user to back up the current keybinds in the game
echo "Before proceeding, please be sure you have" message 1 "Before proceeding, please be sure you have\nmade a backup of your Star Citizen keybinds!\nTo do this from within the game, go to\nOptions->Keybindings->Control Profiles->Save Control Settings\nGive it a name and save it to the backup location\nthat you specified in this script's variables."
echo -e "made a backup of your Star Citizen keybinds!\n"
echo "To do this from within the game, go to"
echo -e "Options->Keybindings->Control Profiles->Save Control Settings\n"
echo "Give it a name and save it to the backup location"
echo -e "that you specified in this script's variables\n"
read -n 1 -s -p "Press any key to continue, or Ctrl-c to quit..."
echo -e "\n----------------------------------------------------------------\n"
# Check for exported keybind files # Check for exported keybind files
exported=0 # Default to none found exported=0 # Default to none found
if [ ! -d "$mappings" ] || [ -z "$(ls -A $mappings)" ]; then if [ ! -d "$mappings" ] || [ -z "$(ls -A $mappings)" ]; then
echo "Warning: No exported keybindings found. Keybinds will not be backed up!" message 1 "Warning: No exported keybindings found. Keybinds will not be backed up!"
exported=0 exported=0
else else
exported=1 exported=1
@ -110,9 +149,7 @@ sanitize() {
echo "Restoring keybinds..." echo "Restoring keybinds..."
mkdir -p "$mappings" && cp -r "$backups/." "$mappings/" mkdir -p "$mappings" && cp -r "$backups/." "$mappings/"
echo -e "Done.\n" echo -e "Done.\n"
echo "*NOTE*" message 1 "\nTo re-import your keybinds, select it in-game from the list:\nOptions->Keybindings->Control Profiles\n"
echo "To re-import your keybinds, select it in-game from the list:"
echo -e "Options->Keybindings->Control Profiles\n"
fi fi
@ -128,30 +165,25 @@ sanitize() {
fi fi
} }
final_check() { check_map_count() {
if [ "$(cat /proc/sys/vm/max_map_count)" -lt 16777216 ]; then if [ "$(cat /proc/sys/vm/max_map_count)" -lt 16777216 ]; then
mem_dialog --warning --text="As far as this script can detect, your system is not configured to allow Star Citizen to use more than ~8GB or memory.\n\nYou will most likely experience crashes." message 2 "As far as this script can detect, your system is not configured\nto allow Star Citizen to use more than ~8GB or memory.\n\nYou will most likely experience crashes."
fi fi
} }
# Check vm.max_map_count for the correct setting and let the user fix it if needed # Check vm.max_map_count for the correct setting and let the user fix it if needed
mem_check() { set_map_count() {
# Zenity Check clear
if [ "$zenity" -eq 0 ]; then
echo "Zenity is not installed. Text menus have not yet been implemented"
exit 0
fi
# If vm.max_map_count is already set, no need to do anything # If vm.max_map_count is already set, no need to do anything
if [ "$(cat /proc/sys/vm/max_map_count)" -ge 16777216 ]; then if [ "$(cat /proc/sys/vm/max_map_count)" -ge 16777216 ]; then
main_dialog --info --text="vm.max_map_count is already set to the optimal value. You're all set!" message 1 "vm.max_map_count is already set to the optimal value. You're all set!"
exit 0 exit 0
fi fi
trap final_check EXIT trap check_map_count EXIT
if grep -E -x -q "vm.max_map_count" /etc/sysctl.conf /etc/sysctl.d/* 2>/dev/null; then if grep -E -x -q "vm.max_map_count" /etc/sysctl.conf /etc/sysctl.d/* 2>/dev/null; then
if mem_dialog --question --text="It looks like you already configured your system to work with Star Citizen, and saved the setting to persist across reboots. However, 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 if message 3 "It looks like you already configured your system to work with Star Citizen, and saved the setting to persist across reboots. However, 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
pkexec sh -c 'sysctl -w vm.max_map_count=16777216' pkexec sh -c 'sysctl -w vm.max_map_count=16777216'
fi fi
exit 0 exit 0
@ -161,34 +193,74 @@ mem_check() {
persist="Change setting and persist after reboot" persist="Change setting and persist after reboot"
manual="Show me the commands; I'll handle it myself" manual="Show me the commands; I'll handle it myself"
if mem_dialog --question --text="Running Star Citizen requires changing a system setting.\n\nvm.max_map_count must be increased to at least 16777216 to avoid crashes in areas with lots of geometry.\n\nAs far as this script can detect, the setting has not been changed on your system.\n\nWould you like to change the setting now?"; then if message 3 "Running Star Citizen requires changing a system setting.\n\nvm.max_map_count must be increased to at least 16777216 to avoid crashes in areas with lots of geometry.\n\nAs far as this script can detect, the setting has not been changed on your system.\n\nWould you like to change the setting now?"; then
# I tried to embed the command in the dialog and run the output, but if [ "$zenity" -eq 1 ]; then
# parsing variables with embedded quotes is an excercise in frustration. # zenity menu
RESULT="$(mem_dialog --list --radiolist --height="200" --column=" " --column="Command" "TRUE" "$once" \ "FALSE" "$persist" \ "FALSE" "$manual")" RESULT="$(message 4 "TRUE $once \ FALSE $persist \ FALSE $manual")"
case "$RESULT" in case "$RESULT" in
"$once") "$once")
pkexec sh -c 'sysctl -w vm.max_map_count=16777216' pkexec sh -c 'sysctl -w vm.max_map_count=16777216'
;; ;;
"$persist") "$persist")
if [ -d "/etc/sysctl.d" ]; then 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' pkexec sh -c 'echo "vm.max_map_count = 16777216" >> /etc/sysctl.d/20-max_map_count.conf && sysctl -p'
else else
pkexec sh -c 'echo "vm.max_map_count = 16777216" >> /etc/sysctl.conf && sysctl -p' pkexec sh -c 'echo "vm.max_map_count = 16777216" >> /etc/sysctl.conf && sysctl -p'
fi fi
;; ;;
"$manual") "$manual")
if [ -d "/etc/sysctl.d" ]; then if [ -d "/etc/sysctl.d" ]; then
mem_dialog --info --no-wrap --text="To change the setting (a kernel parameter) until next boot, run:\n\nsudo sh -c 'sysctl -w vm.max_map_count=16777216'\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 && sysctl -p'" message 1 "To change the setting (a kernel parameter) until next boot, run:\n\nsudo sh -c 'sysctl -w vm.max_map_count=16777216'\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 && sysctl -p'"
else else
mem_dialog --info --no-wrap --text="To change the setting (a kernel parameter) until next boot, run:\n\nsudo sh -c 'sysctl -w vm.max_map_count=16777216'\n\nTo persist the setting between reboots, run:\n\nsudo sh -c 'echo \"vm.max_map_count = 16777216\" >> /etc/sysctl.conf && sysctl -p'" message 1 "To change the setting (a kernel parameter) until next boot, run:\n\nsudo sh -c 'sysctl -w vm.max_map_count=16777216'\n\nTo persist the setting between reboots, run:\n\nsudo sh -c 'echo \"vm.max_map_count = 16777216\" >> /etc/sysctl.conf && sysctl -p'"
fi fi
# Anyone who wants to do it manually doesn't need another warning # Anyone who wants to do it manually doesn't need another warning
trap - EXIT trap - EXIT
;; ;;
*) *)
echo "Dialog canceled or unknown option selected: $RESULT" echo "Dialog canceled or unknown option selected: $RESULT"
;; ;;
esac esac
else
# text menu
options="($once $persist $manual)"
PS3="Enter selection number or 'q' to quit: "
select choice in "${options[@]}"
do
case "$REPLY" in
"1")
pkexec sh -c 'sysctl -w vm.max_map_count=16777216'
break
;;
"2")
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
break
;;
"3")
if [ -d "/etc/sysctl.d" ]; then
message 1 "To change the setting (a kernel parameter) until next boot, run:\n\nsudo sh -c 'sysctl -w vm.max_map_count=16777216'\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 && sysctl -p'"
else
message 1 "To change the setting (a kernel parameter) until next boot, run:\n\nsudo sh -c 'sysctl -w vm.max_map_count=16777216'\n\nTo persist the setting between reboots, run:\n\nsudo sh -c 'echo \"vm.max_map_count = 16777216\" >> /etc/sysctl.conf && sysctl -p'"
fi
# Anyone who wants to do it manually doesn't need another warning
trap - EXIT
break
;;
"q")
break
;;
*)
echo -e "\nInvalid selection"
continue
;;
esac
done
fi
fi fi
} }
@ -200,11 +272,11 @@ mem_check() {
if [ "$zenity" -eq 1 ]; then if [ "$zenity" -eq 1 ]; then
check="Check my system settings for optimal performance" check="Check my system settings for optimal performance"
clean="Delete my USER folder and preserve my keybinds" clean="Delete my USER folder and preserve my keybinds"
options="$(main_dialog --height="175" --text="Welcome, fellow penguin, to the Star Citizen Linux Users Group Helper Script!" --list --radiolist --column=" " --column="What would you like to do?" "TRUE" "$check" \ "FALSE" "$clean")" options="$(message 5 "TRUE $check \ FALSE $clean")"
case "$options" in case "$options" in
"$check") "$check")
mem_check set_map_count
;; ;;
"$clean") "$clean")
sanitize sanitize
@ -221,10 +293,10 @@ else
select choice in "${options[@]}" select choice in "${options[@]}"
do do
case $REPLY in case "$REPLY" in
"1") "1")
echo -e "\n" echo -e "\n"
mem_check set_map_count
break break
;; ;;
"2") "2")