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

Bump version to 2.4.0-rc.1

This commit is contained in:
aclist 2022-07-24 22:20:06 +09:00 committed by GitHub
parent 56989976d4
commit 9d6f2f15f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

243
dzgui.sh
View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
set -o pipefail set -o pipefail
version=2.3.0 version=2.4.0-rc.1
aid=221100 aid=221100
game="dayz" game="dayz"
workshop="steam://url/CommunityFilePage/" workshop="steam://url/CommunityFilePage/"
@ -11,23 +11,47 @@ config_path="$HOME/.config/dztui/"
config_file="${config_path}dztuirc" config_file="${config_path}dztuirc"
tmp=/tmp/dztui.tmp tmp=/tmp/dztui.tmp
separator="%%" separator="%%"
git_url="https://github.com/aclist/dztui/issues/new/choose" git_url="https://github.com/aclist/dztui/issues"
stable_url="https://raw.githubusercontent.com/aclist/dztui/dzgui/dzgui.sh" stable_url="https://raw.githubusercontent.com/aclist/dztui/dzgui/dzgui.sh"
testing_url="https://raw.githubusercontent.com/aclist/dztui/testing/dzgui.sh" testing_url="https://raw.githubusercontent.com/aclist/dztui/testing/dzgui.sh"
help_url="https://aclist.github.io/dzgui/dzgui" help_url="https://aclist.github.io/dzgui/dzgui"
check_config_msg="Check config values and restart." check_config_msg="Check config values and restart."
news_url="https://raw.githubusercontent.com/aclist/dztui/dzgui/news"
update_last_seen(){
mv $config_file ${config_path}dztuirc.old
nr=$(awk '/seen_news=/ {print NR}' ${config_path}dztuirc.old)
seen_news="seen_news=\"$sum\""
awk -v "var=$seen_news" -v "nr=$nr" 'NR==nr {$0=var}{print}' ${config_path}dztuirc.old > $config_file
printf "[DZGUI] Updated last seen news item to '$sum'\n"
source $config_file
}
check_news(){
result=$(curl -Ls "$news_url")
sum=$(echo -n "$result" | md5sum | awk '{print $1}')
}
print_news(){
check_news
if [[ $sum == $seen_news || -z $result ]]; then
hchar=""
news=""
else
hchar="─"
news="$result\n$(awk -v var="$hchar" 'BEGIN{for(c=0;c<90;c++) printf var;}')\n"
update_last_seen
fi
}
#TODO: prevent connecting to offline servers #TODO: prevent connecting to offline servers
#TODO: concat large mod links
#TODO: check map count and warn
#sysctl -q vm.max_map_count
#prompt password
#TODO: abstract zenity title params #TODO: abstract zenity title params
declare -A deps declare -A deps
deps=([awk]="5.1.1" [curl]="7.80.0" [jq]="1.6" [tr]="9.0" [zenity]="3.42.1") deps=([awk]="5.1.1" [curl]="7.80.0" [jq]="1.6" [tr]="9.0" [zenity]="3.42.1" [steam]="1.0.0")
changelog(){ changelog(){
if [[ $branch == "stable" ]]; then
md="https://raw.githubusercontent.com/aclist/dztui/dzgui/changelog.md" md="https://raw.githubusercontent.com/aclist/dztui/dzgui/changelog.md"
else
md="https://raw.githubusercontent.com/aclist/dztui/testing/changelog.md"
fi
prefix="This window can be scrolled." prefix="This window can be scrolled."
echo $prefix echo $prefix
echo "" echo ""
@ -36,7 +60,7 @@ changelog(){
depcheck(){ depcheck(){
for dep in "${!deps[@]}"; do for dep in "${!deps[@]}"; do
command -v $dep 2>&1>/dev/null || (printf "[ERROR] Requires %s >= %s\nCheck your system package manager." $dep ${deps[$dep]}; exit 1) command -v $dep 2>&1>/dev/null || (printf "Requires %s >=%s\n" $dep ${deps[$dep]}; exit 1)
done done
} }
init_items(){ init_items(){
@ -46,6 +70,7 @@ items=(
"Quick connect to favorite server" "Quick connect to favorite server"
"Add server by ID" "Add server by ID"
"Add favorite server" "Add favorite server"
"Delete server"
"List installed mods" "List installed mods"
"Toggle debug mode" "Toggle debug mode"
"Report bug (opens in browser)" "Report bug (opens in browser)"
@ -119,6 +144,9 @@ debug="0"
#Toggle stable/testing branch #Toggle stable/testing branch
branch="stable" branch="stable"
#Last seen news item
seen_news=""
END END
} }
guess_path(){ guess_path(){
@ -169,7 +197,7 @@ run_depcheck() {
if [[ -z $(depcheck) ]]; then if [[ -z $(depcheck) ]]; then
: :
else else
zenity --warning --ok-label="Exit" --text="$(depcheck)" zenity --warning --ok-label="Exit" --title="DZGUI" --text="$(depcheck)"
exit exit
fi fi
} }
@ -214,6 +242,21 @@ open_mod_links(){
browser "$link_file" & browser "$link_file" &
} }
steam_deck_mods(){
until [[ -z $diff ]]; do
next=$(echo -e "$diff" | head -n1)
zenity --question --ok-label="Open" --cancel-label="Cancel" --title="DZGUI" --text="Missing mods. Click [Open] to open mod $next in Steam Workshop and subscribe to it by clicking the green Subscribe button. After the mod is downloaded, return to this menu to continue validation." 2>/dev/null
rc=$?
if [[ $rc -eq 0 ]]; then
echo "[DZGUI] Opening ${workshop}$next"
steam steam://url/CommunityFilePage/$next 2>/dev/null &
zenity --info --title="DZGUI" --ok-label="Next" --text="Click [Next] to continue mod check." 2>/dev/null
else
return
fi
compare
done
}
manual_mod_install(){ manual_mod_install(){
l=0 l=0
if [[ $is_steam_deck -eq 0 ]]; then if [[ $is_steam_deck -eq 0 ]]; then
@ -229,28 +272,31 @@ manual_mod_install(){
fi fi
done done
else else
steam_deck_mods
until [[ -z $diff ]]; do
next=$(echo -e "$diff" | head -n1)
zenity --question --ok-label="Open" --cancel-label="Cancel" --title="DZGUI" --text="Missing mods. Click [Open] to open mod $next in Steam Workshop and subscribe to it by clicking the green Subscribe button. After the mod is downloaded, return to this menu to continue validation." 2>/dev/null
rc=$?
if [[ $rc -eq 0 ]]; then
echo "[DZGUI] Opening ${workshop}$next"
steam steam://url/CommunityFilePage/$next 2>/dev/null &
zenity --info --title="DZGUI" --ok-label="Next" --text="Click [Next] to continue mod check." 2>/dev/null
else
return
fi
compare
done
fi fi
passed_mod_check passed_mod_check
} }
encode(){
echo "$1" | awk '{printf("%c",$1)}' | base64 | sed 's/\//_/g; s/=//g; s/+/]/g'
}
stale_symlinks(){
for l in $(find "$game_dir" -xtype l); do
unlink $l
done
}
legacy_symlinks(){
for d in "$game_dir"/*; do
if [[ $d =~ @[0-9]+-.+ ]]; then
unlink "$d"
fi
done
}
symlinks(){ symlinks(){
for d in "$workshop_dir"/*; do for d in "$workshop_dir"/*; do
id=$(awk -F"= " '/publishedid/ {print $2}' "$d"/meta.cpp | awk -F\; '{print $1}') 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') mod=$(awk -F\" '/name/ {print $2}' "$d"/meta.cpp | sed -E 's/[^[:alpha:]0-9]+/_/g; s/^_|_$//g')
link="@$id-$mod" link="@$encoded_id"
if [[ -h "$game_dir/$link" ]]; then if [[ -h "$game_dir/$link" ]]; then
: :
else else
@ -261,6 +307,8 @@ symlinks(){
} }
passed_mod_check(){ passed_mod_check(){
echo "[DZGUI] Passed mod check" echo "[DZGUI] Passed mod check"
stale_symlinks
legacy_symlinks
symlinks symlinks
launch launch
@ -351,8 +399,8 @@ concat_mods(){
readarray -t serv <<< "$(server_modlist)" readarray -t serv <<< "$(server_modlist)"
for i in "${serv[@]}"; do for i in "${serv[@]}"; do
id=$(awk -F"= " '/publishedid/ {print $2}' "$workshop_dir"/$i/meta.cpp | awk -F\; '{print $1}') id=$(awk -F"= " '/publishedid/ {print $2}' "$workshop_dir"/$i/meta.cpp | awk -F\; '{print $1}')
mod=$(awk -F\" '/name/ {print $2}' "$workshop_dir"/$i/meta.cpp | sed -E 's/[^[:alpha:]0-9]+/_/g; s/^_|_$//g') encoded_id=$(encode $id)
link="@$id-$mod;" link="@$encoded_id;"
echo -e "$link" echo -e "$link"
done | tr -d '\n' | perl -ple 'chop' done | tr -d '\n' | perl -ple 'chop'
fi fi
@ -360,8 +408,17 @@ concat_mods(){
launch(){ launch(){
mods=$(concat_mods) mods=$(concat_mods)
if [[ $debug -eq 1 ]]; then if [[ $debug -eq 1 ]]; then
zenity --warning --title="DZGUI" \ launch_options="steam -applaunch $aid -connect=$ip -nolauncher -nosplash -skipintro \"-mod=$mods\""
--text="$(printf "[DEBUG] This is a dry run. These options would have been used to launch the game:\n\nsteam -applaunch $aid -connect=$ip -nolauncher -nosplash -skipintro \"-mod=$mods\"\n")" 2>/dev/null print_launch_options="$(printf "[DEBUG] This is a dry run. These options would have been used to launch the game:\n\n$launch_options\n" | fold -w 60)"
zenity --question --title="DZGUI" --ok-label="Write to file" --cancel-label="Back"\
--text="$print_launch_options" 2>/dev/null
if [[ $? -eq 0 ]]; then
source_script=$(realpath "$0")
source_dir=$(dirname "$source_script")
echo "$launch_options" > "$source_dir"/options.log
echo "[DZGUI] Wrote 'options.log' to $source_dir"
fi
else else
echo "[DZGUI] All OK. Launching DayZ" echo "[DZGUI] All OK. Launching DayZ"
zenity --title="DZGUI" --info --text="Launch conditions satisfied.\nDayZ will now launch after clicking [OK]." 2>/dev/null zenity --title="DZGUI" --info --text="Launch conditions satisfied.\nDayZ will now launch after clicking [OK]." 2>/dev/null
@ -382,7 +439,7 @@ report_bug(){
if [[ $is_steam_deck -eq 1 ]]; then if [[ $is_steam_deck -eq 1 ]]; then
steam steam://openurl/"$git_url" 2>/dev/null steam steam://openurl/"$git_url" 2>/dev/null
elif [[ $is_steam_deck -eq 0 ]]; then elif [[ $is_steam_deck -eq 0 ]]; then
browser "$git_url" 2>/dev/null browser "$git_url" 2>/dev/null &
fi fi
} }
help_file(){ help_file(){
@ -390,7 +447,7 @@ help_file(){
if [[ $is_steam_deck -eq 1 ]]; then if [[ $is_steam_deck -eq 1 ]]; then
steam steam://openurl/"$help_url" 2>/dev/null steam steam://openurl/"$help_url" 2>/dev/null
elif [[ $is_steam_deck -eq 0 ]]; then elif [[ $is_steam_deck -eq 0 ]]; then
browser "$help_url" 2>/dev/null browser "$help_url" 2>/dev/null &
fi fi
} }
set_mode(){ set_mode(){
@ -400,19 +457,46 @@ set_mode(){
mode=normal mode=normal
fi fi
} }
delete_by_id(){
new_whitelist="whitelist=\"$(echo "$whitelist" | sed "s/,$server_id$//;s/^$server_id,//;s/,$server_id,/,/")\""
mv $config_file ${config_path}dztuirc.old
nr=$(awk '/whitelist=/ {print NR}' ${config_path}dztuirc.old)
awk -v "var=$new_whitelist" -v "nr=$nr" 'NR==nr {$0=var}{print}' ${config_path}dztuirc.old > ${config_path}dztuirc
echo "[DZGUI] Removed $server_id from key 'whitelist'"
zenity --info --title="DZGUI" --text="Removed "$server_id" from:\n${config_path}dztuirc\nIf errors occur, you can restore the file:\n${config_path}dztuirc.old" 2>/dev/null
source $config_file
}
delete_or_connect(){
if [[ $delete -eq 1 ]]; then
server_name=$(echo "$sel" | awk -F"%%" '{print $1}')
server_id=$(echo "$sel" | awk -F"%%" '{print $2}')
zenity --question --text="Delete this server? \n$server_name"
if [[ $? -eq 0 ]]; then
delete_by_id $server_id
fi
else
connect $sel
fi
}
populate(){ populate(){
while true; do while true; do
#TODO: add boolean statement for ping flag; affects all column ordinal output if [[ $delete -eq 1 ]]; then
cols="--column="Server" --column="ID""
set_header "delete"
else
cols="--column="Server" --column="IP" --column="Players" --column="Gametime" --column="Status" --column="ID" --column="Ping"" cols="--column="Server" --column="IP" --column="Players" --column="Gametime" --column="Status" --column="ID" --column="Ping""
set_header ${FUNCNAME[0]} set_header ${FUNCNAME[0]}
fi
rc=$? rc=$?
if [[ $rc -eq 0 ]]; then if [[ $rc -eq 0 ]]; then
if [[ -z $sel ]]; then if [[ -z $sel ]]; then
warn "No item was selected." warn "No item was selected."
else else
connect $sel delete_or_connect
return
fi fi
else else
delete=0
return return
fi fi
done done
@ -421,16 +505,20 @@ list_mods(){
if [[ -z $(installed_mods) || -z $(find $workshop_dir -maxdepth 2 -name "*.cpp" | grep .cpp) ]]; then if [[ -z $(installed_mods) || -z $(find $workshop_dir -maxdepth 2 -name "*.cpp" | grep .cpp) ]]; then
zenity --info --text="No mods currently installed or incorrect path given" $sd_res 2>/dev/null zenity --info --text="No mods currently installed or incorrect path given" $sd_res 2>/dev/null
else else
for d in $(installed_mods); do for d in $(find $game_dir/* -maxdepth 1 -type l); do
awk -F\" '/name/ {print $2}' "$workshop_dir"/$d/meta.cpp dir=$(basename $d)
done | sort | zenity --text-info --title="DZGUI" $sd_res 2>/dev/null awk -v d=$dir -F\" '/name/ {printf "%s\t%s\n", $2,d}' "$gamedir"/$d/meta.cpp
done | sort | sed 's/\t/\n/g' | zenity --list --column="Mod" --column="Symlink" --title="DZGUI" $sd_res --print-column="" 2>/dev/null
fi fi
} }
fetch_query_ports(){
qport_list=$(echo "$response" | jq -r '.data[] .attributes | "\(.ip):\(.port)%%\(.portQuery)"')
}
connect_to_fav(){ connect_to_fav(){
if [[ -n $fav ]]; then if [[ -n $fav ]]; then
one_shot_launch=1 one_shot_launch=1
query_api query_api
qport_list=$(echo "$response" | jq -r '.data[] .attributes | "\(.ip):\(.port)%%\(.portQuery)"') fetch_query_ports
echo "[DZGUI] Attempting connection to $fav_label" echo "[DZGUI] Attempting connection to $fav_label"
connect "$qport_list" connect "$qport_list"
one_shot_launch=0 one_shot_launch=0
@ -440,12 +528,15 @@ connect_to_fav(){
} }
set_header(){ set_header(){
if [[ $1 == "populate" ]]; then if [[ $1 == "delete" ]]; then
sel=$(cat $tmp | zenity $sd_res --list $cols --title="DZGUI" --text="DZGUI $version | Mode: $mode | Branch: $branch | Fav: $fav_label" \
--separator="$separator" --print-column=1,2 --ok-label="Delete" 2>/dev/null)
elif [[ $1 == "populate" ]]; then
sel=$(cat $tmp | zenity $sd_res --list $cols --title="DZGUI" --text="DZGUI $version | Mode: $mode | Branch: $branch | Fav: $fav_label" \ sel=$(cat $tmp | zenity $sd_res --list $cols --title="DZGUI" --text="DZGUI $version | Mode: $mode | Branch: $branch | Fav: $fav_label" \
--separator="$separator" --print-column=2,6 2>/dev/null) --separator="$separator" --print-column=2,6 2>/dev/null)
elif [[ $1 == "main_menu" ]]; then elif [[ $1 == "main_menu" ]]; then
sel=$(zenity --width=1280 --height=800 --list --title="DZGUI" --text="DZGUI $version | Mode: $mode | Branch: $branch | Fav: $fav_label" \ sel=$(zenity $sd_res --list --title="DZGUI" --text="${news}DZGUI $version | Mode: $mode | Branch: $branch | Fav: $fav_label" \
--cancel-label="Exit" --ok-label="Select" --column="Select launch option" "${items[@]}" 2>/dev/null) --cancel-label="Exit" --ok-label="Select" --column="Select launch option" --hide-header "${items[@]}" 2>/dev/null)
fi fi
} }
toggle_branch(){ toggle_branch(){
@ -465,27 +556,13 @@ debug_menu(){
debug_list=( debug_list=(
"Toggle branch" "Toggle branch"
) )
debug_sel=$(zenity --list --width=1280 --height=800 --column="Options" --title="DZGUI" "${debug_list[@]}" 2>/dev/null) debug_sel=$(zenity --list --width=1280 --height=800 --column="Options" --title="DZGUI" --hide-header "${debug_list[@]}" 2>/dev/null)
if [[ $debug_sel == "${debug_list[0]}" ]]; then if [[ $debug_sel == "${debug_list[0]}" ]]; then
toggle_branch toggle_branch
check_version check_version
fi fi
} }
main_menu(){ query_and_connect(){
if [[ $debug -eq 1 ]]; then
items+=("Debug options")
fi
set_mode
if [[ -n $fav ]]; then
items[3]="Change favorite server"
fi
while true; do
set_header ${FUNCNAME[0]}
rc=$?
if [[ $rc -eq 0 ]]; then
if [[ -z $sel ]]; then
warn "No item was selected."
elif [[ $sel == "${items[0]}" ]]; then
query_api query_api
parse_json <<< "$response" parse_json <<< "$response"
#TODO: create logger function #TODO: create logger function
@ -497,6 +574,25 @@ main_menu(){
else else
populate populate
fi fi
}
main_menu(){
print_news
set_mode
if [[ $debug -eq 1 ]]; then
items+=("Debug options")
fi
if [[ -n $fav ]]; then
items[3]="Change favorite server"
fi
while true; do
set_header ${FUNCNAME[0]}
rc=$?
if [[ $rc -eq 0 ]]; then
if [[ -z $sel ]]; then
warn "No item was selected."
elif [[ $sel == "${items[0]}" ]]; then
query_and_connect
elif [[ $sel == "${items[1]}" ]]; then elif [[ $sel == "${items[1]}" ]]; then
connect_to_fav connect_to_fav
elif [[ $sel == "${items[2]}" ]]; then elif [[ $sel == "${items[2]}" ]]; then
@ -504,18 +600,21 @@ main_menu(){
elif [[ $sel == "${items[3]}" ]]; then elif [[ $sel == "${items[3]}" ]]; then
add_by_fav add_by_fav
elif [[ $sel == "${items[4]}" ]]; then elif [[ $sel == "${items[4]}" ]]; then
list_mods delete=1
query_and_connect
elif [[ $sel == "${items[5]}" ]]; then elif [[ $sel == "${items[5]}" ]]; then
list_mods
elif [[ $sel == "${items[6]}" ]]; then
toggle_debug toggle_debug
main_menu main_menu
return return
elif [[ $sel == "${items[6]}" ]]; then
report_bug
elif [[ $sel == "${items[7]}" ]]; then elif [[ $sel == "${items[7]}" ]]; then
help_file report_bug
elif [[ $sel == "${items[8]}" ]]; then elif [[ $sel == "${items[8]}" ]]; then
changelog | zenity --text-info $sd_res --title="DZGUI" 2>/dev/null help_file
elif [[ $sel == "${items[9]}" ]]; then elif [[ $sel == "${items[9]}" ]]; then
changelog | zenity --text-info $sd_res --title="DZGUI" 2>/dev/null
elif [[ $sel == "${items[10]}" ]]; then
debug_menu debug_menu
else else
warn "This feature is not yet implemented." warn "This feature is not yet implemented."
@ -527,7 +626,8 @@ main_menu(){
} }
parse_json(){ parse_json(){
list=$(jq -r '.data[] .attributes | "\(.name)\t\(.ip):\(.port)\t\(.players)/\(.maxPlayers)\t\(.details.time)\t\(.status)\t\(.id)"') list=$(jq -r '.data[] .attributes | "\(.name)\t\(.ip):\(.port)\t\(.players)/\(.maxPlayers)\t\(.details.time)\t\(.status)\t\(.id)"')
qport_list=$(echo "$response" | jq -r '.data[] .attributes | "\(.ip):\(.port)%%\(.portQuery)"') fetch_query_ports
#qport_list=$(echo "$response" | jq -r '.data[] .attributes | "\(.ip):\(.port)%%\(.portQuery)"')
echo -e "$list" > $tmp echo -e "$list" > $tmp
} }
check_ping(){ check_ping(){
@ -562,10 +662,14 @@ create_array(){
#TODO: probe offline return codes #TODO: probe offline return codes
id=$(echo "$line" | awk -F'\t' '{print $6}') id=$(echo "$line" | awk -F'\t' '{print $6}')
tc=$(awk 'END{print NR}' $tmp) tc=$(awk 'END{print NR}' $tmp)
if [[ $delete -eq 1 ]]; then
declare -g -a rows=("${rows[@]}" "$name" "$id")
else
echo "$lc/$tc" echo "$lc/$tc"
echo "# Checking ping: $lc/$tc" echo "# Checking ping: $lc/$tc"
ping=$(check_ping "$line") ping=$(check_ping "$line")
declare -g -a rows=("${rows[@]}" "$name" "$ip" "$players" "$time" "$stat" "$id" "$ping") declare -g -a rows=("${rows[@]}" "$name" "$ip" "$players" "$time" "$stat" "$id" "$ping")
fi
let lc++ let lc++
done <<< "$list" done <<< "$list"
@ -646,8 +750,8 @@ check_version(){
fi fi
} }
check_architecture(){ check_architecture(){
os_release=$(awk '/SteamOS/' "/etc/os-release") cpu=$(cat /proc/cpuinfo | grep "AMD Custom APU 0405")
if [[ -f "/etc/os-release" ]] && [[ -n $os_releasec ]]; then if [[ -n $cpu ]]; then
is_steam_deck=1 is_steam_deck=1
echo "[DZGUI] Setting architecture to 'Steam Deck'" echo "[DZGUI] Setting architecture to 'Steam Deck'"
else else
@ -700,6 +804,18 @@ setup(){
items[3]="Change favorite server" items[3]="Change favorite server"
fi fi
} }
check_map_count(){
count=1048576
if [[ $(sysctl -q vm.max_map_count | awk -F"= " '{print $2}') -ne $count ]]; then
map_warning=$(zenity --question --title="DZGUI" --text "System map count must be $count or higher to run DayZ with Wine. Increase map count and make this change permanent? (will prompt for sudo password)" 2>/dev/null)
if [[ $? -eq 0 ]]; then
pass=$(zenity --password)
sudo -S <<< "$pass" sh -c "echo 'vm.max_map_count=1048576' > /etc/sysctl.d/dayz.conf"
echo ""
fi
fi
}
add_by_fav(){ add_by_fav(){
while true; do while true; do
fav_id=$(zenity --entry --text="Enter server ID" --title="DZGUI" 2>/dev/null) fav_id=$(zenity --entry --text="Enter server ID" --title="DZGUI" 2>/dev/null)
@ -728,6 +844,7 @@ main(){
run_depcheck run_depcheck
check_version check_version
check_architecture check_architecture
check_map_count
config config
run_varcheck run_varcheck
init_items init_items