From ccee6b10f151a7cd5ff012dc60169f797cbba446 Mon Sep 17 00:00:00 2001 From: aclist Date: Wed, 10 May 2023 13:49:23 +0900 Subject: [PATCH] fix: sudo escalation --- changelog.md | 4 ++++ dzgui.sh | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 0028936..2769bce 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,10 @@ - Custom query API - Store favorites by IP +## [3.2.7] 2023-05-10 +### Changed +- Better sudo escalation within zenity dialogs if vm map count is too small + ## [3.2.6] 2023-05-10 ### Fixed - Don't parse Flatpak symlinks when setting up default Steam path diff --git a/dzgui.sh b/dzgui.sh index 24dcd48..67b53b1 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -1,7 +1,7 @@ #!/bin/bash set -o pipefail -version=3.2.6 +version=3.2.7 aid=221100 game="dayz" @@ -1722,14 +1722,19 @@ setup(){ fi } check_map_count(){ - count=1048576 + local count=1048576 echo "[DZGUI] Checking system map count" - if [[ $(sudo sysctl -q vm.max_map_count | awk -F"= " '{print $2}') -lt $count ]]; then - $steamsafe_zenity --question --width 500 --title="DZGUI" --text "System map count must be $count or higher to run DayZ with Wine.\nIncrease map count and make this change permanent? (will prompt for sudo password)" 2>/dev/null + if [[ ! -f /etc/sysctl.d/dayz.conf ]]; then + $steamsafe_zenity --question --width 500 --title="DZGUI" --cancel-label="Cancel" --ok-label="OK" --text "sudo password required to check system vm map count." 2>/dev/null if [[ $? -eq 0 ]]; then - pass=$($steamsafe_zenity --password) - sudo -S <<< "$pass" sh -c "echo 'vm.max_map_count=1048576' > /etc/sysctl.d/dayz.conf" + local pass=$($steamsafe_zenity --password) + local ct=$(sudo -S <<< "$pass" sh -c "sysctl -q vm.max_map_count | awk -F'= ' '{print \$2}'") + local new_ct + [[ $ct -lt $count ]] && ct=$count + sudo -S <<< "$pass" sh -c "echo 'vm.max_map_count=$ct' > /etc/sysctl.d/dayz.conf" sudo sysctl -p /etc/sysctl.d/dayz.conf + else + exit 1 fi fi } @@ -1827,4 +1832,5 @@ main(){ #TODO: tech debt: cruddy handling for steam forking [[ $? -eq 1 ]] && pkill -f dzgui.sh } +parent=$(cat /proc/$PPID/comm) main