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

Merge testing changes

This commit is contained in:
aclist 2022-08-16 19:29:33 +09:00 committed by GitHub
parent b2dcbbd510
commit 78caecc4b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

126
dzgui.sh
View file

@ -1,7 +1,8 @@
#!/bin/bash #!/bin/bash
set -o pipefail set -o pipefail
version=2.4.1 version=2.5.0
aid=221100 aid=221100
game="dayz" game="dayz"
workshop="steam://url/CommunityFilePage/" workshop="steam://url/CommunityFilePage/"
@ -44,7 +45,7 @@ print_news(){
fi fi
} }
#TODO: prevent connecting to offline servers #TODO: prevent connecting to offline servers
#TODO: abstract zenity title params #TODO: abstract zenity title params and dimensions
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" [steam]="1.0.0") deps=([awk]="5.1.1" [curl]="7.80.0" [jq]="1.6" [tr]="9.0" [zenity]="3.42.1" [steam]="1.0.0")
@ -80,11 +81,6 @@ items=(
"View changelog" "View changelog"
) )
} }
exit_and_cleanup(){
#TODO: this is currently unused
rm $tmp
rm $link_file
}
warn_and_exit(){ warn_and_exit(){
zenity --info --title="DZGUI" --text="$1" --icon-name="dialog-warning" 2>/dev/null zenity --info --title="DZGUI" --text="$1" --icon-name="dialog-warning" 2>/dev/null
printf "[DZGUI] %s\n" "$check_config_msg" printf "[DZGUI] %s\n" "$check_config_msg"
@ -96,6 +92,12 @@ warn(){
info(){ info(){
zenity --info --title="DZGUI" --text="$1" 2>/dev/null zenity --info --title="DZGUI" --text="$1" 2>/dev/null
} }
set_api_params(){
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(){ query_api(){
#TODO: prevent drawing list if null values returned without API error #TODO: prevent drawing list if null values returned without API error
if [[ $one_shot_launch -eq 1 ]]; then if [[ $one_shot_launch -eq 1 ]]; then
@ -107,8 +109,7 @@ query_api(){
list_of_ids="$whitelist" list_of_ids="$whitelist"
fi fi
fi fi
response=$(curl -s "$api" -H "Authorization: Bearer "$api_key"" -G -d "sort=-players" \ set_api_params
-d "filter[game]=$game" -d "filter[ids][whitelist]=$list_of_ids")
if [[ "$(jq -r 'keys[]' <<< "$response")" == "errors" ]]; then if [[ "$(jq -r 'keys[]' <<< "$response")" == "errors" ]]; then
code=$(jq -r '.errors[] .status' <<< $response) code=$(jq -r '.errors[] .status' <<< $response)
#TODO: fix granular api codes #TODO: fix granular api codes
@ -178,30 +179,35 @@ freedesktop_dirs(){
write_desktop_file > "$HOME/Desktop/dzgui.desktop" write_desktop_file > "$HOME/Desktop/dzgui.desktop"
fi fi
} }
guess_path(){ file_picker(){
echo "# Checking for default DayZ path" #TODO: unimplemented
path=$(find $HOME -path "*.local/share/Steam/steamapps/common/DayZ" | wc -c) while true; do
if [[ ! $path -eq 0 ]]; then local path=$(zenity --file-selection --directory 2>/dev/null)
steam_path="$HOME/.local/share/Steam" if [[ -z "$path" ]] || [[ ! -d "$path" ]] || [[ ! "$path" =~ steamapps/common/DayZ ]]; then
else continue
echo "# Searching for alternate DayZ path (make take some time)" else
path=$(find / -path "*/steamapps/common/DayZ" 2>/dev/null) echo "[DZGUI]" Set path to $path
if [[ $(echo "$path" | wc -l) -gt 1 ]]; then
path_sel=$(echo -e "$path" | zenity --list --title="DZGUI" --text="Multiple paths found. Select correct DayZ path" --column="Paths" --width 1200 --height 800)
clean_path=$(echo -e "$path_sel" | awk -F"/steamapps" '{print $1}')
steam_path="$clean_path"
elif [[ ! $(echo $path | wc -c) -eq 0 ]]; then
clean_path=$(echo -e "$path" | awk -F"/steamapps" '{print $1}') clean_path=$(echo -e "$path" | awk -F"/steamapps" '{print $1}')
steam_path="$clean_path" steam_path="$clean_path"
else return
steam_path=""
fi fi
done
}
guess_path(){
echo "# Checking for default DayZ path"
path=$(find $HOME -type d -regex ".*/steamapps/common/DayZ$" -print -quit)
if [[ -n $path ]]; then
steam_path="$path"
else
echo "# Searching for alternate DayZ path. This may take some time."
path=$(find / -type d \( -path "/proc" -o -path "*/timeshift" -o -path "/tmp" -o -path "/usr" -o -path "/boot" -o -path "/proc" -o -path "/root" -o -path "/run" -o -path "/sys" -o -path "/etc" -o -path "/var" -o -path "/run" -o -path "/lost+found" \) -prune -o -regex ".*/steamapps/common/DayZ$" -print -quit 2>/dev/null)
clean_path=$(echo -e "$path" | awk -F"/steamapps" '{print $1}')
steam_path="$clean_path"
fi fi
echo "[DZGUI] Set Steam path to $steam_path"
} }
create_config(){ create_config(){
while true; do while true; do
player_input="$(zenity --forms --add-entry="Player name (required for some servers)" --add-entry="API key" --add-entry="Server 1 (you can add more later)" --title=DZGUI --text=DZGUI --add-entry="Server 2" --add-entry="Server 3" --add-entry="Server 4" $sd_res --separator="│")" player_input="$(zenity --forms --add-entry="Player name (required for some servers)" --add-entry="API key" --add-entry="Server 1 (you can add more later)" --title=DZGUI --text=DZGUI --add-entry="Server 2" --add-entry="Server 3" --add-entry="Server 4" $sd_res --separator="│" 2>/dev/null)"
#explicitly setting IFS crashes zenity in loop #explicitly setting IFS crashes zenity in loop
#and mapfile does not support high ascii delimiters #and mapfile does not support high ascii delimiters
#so split fields with newline #so split fields with newline
@ -228,7 +234,9 @@ create_config(){
warn "Server 4: only numeric IDs" warn "Server 4: only numeric IDs"
else else
whitelist=$(echo "$player_input" | awk -F"│" '{OFS=","}{print $3,$4,$5,$6}' | sed 's/,*$//g' | sed 's/^,*//g') whitelist=$(echo "$player_input" | awk -F"│" '{OFS=","}{print $3,$4,$5,$6}' | sed 's/,*$//g' | sed 's/^,*//g')
guess_path > >(zenity --width 500 --progress --auto-close --pulsate) guess_path > >(zenity --width 500 --progress --auto-close --pulsate 2>/dev/null) &&
echo "[DZGUI] Set path to $steam_path"
#FIXME: tech debt: gracefully exit if user cancels search process
mkdir -p $config_path; write_config > $config_file mkdir -p $config_path; write_config > $config_file
info "Config file created at $config_file." info "Config file created at $config_file."
return return
@ -336,7 +344,7 @@ manual_mod_install(){
passed_mod_check passed_mod_check
} }
encode(){ encode(){
echo "$1" | awk '{printf("%c",$1)}' | base64 | sed 's/\//_/g; s/=//g; s/+/]/g' echo "$1" | md5sum | cut -c -8
} }
stale_symlinks(){ stale_symlinks(){
for l in $(find "$game_dir" -xtype l); do for l in $(find "$game_dir" -xtype l); do
@ -349,6 +357,13 @@ legacy_symlinks(){
unlink "$d" unlink "$d"
fi fi
done done
for d in "$workshop_dir"/*; do
local id=$(awk -F"= " '/publishedid/ {print $2}' "$d"/meta.cpp | awk -F\; '{print $1}')
local encoded_id=$(echo "$id" | awk '{printf("%c",$1)}' | base64 | sed 's/\//_/g; s/=//g; s/+/]/g')
if [[ -h "$game_dir/@$encoded_id" ]]; then
unlink "$game_dir/@$encoded_id"
fi
done
} }
symlinks(){ symlinks(){
for d in "$workshop_dir"/*; do for d in "$workshop_dir"/*; do
@ -376,7 +391,7 @@ connect(){
#TODO: sanitize/validate input #TODO: sanitize/validate input
readarray -t qport_arr <<< "$qport_list" readarray -t qport_arr <<< "$qport_list"
if [[ -z ${qport_arr[@]} ]]; then if [[ -z ${qport_arr[@]} ]]; then
err "Failed to process favorite server" err "Failed to obtain query ports"
return return
fi fi
ip=$(echo "$1" | awk -F"$separator" '{print $1}') ip=$(echo "$1" | awk -F"$separator" '{print $1}')
@ -470,12 +485,13 @@ launch(){
source_script=$(realpath "$0") source_script=$(realpath "$0")
source_dir=$(dirname "$source_script") source_dir=$(dirname "$source_script")
echo "$launch_options" > "$source_dir"/options.log echo "$launch_options" > "$source_dir"/options.log
echo "[DZGUI] Wrote 'options.log' to $source_dir" echo "[DZGUI] Wrote launch options to $source_dir/options.log"
zenity --info --width 500 --title="DZGUI" --text="Wrote launch options to \n$source_dir/options.log" 2>/dev/null
fi 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 --width 500 --title="DZGUI" --info --text="Launch conditions satisfied.\nDayZ will now launch after clicking [OK]." 2>/dev/null
steam -applaunch $aid -connect=$ip -nolauncher -nosplash -skipintro -name=$name \"-mod=$mods\" steam -applaunch $aid -connect=$ip -nolauncher -nosplash -skipintro -name=$name \"-mod=$mods\"
exit exit
fi fi
@ -638,7 +654,7 @@ debug_menu(){
} }
query_and_connect(){ query_and_connect(){
query_api query_api
parse_json <<< "$response" parse_json
#TODO: create logger function #TODO: create logger function
echo "[DZGUI] Checking response time of servers" echo "[DZGUI] Checking response time of servers"
create_array | zenity --width 500 --progress --pulsate --title="DZGUI" --auto-close 2>/dev/null create_array | zenity --width 500 --progress --pulsate --title="DZGUI" --auto-close 2>/dev/null
@ -698,10 +714,28 @@ main_menu(){
fi fi
done done
} }
page_through(){
list_response=$(curl -s "$page")
list=$(echo "$list_response" | jq -r '.data[] .attributes | "\(.name)\t\(.ip):\(.port)\t\(.players)/\(.maxPlayers)\t\(.details.time)\t\(.status)\t\(.id)"')
idarr+=("$list")
parse_json
}
parse_json(){ parse_json(){
list=$(jq -r '.data[] .attributes | "\(.name)\t\(.ip):\(.port)\t\(.players)/\(.maxPlayers)\t\(.details.time)\t\(.status)\t\(.id)"') page=$(echo "$list_response" | jq -r '.links.next?')
fetch_query_ports if [[ $first_entry -eq 1 ]]; then
echo -e "$list" > $tmp list=$(echo "$list_response" | jq -r '.data[] .attributes | "\(.name)\t\(.ip):\(.port)\t\(.players)/\(.maxPlayers)\t\(.details.time)\t\(.status)\t\(.id)"')
idarr+=("$list")
first_entry=0
fi
if [[ "$page" != "null" ]]; then
list=$(echo "$list_response" | jq -r '.data[] .attributes | "\(.name)\t\(.ip):\(.port)\t\(.players)/\(.maxPlayers)\t\(.details.time)\t\(.status)\t\(.id)"')
idarr+=("$list")
page_through
else
printf "%s\n" "${idarr[@]}" > $tmp
idarr=()
fetch_query_ports
fi
} }
check_ping(){ check_ping(){
ping_ip=$(echo "$1" | awk -F'\t' '{print $2}' | awk -F: '{print $1}') ping_ip=$(echo "$1" | awk -F'\t' '{print $2}' | awk -F: '{print $1}')
@ -749,6 +783,7 @@ create_array(){
} }
set_fav(){ set_fav(){
#TODO: test API key here and return errors #TODO: test API key here and return errors
echo "[DZGUI] Querying favorite server"
query_api query_api
fav_label=$(curl -s "$api" -H "Authorization: Bearer "$api_key"" -G -d "filter[game]=$game" -d "filter[ids][whitelist]=$fav" \ fav_label=$(curl -s "$api" -H "Authorization: Bearer "$api_key"" -G -d "filter[game]=$game" -d "filter[ids][whitelist]=$fav" \
| jq -r '.data[] .attributes .name') | jq -r '.data[] .attributes .name')
@ -929,7 +964,27 @@ while true; do
fi fi
done done
} }
#cleanup(){
# rm $config_path/.lockfile
#}
lock(){
if [[ ! -f $config_path/.lockfile ]]; then
touch $config_path/.lockfile
fi
pid=$(cat $config_path/.lockfile)
ps -p $pid -o pid= >/dev/null 2>&1
res=$?
if [[ $res -eq 0 ]]; then
echo "[DZGUI] Already running ($pid)"
exit
elif [[ $pid == $$ ]]; then
:
else
echo $$ > $config_path/.lockfile
fi
}
main(){ main(){
lock
run_depcheck run_depcheck
check_architecture check_architecture
check_version check_version
@ -942,3 +997,4 @@ main(){
} }
main main
#trap cleanup EXIT