Loop main menu until user quits. Beautify dialogs

This commit is contained in:
the-sane 2020-08-14 22:11:31 -04:00 committed by GitHub
parent 8e4a6f00fe
commit 095e18ef53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -52,10 +52,10 @@ message() {
margs=("--question" "--text=") margs=("--question" "--text=")
elif [ "$1" -eq 4 ]; then elif [ "$1" -eq 4 ]; then
# radio list # radio list
margs=("--list" "--radiolist" "--height=200" "--column=" "--column=What would you like to do?") margs=("--list" "--radiolist" "--text=Choose from the following options:" "--hide-header" "--column=" "--column=Option")
elif [ "$1" -eq 5 ]; then elif [ "$1" -eq 5 ]; then
# main menu radio list # main menu radio list
margs=("--list" "--radiolist" "--height=175" "--text=Welcome, fellow penguin, to the Star Citizen LUG Helper Script!" "--column=" "--column=What would you like to do?") margs=("--list" "--radiolist" "--height=240" "--text=<b><big>Welcome, fellow penguin, to the Star Citizen LUG Helper Script!</big>\n\nThis script is designed to help you optimize your system for Star Citizen.</b>\n\nYou may choose from the following options:" "--hide-header" "--column=" "--column=Option")
else else
echo -e "Invalid message format.\n\nThe message function expects a numerical argument followed by the string to display.\n" 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..." read -n 1 -s -p "Press any key..."
@ -285,6 +285,7 @@ sanitize() {
message 1 "Your USER directory has been cleaned up!" message 1 "Your USER directory has been cleaned up!"
} }
# Check if setting vm.max_map_count was successful
check_map_count() { 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
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." 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."
@ -312,13 +313,14 @@ set_map_count() {
once="Change setting until next reboot" once="Change setting until next reboot"
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"
goback="Return to the main menu"
if message 3 "Running Star Citizen requires changing a system setting.\n\nvm.max_map_count must be increased to at least 16777216\nto avoid crashes in areas with lots of geometry.\n\nAs far as this script can detect, the setting\nhas 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\nto avoid crashes in areas with lots of geometry.\n\nAs far as this script can detect, the setting\nhas not been changed on your system.\n\nWould you like to change the setting now?"; then
if [ "$has_zen" -eq 1 ]; then if [ "$has_zen" -eq 1 ]; then
# zenity menu # zenity menu
list=("TRUE" "$once" "FALSE" "$persist" "FALSE" "$manual") options_mapcount=("--height=165" "TRUE" "$once" "FALSE" "$persist" "FALSE" "$manual")
RESULT="$(message 4 "${list[@]}")" choice="$(message 4 "${options_mapcount[@]}")"
case "$RESULT" in case "$choice" in
"$once") "$once")
pkexec sh -c 'sysctl -w vm.max_map_count=16777216' pkexec sh -c 'sysctl -w vm.max_map_count=16777216'
;; ;;
@ -343,18 +345,19 @@ set_map_count() {
esac esac
else else
# text menu # text menu
echo -e "\n" clear
options=("$once" "$persist" "$manual") echo -e "\nThis script can change vm.max_map_count for you.\nChoose from the following options:\n"
PS3="Enter selection number or 'q' to quit: " options_mapcount=("$once" "$persist" "$manual" "$goback")
PS3="Enter selection number: "
select choice in "${options[@]}" select choice in "${options_mapcount[@]}"
do do
case "$REPLY" in case "$choice" in
"1") "$once")
pkexec sh -c 'sysctl -w vm.max_map_count=16777216' pkexec sh -c 'sysctl -w vm.max_map_count=16777216'
break break
;; ;;
"2") "$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
@ -362,7 +365,7 @@ set_map_count() {
fi fi
break break
;; ;;
"3") "$manual")
clear clear
if [ -d "/etc/sysctl.d" ]; then 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 &amp;&amp; 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 &amp;&amp; sysctl -p'"
@ -373,7 +376,7 @@ set_map_count() {
trap - EXIT trap - EXIT
break break
;; ;;
"q") "$goback")
break break
;; ;;
*) *)
@ -386,10 +389,68 @@ set_map_count() {
fi fi
} }
# Display the main menu
main_menu() {
# Set the menu options
check="Check vm.max_map_count for optimal performance"
clean="Delete my USER folder and preserve my keybinds"
quit="Quit"
# Use Zenity if it is available
if [ "$has_zen" -eq 1 ]; then
options_main=("TRUE" "$check" "FALSE" "$clean" "FALSE" "$quit")
choice="$(message 5 "${options_main[@]}")"
case "$choice" in
"$check")
set_map_count
;;
"$clean")
sanitize
;;
"$quit")
exit 0
;;
*)
exit 0
;;
esac
else
# Use a text menu if Zenity is not available
clear
echo -e "\nWelcome, fellow penguin, to the Star Citizen Linux Users Group Helper Script!\n\nThis script is designed to help you optimize your system for Star Citizen.\nYou may choose from the following options:\n"
options_main=("$check" "$clean" "$quit")
PS3="Enter selection number: "
select choice in "${options_main[@]}"
do
case "$choice" in
"$check")
echo -e "\n"
set_map_count
break
;;
"$clean")
echo -e "\n"
sanitize
break
;;
"$quit")
exit 0
;;
*)
echo -e "\nInvalid selection"
continue
;;
esac
done
fi
}
############################################################################ ############################################################################
# MAIN # MAIN
############################################################################ ############################################################################
clear
# Check if Zenity is available # Check if Zenity is available
has_zen=0 has_zen=0
@ -397,50 +458,7 @@ if [ -x "$(command -v zenity)" ]; then
has_zen=1 has_zen=1
fi fi
# Use Zenity if it is available # Loop the main menu until the user selects quit
if [ "$has_zen" -eq 1 ]; then while true; do
check="Check vm.max_map_count for optimal performance" main_menu
clean="Delete my USER folder and preserve my keybinds" done
list=("TRUE" "$check" "FALSE" "$clean")
options="$(message 5 "${list[@]}")"
case "$options" in
"$check")
set_map_count
;;
"$clean")
sanitize
;;
*)
;;
esac
else
# Use a text menu if Zenity is not available
echo -e "\nWelcome, fellow penguin, to the Star Citizen Linux Users Group Helper Script!\nWhat would you like to do?\n"
options=("Check vm.max_map_count for optimal performance" "Delete my USER folder and preserve my keybinds")
PS3="Enter selection number or 'q' to quit: "
select choice in "${options[@]}"
do
case "$REPLY" in
"1")
echo -e "\n"
set_map_count
break
;;
"2")
echo -e "\n"
sanitize
break
;;
"q")
break
;;
*)
echo -e "\nInvalid selection"
continue
;;
esac
done
fi