mirror of
https://github.com/aclist/dztui.git
synced 2024-12-29 13:52:03 +01:00
fix: encapsulate news function
This commit is contained in:
parent
373164b7ee
commit
dc6f82ed6e
1 changed files with 19 additions and 14 deletions
31
dzgui.sh
31
dzgui.sh
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
version=4.1.0
|
version=4.1.1
|
||||||
|
|
||||||
aid=221100
|
aid=221100
|
||||||
game="dayz"
|
game="dayz"
|
||||||
|
@ -40,31 +40,36 @@ version_file="$config_path/versions"
|
||||||
steamsafe_zenity="/usr/bin/zenity"
|
steamsafe_zenity="/usr/bin/zenity"
|
||||||
|
|
||||||
update_last_seen(){
|
update_last_seen(){
|
||||||
|
local news_sum="$1"
|
||||||
mv $config_file ${config_path}dztuirc.old
|
mv $config_file ${config_path}dztuirc.old
|
||||||
nr=$(awk '/seen_news=/ {print NR}' ${config_path}dztuirc.old)
|
nr=$(awk '/seen_news=/ {print NR}' ${config_path}dztuirc.old)
|
||||||
seen_news="seen_news=\"$sum\""
|
seen_news="seen_news=\"$news_sum\""
|
||||||
awk -v "var=$seen_news" -v "nr=$nr" 'NR==nr {$0=var}{print}' ${config_path}dztuirc.old > $config_file
|
awk -v "var=$seen_news" -v "nr=$nr" 'NR==nr {$0=var}{print}' ${config_path}dztuirc.old > $config_file
|
||||||
source $config_file
|
source $config_file
|
||||||
}
|
}
|
||||||
check_news(){
|
check_news(){
|
||||||
logger INFO "${FUNCNAME[0]}"
|
logger INFO "${FUNCNAME[0]}"
|
||||||
echo "# Checking news"
|
|
||||||
[[ $branch == "stable" ]] && news_url="$stable_url/news"
|
[[ $branch == "stable" ]] && news_url="$stable_url/news"
|
||||||
[[ $branch == "testing" ]] && news_url="$testing_url/news"
|
[[ $branch == "testing" ]] && news_url="$testing_url/news"
|
||||||
local result=$(curl -Ls "$news_url")
|
local result=$(curl -Ls "$news_url")
|
||||||
sum=$(echo -n "$result" | md5sum | awk '{print $1}')
|
local sum=$(echo -n "$result" | md5sum | awk '{print $1}')
|
||||||
|
printf "%s\n%s\n" "$result" "$sum"
|
||||||
logger INFO "News: $result"
|
logger INFO "News: $result"
|
||||||
}
|
}
|
||||||
print_news(){
|
print_news(){
|
||||||
|
readarray -t news_result < <(check_news)
|
||||||
|
local news_marquee=${news_result[0]}
|
||||||
|
local news_sum=${news_result[1]}
|
||||||
|
local hchar
|
||||||
|
local news
|
||||||
logger INFO "${FUNCNAME[0]}"
|
logger INFO "${FUNCNAME[0]}"
|
||||||
if [[ $sum == $seen_news || -z $result ]]; then
|
if [[ $news_sum == $seen_news ]] || [[ -z $news_marquee ]]; then
|
||||||
hchar=""
|
return 1
|
||||||
news=""
|
|
||||||
else
|
|
||||||
hchar="─"
|
|
||||||
news="$result\n$(awk -v var="$hchar" 'BEGIN{for(c=0;c<90;c++) printf var;}')\n"
|
|
||||||
update_last_seen
|
|
||||||
fi
|
fi
|
||||||
|
hchar="─"
|
||||||
|
news="$news_marquee\n$(awk -v var="$hchar" 'BEGIN{for(c=0;c<90;c++) printf var;}')\n"
|
||||||
|
update_last_seen "$news_sum"
|
||||||
|
echo "$news"
|
||||||
}
|
}
|
||||||
|
|
||||||
declare -A deps
|
declare -A deps
|
||||||
|
@ -998,7 +1003,8 @@ set_header(){
|
||||||
local switch="$1"
|
local switch="$1"
|
||||||
logger INFO "${FUNCNAME[0]}"
|
logger INFO "${FUNCNAME[0]}"
|
||||||
logger INFO "Header mode is $1"
|
logger INFO "Header mode is $1"
|
||||||
print_news
|
local news
|
||||||
|
news=$(print_news)
|
||||||
[[ $auto_install -eq 2 ]] && install_mode="auto"
|
[[ $auto_install -eq 2 ]] && install_mode="auto"
|
||||||
[[ $auto_install -eq 1 ]] && install_mode="headless"
|
[[ $auto_install -eq 1 ]] && install_mode="headless"
|
||||||
[[ $auto_install -eq 0 ]] && install_mode=manual
|
[[ $auto_install -eq 0 ]] && install_mode=manual
|
||||||
|
@ -2117,7 +2123,6 @@ initial_setup(){
|
||||||
stale_symlinks
|
stale_symlinks
|
||||||
init_items
|
init_items
|
||||||
setup
|
setup
|
||||||
check_news
|
|
||||||
echo "100"
|
echo "100"
|
||||||
}
|
}
|
||||||
main(){
|
main(){
|
||||||
|
|
Loading…
Reference in a new issue