1
0
Fork 0
mirror of https://github.com/aclist/dztui.git synced 2024-12-29 13:52:03 +01:00

chore: backports from stable

This commit is contained in:
aclist 2023-07-25 10:10:07 +09:00
parent 24b07a9bf9
commit 3f2397ad74

332
dzgui.sh
View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -o pipefail
version=3.4.0-rc.8
version=3.4.0-rc.9
aid=221100
game="dayz"
@ -13,6 +13,7 @@ config_file="${config_path}dztuirc"
hist_file="${config_path}/history"
tmp=/tmp/dzgui.tmp
fifo=/tmp/table.tmp
debug_log="$PWD/DZGUI_DEBUG.log"
separator="%%"
check_config_msg="Check config values and restart."
issues_url="https://github.com/aclist/dztui/issues"
@ -52,13 +53,16 @@ update_last_seen(){
source $config_file
}
check_news(){
logger INFO "${FUNCNAME[0]}"
echo "# Checking news"
[[ $branch == "stable" ]] && news_url="$stable_url/news"
[[ $branch == "testing" ]] && news_url="$testing_url/news"
result=$(curl -Ls "$news_url")
sum=$(echo -n "$result" | md5sum | awk '{print $1}')
logger INFO "News: $result"
}
print_news(){
logger INFO "${FUNCNAME[0]}"
if [[ $sum == $seen_news || -z $result ]]; then
hchar=""
news=""
@ -127,12 +131,14 @@ info(){
$steamsafe_zenity --info --title="DZGUI" --text="$1" --width=500 2>/dev/null
}
set_api_params(){
logger INFO "${FUNCNAME[0]}"
response=$(curl -s "$api" -H "Authorization: Bearer "$api_key"" -G -d "sort=-players" \
-d "filter[game]=$game" -d "filter[ids][whitelist]=$list_of_ids")
list_response=$response
first_entry=1
}
query_api(){
logger INFO ${FUNCNAME[0]}
echo "# Querying API"
#TODO: prevent drawing list if null values returned without API error
if [[ $one_shot_launch -eq 1 ]]; then
@ -232,17 +238,17 @@ freedesktop_dirs(){
fi
}
find_library_folder(){
echo "ENTERED: ${FUNCNAME[0]}" >> /tmp/dzdebug.log
echo "RECEIVED ARG: $1" >> /tmp/dzdebug.log
logger INFO "${FUNCNAME[0]}"
logger INFO "User picked directory: '$1'"
steam_path="$(python3 "$helpers_path/vdf2json.py" -i "$1/steamapps/libraryfolders.vdf" | jq -r '.libraryfolders[]|select(.apps|has("221100")).path')"
echo "STEAM PATH RESOLVED TO: $steam_path" >> /tmp/dzdebug.log
logger INFO "Steam path resolved to: $steam_path"
}
file_picker(){
echo "${FUNCNAME[0]}" >> /tmp/dzdebug.log
logger INFO "${FUNCNAME[0]}"
local path=$($steamsafe_zenity --file-selection --directory 2>/dev/null)
echo "FILE PICKER PATH RESOLVED TO: $path" >> /tmp/dzdebug.log
logger INFO "File picker path resolve to: $path"
if [[ -z "$path" ]]; then
echo "PATH WAS EMPTY" >> /tmp/dzdebug.log
logger INFO "Path was empty"
return
else
default_steam_path="$path"
@ -250,7 +256,7 @@ file_picker(){
fi
}
create_config(){
debug "ENTERED ${FUNCNAME[0]}"
logger INFO "${FUNCNAME[0]}"
check_pyver
write_to_config(){
mkdir -p $config_path
@ -279,15 +285,15 @@ create_config(){
warn "Invalid BM API key"
else
while true; do
debug "STEAMSAFEZENITY: $steamsafe_zenity"
logger INFO "steamsafe_zenity is $steamsafe_zenity"
[[ -n $steam_path ]] && { write_to_config; return; }
find_default_path
find_library_folder "$default_steam_path"
if [[ -z $steam_path ]]; then
debug "STEAM PATH WAS EMPTY"
logger WARN "Steam path was empty"
zenity --question --text="DayZ not found or not installed at the chosen path." --ok-label="Choose path manually" --cancel-label="Exit"
if [[ $? -eq 0 ]]; then
debug "USER SELECTED FILE PICKER"
logger INFO "User selected file picker"
file_picker
else
exit
@ -309,25 +315,29 @@ varcheck(){
fi
}
run_depcheck(){
logger INFO "${FUNCNAME[0]}"
if [[ -n $(depcheck) ]]; then
echo "100"
logger ERROR "Missing dependencies, quitting"
$steamsafe_zenity --warning --ok-label="Exit" --title="DZGUI" --text="$(depcheck)"
exit
fi
}
debug(){
echo "$*" >> /tmp/dzdebug.log
logger(){
local date="$(date "+%F %T")"
local tag="$1"
local string="$2"
printf "[%s] [%s] %s\n" "$date" "$tag" "$string" >> "$debug_log"
}
check_pyver(){
debug "ENTERED ${FUNCNAME[0]}"
pyver=$(python3 --version | awk '{print $2}')
debug "PYVER is $pyver"
if [[ -z $pyver ]] || [[ ${pyver:0:1} -lt 3 ]]; then
warn "Requires python >=3.0" &&
exit
fi
}
run_varcheck(){
logger INFO "${FUNCNAME[0]}"
source $config_file
workshop_dir="$steam_path/steamapps/workshop/content/$aid"
game_dir="$steam_path/steamapps/common/DayZ"
@ -335,6 +345,7 @@ run_varcheck(){
$steamsafe_zenity --question --cancel-label="Exit" --text="Malformed config file. This is probably user error.\nStart first-time setup process again?" --width=500 2>/dev/null
code=$?
if [[ $code -eq 1 ]]; then
logger ERROR "Malformed config vars"
exit
else
create_config
@ -342,19 +353,17 @@ run_varcheck(){
fi
}
config(){
debug "ENTERED ${FUNCNAME[0]}"
logger INFO "${FUNCNAME[0]}"
if [[ ! -f $config_file ]]; then
debug "CONFIG FILE MISSING"
debug "STEAMSAFEZENITY is $steamsafe_zenity"
$steamsafe_zenity --width 500 --info --text="Config file not found. Click OK to proceed to first-time setup." 2>/dev/null
logger WARN "Config file missing"
logger INFO "steamsafe_zenity is $steamsafe_zenity"
$steamsafe_zenity --width=500 --info --text="Config file not found. Click OK to proceed to first-time setup." 2>/dev/null
code=$?
debug "RETURN CODE WAS $code"
logger INFO "Return code $code"
#TODO: prevent progress if user hits ESC
if [[ $code -eq 1 ]]; then
debug "RECEIVED EXIT CODE 1"
exit
else
debug "CREATING CONFIG"
create_config
fi
else
@ -435,7 +444,6 @@ manual_mod_install(){
compare
if [[ -z $diff ]]; then
passed_mod_check > >($steamsafe_zenity --pulsate --progress --auto-close --width=500 2>/dev/null)
echo "${FUNCNAME[0]}" >> $config_path/dzdebug
launch
else
return 1
@ -446,6 +454,7 @@ encode(){
echo "$1" | md5sum | cut -c -8
}
stale_symlinks(){
logger INFO "${FUNCNAME[0]}"
for l in $(find "$game_dir" -xtype l); do
unlink $l
done
@ -465,31 +474,34 @@ legacy_symlinks(){
done
}
symlinks(){
readarray -t wdirs < <(find "$workshop_dir"/*/meta.cpp)
for (( i = 0; i < ${#wdirs[@]}; i++ )); do
echo "# Processing symlink $i of ${#wdirs[@]}"
id=$(awk -F"= " '/publishedid/ {print $2}' "${wdirs[$i]}" | awk -F\; '{print $1}')
mod=$(awk -F\" '/name/ {print $2}' "${wdirs[$i]}" | sed -E 's/[^[:alpha:]0-9]+/_/g; s/^_|_$//g')
for d in "$workshop_dir"/*; do
id=$(awk -F"= " '/publishedid/ {print $2}' "$d"/meta.cpp | awk -F\; '{print $1}')
encoded_id=$(encode "$id")
mod=$(awk -F\" '/name/ {print $2}' "$d"/meta.cpp | sed -E 's/[^[:alpha:]0-9]+/_/g; s/^_|_$//g')
link="@$encoded_id"
if [[ -h "$game_dir/$link" ]]; then
:
else
ln -fs "${wdirs[$i]}" "$game_dir/$link"
printf "[DZGUI] Creating symlink for $mod\n"
ln -fs "$d" "$game_dir/$link"
fi
done
}
passed_mod_check(){
echo "[DZGUI] Passed mod check"
echo "# Preparing symlinks"
legacy_symlinks
symlinks
echo "100"
}
auto_mod_install(){
[[ -z $(is_steam_running) ]] && { $steamsafe_zenity --info --text "Steam must be running to use this feature."; return; }
#[[ -z $(is_steam_running) ]] && { $steamsafe_zenity --info --text "Steam must be running to use this feature."; return; }
popup 300
rc=$?
if [[ $rc -eq 0 ]]; then
calc_mod_sizes
local total_size=$(numfmt --to=iec $totalmodsize)
#calc_mod_sizes
#local total_size=$(numfmt --to=iec $totalmodsize)
log="$default_steam_path/logs/content_log.txt"
[[ -f "/tmp/dz.status" ]] && rm "/tmp/dz.status"
touch "/tmp/dz.status"
@ -584,7 +596,7 @@ update_history(){
echo -e "${old}${ip}" > "$hist_file"
}
is_steam_running(){
wmctrl -ilx | awk 'tolower($3) == "steam.steam"'
xdotool search --onlyvisible --name "Steam"
}
connect(){
#TODO: sanitize/validate input
@ -616,7 +628,6 @@ connect(){
esac
else
passed_mod_check > >($steamsafe_zenity --pulsate --progress --auto-close --width=500 2>/dev/null)
echo "${FUNCNAME[0]}" >> $config_path/dzdebug
update_history
launch
fi
@ -708,7 +719,7 @@ history_table(){
ip_table(){
while true; do
sel=$(prepare_ip_list "$meta_file" | $steamsafe_zenity --width 1200 --height 800 --text="Multiple maps found at this server. Select map from the list below" --title="DZGUI" --list --column=Name --column=IP --column=Players --column=Gametime --column=Qport --print-column=2 --separator=%% 2>/dev/null)
sel=$(prepare_ip_list "$meta_file" | $steamsafe_zenity --width 1200 --height 800 --text="One or more maps found at this server. Select map from the list below" --title="DZGUI" --list --column=Name --column=IP --column=Players --column=Gametime --column=Qport --print-column=2 --separator=%% 2>/dev/null)
if [[ $? -eq 1 ]]; then
return_from_table=1
return
@ -867,12 +878,12 @@ launch(){
source_dir=$(dirname "$source_script")
echo "$launch_options" > "$source_dir"/options.log
echo "[DZGUI] Wrote launch options to $source_dir/options.log"
$steamsafe_zenity --info --width 500 --title="DZGUI" --text="Wrote launch options to \n$source_dir/options.log" 2>/dev/null
$steamsafe_zenity --info --width=500 --title="DZGUI" --text="Wrote launch options to \n$source_dir/options.log" 2>/dev/null
fi
else
echo "[DZGUI] All OK. Launching DayZ"
$steamsafe_zenity --width 500 --title="DZGUI" --info --text="Launch conditions satisfied.\nDayZ will now launch after clicking [OK]." 2>/dev/null
$steamsafe_zenity --width=500 --title="DZGUI" --info --text="Launch conditions satisfied.\nDayZ will now launch after clicking [OK]." 2>/dev/null
$steam_cmd -applaunch $aid -connect=$ip -nolauncher -nosplash -skipintro -name=$name \"-mod=$mods\"
exit
fi
@ -905,11 +916,13 @@ hof(){
browser "${help_url}#_hall_of_fame"
}
set_mode(){
logger INFO "${FUNCNAME[0]}"
if [[ $debug -eq 1 ]]; then
mode=debug
else
mode=normal
fi
logger INFO "Mode is $mode"
}
delete_by_id(){
new_whitelist="whitelist=\"$(echo "$whitelist" | sed "s/,$server_id$//;s/^$server_id,//;s/,$server_id,/,/;s/^$server_id$//")\""
@ -1004,6 +1017,8 @@ connect_to_fav(){
}
set_header(){
logger INFO "${FUNCNAME[0]}"
logger INFO "Header mode is $1"
print_news
[[ $auto_install -eq 2 ]] && install_mode="auto"
[[ $auto_install -eq 1 ]] && install_mode="headless"
@ -1032,38 +1047,6 @@ toggle_branch(){
printf "[DZGUI] Toggled branch to '$branch'\n"
source $config_file
}
is_beta(){
local dir="$default_steam_path/package"
if [[ -f $dir/beta ]]; then
echo 0
else
echo 1
fi
}
focus_beta_client(){
wid(){
wmctrl -ilx | awk 'tolower($3) == "steam.steam"' | grep 'Steam$' | awk '{print $1}'
}
until [[ -n $(wid) ]]; do
:
done
wmctrl -ia $(wid)
sleep 0.1s
wid=$(xdotool getactivewindow)
local geo=$(xdotool getwindowgeometry $wid)
local pos=$(<<< "$geo" awk 'NR==2 {print $2}' | sed 's/,/ /')
local dim=$(<<< "$geo" awk 'NR==3 {print $2}' | sed 's/x/ /')
local pos1=$(<<< "$pos" awk '{print $1}')
local pos2=$(<<< "$pos" awk '{print $2}')
local dim1=$(<<< "$dim" awk '{print $1}')
local dim2=$(<<< "$dim" awk '{print $2}')
local dim1=$(((dim1/2)+pos1))
local dim2=$(((dim2/2)+pos2))
xdotool mousemove $dim1 $dim2
xdotool click 1
sleep 0.5s
xdotool key Tab
}
generate_log(){
cat <<-DOC
Linux: $(uname -mrs)
@ -1078,33 +1061,54 @@ generate_log(){
$(list_mods)
DOC
}
focus_beta_client(){
steam steam://open/console 2>/dev/null 1>&2 &&
sleep 1s
wid(){
#wmctrl -ilx | awk 'tolower($3) == "steam.steam"' | grep 'Steam$' | awk '{print $1}'
wmctrl -ilx | awk '$3 == "steamwebhelper.steam" {print $1}'
}
until [[ -n $(wid) ]]; do
:
done
wmctrl -ia $(wid)
sleep 0.1s
wid=$(xdotool getactivewindow)
echo wid is $wid
local geo=$(xdotool getwindowgeometry $wid)
local pos=$(<<< "$geo" awk 'NR==2 {print $2}' | sed 's/,/ /')
local dim=$(<<< "$geo" awk 'NR==3 {print $2}' | sed 's/x/ /')
local pos1=$(<<< "$pos" awk '{print $1}')
local pos2=$(<<< "$pos" awk '{print $2}')
local dim1=$(<<< "$dim" awk '{print $1}')
local dim2=$(<<< "$dim" awk '{print $2}')
local dim1=$(((dim1/2)+pos1))
local dim2=$(((dim2/2)+pos2))
echo moving mouse
xdotool mousemove $dim1 $dim2
xdotool click 1
sleep 0.5s
xdotool key Tab
}
console_dl(){
readarray -t modids <<< "$@"
$steam_cmd steam://open/console 2>/dev/null 1>&2 &&
sleep 1s
focus_beta_client
# steam steam://open/console 2>/dev/null 1>&2 &&
# sleep 1s
#https://github.com/jordansissel/xdotool/issues/67
#https://dwm.suckless.org/patches/current_desktop/
# local wid=$(xdotool search --onlyvisible --name Steam)
#xdotool windowactivate $wid
sleep 1.5s
for i in "${modids[@]}"; do
if [[ $(is_beta) -eq 0 ]]; then
if [[ ${#modids[@]} -eq 1 ]]; then
focus_beta_client
fi
else
wid=0
until [[ $(xdotool getwindowname $wid 2>/dev/null) == "Steam" ]]; do
wid=$(xdotool getactivewindow)
done
xdotool windowfocus $wid
xdotool key Tab
fi
xdotool type --delay 0 "workshop_download_item $aid $i"
sleep 0.5s
xdotool key Return
sleep 0.5s
xdotool type --delay 0 "workshop_download_item $aid $i"
sleep 0.5s
xdotool key Return
sleep 0.5s
done
}
find_default_path(){
logger INFO "${FUNCNAME[0]}"
discover(){
echo "# Searching for Steam"
default_steam_path=$(find / -type d \( -path "/proc" -o -path "*/timeshift" -o -path \
@ -1223,9 +1227,8 @@ options_menu(){
"Generate debug log")
source_script=$(realpath "$0")
source_dir=$(dirname "$source_script")
generate_log > "$source_dir/DZGUI.log"
printf "[DZGUI] Wrote log file to %s/log\n" "$source_dir"
$steamsafe_zenity --info --width 500 --title="DZGUI" --text="Wrote log file to \n$source_dir/log" 2>/dev/null
$steamsafe_zenity --info --width=500 --title="DZGUI" --text="Wrote log file to \n$source_dir/log" 2>/dev/null
;;
Toggle[[:space:]]auto*) toggle_console_dl ;;
"Force update local mods")
@ -1244,7 +1247,7 @@ query_and_connect(){
parse_json
create_array
}
q | $steamsafe_zenity --width 500 --progress --pulsate --title="DZGUI" --auto-close 2>/dev/null
q | $steamsafe_zenity --width=500 --progress --pulsate --title="DZGUI" --auto-close 2>/dev/null
rc=$?
if [[ $rc -eq 1 ]]; then
:
@ -1449,7 +1452,6 @@ munge_servers(){
fi
}
debug_servers(){
[[ -f $debug_log ]] && rm $debug_log
if [[ -n $steam_api ]]; then
exists=true
else
@ -1461,19 +1463,6 @@ debug_servers(){
debug_res=$(curl -Ls "https://api.steampowered.com/IGameServersService/GetServerList/v1/?filter=\appid\221100&limit=10&key=$steam_api")
debug_len=$(echo "$debug_res" | jq '[.response.servers[]]|length')
[[ -z $debug_len ]] && debug_len=0
cat <<-DOC > $debug_log
======START DEBUG======
Key exists: $exists
First char: $first_char
Last char: $last_char
Key length: $key_len
======Short query======
Expected: 10
Found: $debug_len
Response follows---->
$debug_res
======END DEBUG=======
DOC
}
server_browser(){
check_steam_api
@ -1497,7 +1486,6 @@ server_browser(){
total_servers=$(echo "$response" | jq 'length' | numfmt --grouping)
players_online=$(curl -Ls "https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?appid=$aid" \
| jq '.response.player_count' | numfmt --grouping)
debug_log="$HOME/.local/share/dzgui/DEBUG.log"
debug_servers
local sel=$(munge_servers)
if [[ -z $sel ]]; then
@ -1524,42 +1512,46 @@ mods_disk_size(){
printf "Location: %s/steamapps/workshop/content/221100" "$steam_path"
}
main_menu(){
logger INFO "${FUNCNAME[0]}"
logger INFO "Setting mode"
set_mode
while true; do
set_header ${FUNCNAME[0]}
rc=$?
if [[ $rc -eq 0 ]]; then
case "$sel" in
"") warn "No item was selected." ;;
" Server browser") server_browser ;;
" My servers") query_and_connect ;;
" Quick connect to favorite server") connect_to_fav ;;
" Connect by IP") connect_by_ip ;;
" Recent servers (last 10)") history_table ;;
" Add server by ID") add_by_id ;;
" Add favorite server") add_by_fav ;;
" Change favorite server") add_by_fav ;;
" Delete server") delete=1; query_and_connect ;;
" List installed mods")
list_mods | sed 's/\t/\n/g' | $steamsafe_zenity --list --column="Mod" --column="Symlink" --column="Dir" \
--title="DZGUI" $sd_res --text="$(mods_disk_size)" \
--print-column="" 2>/dev/null
;;
" View changelog") changelog | $steamsafe_zenity --text-info $sd_res --title="DZGUI" 2>/dev/null ;;
" Advanced options")
options_menu
main_menu
return
rc=$?
logger INFO "set_header rc is $rc"
if [[ $rc -eq 0 ]]; then
case "$sel" in
"") warn "No item was selected." ;;
" Server browser") server_browser ;;
" My servers") query_and_connect ;;
" Quick connect to favorite server") connect_to_fav ;;
" Connect by IP") connect_by_ip ;;
" Recent servers (last 10)") history_table ;;
" Add server by ID") add_by_id ;;
" Add favorite server") add_by_fav ;;
" Change favorite server") add_by_fav ;;
" Delete server") delete=1; query_and_connect ;;
" List installed mods")
list_mods | sed 's/\t/\n/g' | $steamsafe_zenity --list --column="Mod" --column="Symlink" --column="Dir" \
--title="DZGUI" $sd_res --text="$(mods_disk_size)" \
--print-column="" 2>/dev/null
;;
" Help file ⧉") help_file ;;
" Report bug ⧉") report_bug ;;
" Forum ⧉") forum ;;
" NEW: Sponsor ⧉") sponsor ;;
" NEW: Hall of fame ⧉") hof ;;
esac
else
return
fi
" View changelog") changelog | $steamsafe_zenity --text-info $sd_res --title="DZGUI" 2>/dev/null ;;
" Advanced options")
options_menu
main_menu
return
;;
" Help file ⧉") help_file ;;
" Report bug ⧉") report_bug ;;
" Forum ⧉") forum ;;
" NEW: Sponsor ⧉") sponsor ;;
" NEW: Hall of fame ⧉") hof ;;
esac
else
logger INFO "Returning from main menu"
return
fi
done
}
page_through(){
@ -1626,6 +1618,7 @@ create_array(){
for i in "${rows[@]}"; do echo -e "$i"; done > $tmp
}
set_fav(){
logger INFO "${FUNCNAME[0]}"
echo "[DZGUI] Querying favorite server"
query_api
fav_label=$(curl -s "$api" -H "Authorization: Bearer "$api_key"" -G -d "filter[game]=$game" -d "filter[ids][whitelist]=$fav" \
@ -1635,8 +1628,10 @@ set_fav(){
else
fav_label="'$fav_label'"
fi
logger INFO "Fav label is $fav_label"
}
check_unmerged(){
logger INFO "${FUNCNAME[0]}"
if [[ -f ${config_path}.unmerged ]]; then
printf "[DZGUI] Found new config format, merging changes\n"
merge_config
@ -1649,17 +1644,17 @@ merge_config(){
[[ -z $staging_dir ]] && staging_dir="/tmp"
write_config > $config_file
printf "[DZGUI] Wrote new config file to %sdztuirc\n" $config_path
$steamsafe_zenity --info --width 500 --title="DZGUI" --text="Wrote new config format to \n${config_path}dztuirc\nIf errors occur, you can restore the file:\n${config_path}dztuirc.old" 2>/dev/null
$steamsafe_zenity --info --width=500 --title="DZGUI" --text="Wrote new config format to \n${config_path}dztuirc\nIf errors occur, you can restore the file:\n${config_path}dztuirc.old" 2>/dev/null
}
download_new_version(){
echo "# Downloading version $upstream"
if [[ $is_steam_deck -eq 1 ]]; then
freedesktop_dirs
fi
source_script=$(realpath "$0")
source_dir=$(dirname "$source_script")
mv $source_script $source_script.old
echo "# Downloading version $upstream"
curl -Ls "$version_url" > $source_script
rc=$?
if [[ $rc -eq 0 ]]; then
@ -1667,7 +1662,7 @@ download_new_version(){
chmod +x $source_script
touch ${config_path}.unmerged
echo "100"
$steamsafe_zenity --question --width 500 --title="DZGUI" --text "DZGUI $upstream successfully downloaded.\nTo view the changelog, select Changelog.\nTo use the new version, select Exit and restart." --ok-label="Changelog" --cancel-label="Exit" 2>/dev/null
$steamsafe_zenity --question --width=500 --title="DZGUI" --text "DZGUI $upstream successfully downloaded.\nTo view the changelog, select Changelog.\nTo use the new version, select Exit and restart." --ok-label="Changelog" --cancel-label="Exit" 2>/dev/null
code=$?
if [[ $code -eq 0 ]]; then
changelog | $steamsafe_zenity --text-info $sd_res --title="DZGUI" 2>/dev/null
@ -1684,15 +1679,18 @@ download_new_version(){
}
check_branch(){
logger INFO "${FUNCNAME[0]}"
if [[ $branch == "stable" ]]; then
version_url="$stable_url/dzgui.sh"
elif [[ $branch == "testing" ]]; then
version_url="$testing_url/dzgui.sh"
fi
logger INFO "Branch is $branch"
upstream=$(curl -Ls "$version_url" | awk -F= '/^version=/ {print $2}')
logger INFO "Upstream version is $version"
}
enforce_dl(){
download_new_version > >($steamsafe_zenity --progress --title="DZGUI" --pulsate --auto-close --no-cancel --width=500)
download_new_version > >($steamsafe_zenity --progress --pulsate --auto-close --no-cancel --width=500)
}
prompt_dl(){
$steamsafe_zenity --question --title="DZGUI" --text "Version conflict.\n\nYour branch:\t\t\t$branch\nYour version:\t\t\t$version\nUpstream version:\t\t$upstream\n\nVersion updates introduce important bug fixes and are encouraged.\n\nAttempt to download latest version?" --width=500 --ok-label="Yes" --cancel-label="No" 2>/dev/null
@ -1701,19 +1699,22 @@ prompt_dl(){
return
else
echo "100"
download_new_version > >($steamsafe_zenity --title="DZGUI" --progress --pulsate --auto-close --no-cancel --width=500)
download_new_version > >($steamsafe_zenity --progress --pulsate --auto-close --no-cancel --width=500)
fi
}
check_version(){
logger INFO "${FUNCNAME[0]}"
[[ -f $config_file ]] && source $config_file
[[ -z $branch ]] && branch="stable"
check_branch
[[ ! -f "$freedesktop_path/dzgui.desktop" ]] && freedesktop_dirs
if [[ $version == $upstream ]]; then
logger INFO "Local version is same as upstream"
check_unmerged
else
# echo "100"
echo "[DZGUI] Upstream ($upstream) != local ($version)"
logger INFO "Local and remote version mismatch"
if [[ $enforce_dl -eq 1 ]]; then
enforce_dl
else
@ -1722,12 +1723,15 @@ check_version(){
fi
}
check_architecture(){
logger INFO "${FUNCNAME[0]}"
cpu=$(cat /proc/cpuinfo | grep "AMD Custom APU 0405")
if [[ -n "$cpu" ]]; then
is_steam_deck=1
logger INFO "Setting architecture to 'Steam Deck'"
echo "[DZGUI] Setting architecture to 'Steam Deck'"
else
is_steam_deck=0
logger INFO "Setting architecture to 'desktop'"
echo "[DZGUI] Setting architecture to 'desktop'"
fi
}
@ -1769,27 +1773,37 @@ toggle_debug(){
}
setup(){
logger INFO "${FUNCNAME[0]}"
if [[ -n $fav ]]; then
set_fav
items[8]=" Change favorite server"
fi
}
check_map_count(){
logger INFO "${FUNCNAME[0]}"
[[ $is_steam_deck -eq 1 ]] && return
local count=1048576
logger INFO "Checking system map count"
echo "[DZGUI] Checking system map count"
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
$steamsafe_zenity --question --width=500 --title="DZGUI" --cancel-label="Cancel" --ok-label="OK" --text "sudo password required to check system vm map count."
local rc=$?
logger INFO "Return code is $rc"
if [[ $rc -eq 0 ]]; then
local pass
logger INFO "Prompting user for sudo escalation"
pass=$($steamsafe_zenity --password)
[[ $? -eq 1 ]] && exit 1
local rc
logger INFO "Return code is $rc"
[[ $rc -eq 1 ]] && exit 1
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
logger INFO "Updating map 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
logger INFO "Zenity dialog failed or user exit"
exit 1
fi
fi
@ -1837,6 +1851,7 @@ lock(){
fi
}
fetch_helpers(){
logger INFO "${FUNCNAME[0]}"
mkdir -p "$helpers_path"
[[ ! -f "$helpers_path/vdf2json.py" ]] && curl -Ls "$vdf2json_url" > "$helpers_path/vdf2json.py"
}
@ -1849,11 +1864,13 @@ update_steam_cmd(){
awk -v "var=$new_cmd" -v "nr=$nr" 'NR==nr {$0=var}{print}' ${config_path}dztuirc.old > ${config_path}dztuirc
}
steam_deps(){
logger INFO "${FUNCNAME[0]}"
local flatpak steam
[[ $(command -v flatpak) ]] && flatpak=$(flatpak list | grep valvesoftware.Steam)
steam=$(command -v steam)
if [[ -z "$steam" ]] && [[ -z "$flatpak" ]]; then
warn "Requires Steam or Flatpak Steam"
logger ERROR "Steam was missing"
exit
elif [[ -n "$steam" ]] && [[ -n "$flatpak" ]]; then
toggle_steam=1
@ -1865,6 +1882,7 @@ steam_deps(){
else
steam_cmd="flatpak run com.valvesoftware.Steam"
fi
logger INFO "steam_cmd set to $steam_cmd"
}
initial_setup(){
echo "# Initial setup"
@ -1883,12 +1901,34 @@ initial_setup(){
check_news
echo "100"
}
test_zenity_version(){
local current="$1"
local cutoff="3.91.0"
if [[ "$(printf '%s\n' "$cutoff" "$current" | sort -V | head -n1)" == "$cutoff" ]]; then
logger INFO "zenity version greater than or equal to $cutoff"
echo greater
else
logger INFO "zenity version lesser than $cutoff"
echo lesser
fi
}
main(){
lock
initial_setup > >($steamsafe_zenity --pulsate --progress --auto-close --title="DZGUI" --no-cancel --width=500 2>/dev/null)
local zenv=$(zenity --version 2>/dev/null)
[[ -z $zenv ]] && { logger "Missing zenity"; exit; }
local res=$(test_zenity_version $zenv)
case $res in
"greater")
initial_setup
;;
"lesser")
initial_setup > >($steamsafe_zenity --pulsate --progress --auto-close --title="DZGUI" --no-cancel --width=500 2>/dev/null)
;;
esac
main_menu
#TODO: tech debt: cruddy handling for steam forking
[[ $? -eq 1 ]] && pkill -f dzgui.sh
}
parent=$(cat /proc/$PPID/comm)
[[ -f "$debug_log" ]] && rm "$debug_log"
main