Fixes, formatting

This commit is contained in:
the-sane 2020-08-03 18:15:38 -04:00 committed by GitHub
parent 7002579c3c
commit 94dc48f52c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,37 +39,31 @@ mappings="$user/Controls/Mappings"
############################################################################ ############################################################################
############################################################################ ############################################################################
# Check if Zenity is available
zenity=0
if [ -x "$(command -v zenity)" ]; then
zenity=1
fi
# Display a message to the user. Expects a numerical argument followed by the string to display. # Display a message to the user. Expects a numerical argument followed by the string to display.
message() { message() {
if [ "$zenity" -eq 1 ]; then if [ "$has_zen" -eq 1 ]; then
if [ "$1" -eq 1 ]; then if [ "$1" -eq 1 ]; then
# info # info
margs="--info --no-wrap --text=" margs="--info --no-wrap --text="
elif [ "$1" -eq 2 ]; then elif [ "$1" -eq 2 ]; then
# warning # warning
margs="--warning --no-wrap --text=" margs="--warning --no-wrap --text="
elif [ "$1" -eq 3 ]; then elif [ "$1" -eq 3 ]; then
# question # question
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 --height=\"200\" --column=\" \" --column=\"What would you like to do?\" "
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 Linux Users Group Helper Script!" --column=\" \" --column=\"What would you like to do?\" " 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 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..."
fi fi
# Display the message # Display the message
zenity "$margs$2" --icon-name='lutris' --width="400" --title="Star Citizen LUG Helper Script" zenity "$margs" --icon-name='lutris' --width="400" --title="Star Citizen LUG Helper Script"
else else
# Text based menu. Does not work with message types 4 and 5 (zenity radio lists) # Text based menu. Does not work with message types 4 and 5 (zenity radio lists)
# those need to be handled specially in the code # those need to be handled specially in the code
@ -84,20 +78,20 @@ message() {
exit 0 exit 0
elif [ "$1" -eq 3 ]; then elif [ "$1" -eq 3 ]; then
# question # question
echo -e "\n$2\n" echo -e "$2"
while true; do while true; do
read -p "[y/n]: " yn read -p "[y/n]: " yn
case "$yn" in case "$yn" in
[Yy]*) [Yy]*)
return 0 return 0
;; ;;
[Nn]*) [Nn]*)
return 1 return 1
;; ;;
*) *)
echo "Please type 'y' or 'n'" echo "Please type 'y' or 'n'"
;; ;;
esac esac
done done
else 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" 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"
@ -193,71 +187,73 @@ set_map_count() {
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 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 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,\nthe setting has not been changed on your system.\n\nWould you like to change the setting now?"; then
if [ "$zenity" -eq 1 ]; then if [ "$has_zen" -eq 1 ]; then
# zenity menu # zenity menu
RESULT="$(message 4 "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
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'" 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
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'" 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 else
# text menu # text menu
options="($once $persist $manual)" echo -e "\n"
options=("$once" "$persist" "$manual")
PS3="Enter selection number or 'q' to quit: " PS3="Enter selection number or 'q' to quit: "
select choice in "${options[@]}" select choice in "${options[@]}"
do do
case "$REPLY" in case "$REPLY" in
"1") "1")
pkexec sh -c 'sysctl -w vm.max_map_count=16777216' pkexec sh -c 'sysctl -w vm.max_map_count=16777216'
break break
;; ;;
"2") "2")
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
break break
;; ;;
"3") "3")
if [ -d "/etc/sysctl.d" ]; then clear
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'" if [ -d "/etc/sysctl.d" ]; then
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.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.conf && sysctl -p'" else
fi 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'"
# Anyone who wants to do it manually doesn't need another warning fi
trap - EXIT # Anyone who wants to do it manually doesn't need another warning
break trap - EXIT
;; break
;;
"q") "q")
break break
;; ;;
*) *)
echo -e "\nInvalid selection" echo -e "\nInvalid selection"
continue continue
;; ;;
esac esac
done done
fi fi
@ -268,8 +264,14 @@ set_map_count() {
# MAIN # MAIN
############################################################################ ############################################################################
# Check if Zenity is available
has_zen=0
if [ -x "$(command -v zenity)" ]; then
has_zen=1
fi
# Use Zenity if it is available # Use Zenity if it is available
if [ "$zenity" -eq 1 ]; then if [ "$has_zen" -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="$(message 5 "TRUE $check \ FALSE $clean")" options="$(message 5 "TRUE $check \ FALSE $clean")"
@ -285,7 +287,7 @@ if [ "$zenity" -eq 1 ]; then
;; ;;
esac esac
else else
# Use a text menu if Zenity is not available # 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" echo -e "\nWelcome, fellow penguin, to the Star Citizen Linux Users Group Helper Script!\nWhat would you like to do?\n"
options=("Check my system settings for optimal performance" "Delete my USER folder and preserve my keybinds") options=("Check my system settings for optimal performance" "Delete my USER folder and preserve my keybinds")