diff --git a/banner-empty.jpg b/banner-empty.jpg new file mode 100644 index 0000000..233a355 Binary files /dev/null and b/banner-empty.jpg differ diff --git a/banner-example.jpg b/banner-example.jpg new file mode 100644 index 0000000..3e31ff9 Binary files /dev/null and b/banner-example.jpg differ diff --git a/banner-input.jpg b/banner-input.jpg index ff874e4..e477005 100644 Binary files a/banner-input.jpg and b/banner-input.jpg differ diff --git a/generate-banner.sh b/generate-banner.sh index 7bdd22a..42fc35c 100755 --- a/generate-banner.sh +++ b/generate-banner.sh @@ -1,35 +1,60 @@ #!/bin/bash -#echo "$(date)" -#uptime: +#################### +###### CONFIG ###### +#################### +inputPath="./banner-input.jpg" #background used for text +inputEmpty="./banner-empty.jpg" #copied when no players online +outputPath="/var/www/files.raidworld.net/teamspeak/Banner_dynamic.jpg" +#fontPath="./FatFrank.otf" +fontPath="./integral-cf_regular.otf" + +posx=65 +posy=725 +pointSize=40 +textColor1="#ff7900" #colorlist: showrgb +textColor2="white" + + + + +####################################### +########## GET PLAYER COUNTS ########## +####################################### uptime=$(awk '{printf "%.2f\n",$1/86400}' /proc/uptime) - -#Minecraft: -vanilla=$(netstat -tn | grep -i 25565 | grep ESTABLISHED | wc -l) -build=$(netstat -tn | grep -i 1234 | grep ESTABLISHED | wc -l) -wasteland=$(netstat -tn | grep -i 2222 | grep ESTABLISHED | wc -l) -#Minecraft=$(($vanilla+$wasteland)) #(simpel) - -#mit vergleich: -last=$(<.minecraftlog) -#echo "last: $last" -if [ $(($vanilla+$wasteland+$build)) -gt 0 ]; then - if [ "$last" == "1" ]; then - Minecraft=$(($vanilla+$wasteland+$build)) - else - echo "note: minecraft: $(($vanilla+$wasteland+$build)) aber vorher 0 =>ignorieren" - echo "1" > .minecraftlog - Minecraft=0 - fi -else - echo "0" > .minecraftlog - Minecraft=0 -fi +################# +### Minecraft ### +################# + echo "=> obtaining minecraft player count..." + vanilla=$(netstat -tn | grep -i 25565 | grep ESTABLISHED | wc -l) + build=$(netstat -tn | grep -i 1234 | grep ESTABLISHED | wc -l) + wasteland=$(netstat -tn | grep -i 2222 | grep ESTABLISHED | wc -l) + #Minecraft=$(($vanilla+$wasteland)) #simple version + + #TODO: this needs rework? + #smooth count (prevent rare false detection) + last=$(ignorieren" + echo "1" > tmp/minecraftlog + Minecraft=0 + fi + else + echo "0" > tmp/minecraftlog + Minecraft=0 + fi -#Teeworlds: +################# +### Teeworlds ### +################# +echo "=> obtaining teeworlds player count..." telnet_teeworlds_zcatch () { expect << EOF spawn telnet -e q raidworld.net 6431 @@ -60,133 +85,99 @@ telnet_teeworlds_vanilla () { expect -re ".*>" EOF } - -echo "debug: fetching teeworlds players via telnet..." tw_zcatch="$(telnet_teeworlds_zcatch | sed 's/^..//' | grep -o 'rver]: id=' | wc -l)" tw_vanilla="$(telnet_teeworlds_vanilla | sed 's/^..//' | grep -o 'rver]: id=' | wc -l)" Teeworlds=$(($tw_zcatch+$tw_vanilla)) -########################### -#######Urbanterror:######## -echo "debug: fetching urbanterro players via lynx" -output="$(lynx -dump -nolist http://www.Urbanterror.info/servers/91.250.87.150:27960/ | grep Slots | cut -c 18-19)" -Urbanterror="${output// /}" -Urbanterror=0 + +################# +## Urbanterror ## +################# + # echo "=> obtaining urbanterror player count..." + # output="$(lynx -dump -nolist http://www.Urbanterror.info/servers/91.250.87.150:27960/ | grep Slots | cut -c 18-19)" + # Urbanterror="${output// /}" + # Urbanterror=0 +################## +### 7daystodie ### +################## + # echo "=> obtaining 7days-to-die player count..." + # output="$(lynx -dump -nolist https://7daystodie-servers.com/server/60948/ | grep Players | cut -c 21-22)" + # daystodie="${output// /}" + # daystodie=0 + + + +################ +### Factorio ### +################ + # echo "=> obtaining factorio player count..." + # disconnected="$(grep -o "Disconnect notification" /home/factorio/factorio/factorio-current.log | wc -l)" + # connected="$(grep -o "JoinGame" /home/factorio/factorio/factorio-current.log | wc -l)" + # #echo "Factorio-disconnected: $disconnected" + # #echo "Factorio-connected: $connected" + # if [ $(($connected - $disconnected)) -gt 0 ]; then + # Factorio=$(($connected - $disconnected)) + # else + # Factorio=0 + # fi + ########################## -###3####7daystodie:####### -###echo "debug: fetching 7daystodie players via lynx" -###output="$(lynx -dump -nolist https://7daystodie-servers.com/server/60948/ | grep Players | cut -c 21-22)" -###daystodie="${output// /}" -#echo $daystodie -daystodie=0 - - - - - - -############################# -#######Factorio:################# -### disconnected="$(grep -o "Disconnect notification" /home/factorio/factorio/factorio-current.log | wc -l)" -### connected="$(grep -o "JoinGame" /home/factorio/factorio/factorio-current.log | wc -l)" -### #echo "Factorio-disconnected: $disconnected" -### #echo "Factorio-connected: $connected" -### if [ $(($connected - $disconnected)) -gt 0 ]; then -### Factorio=$(($connected - $disconnected)) -### else -### Factorio=0 -### fi -### ##echo "=>Factorio-Players: $Factorio" - - -Factorio=0 - - - - - - - - - -#Minecraft=2 -Minecraft=$((Minecraft+0)) -#Teeworlds=12 -#Urbanterror=4 +#### Manipulate count #### +########################## +#Force player count for testing +#Minecraft=1 +#Minecraft=$((Minecraft+0)) +#Teeworlds=20 +#Urbanterror=1 #daystodie=1 -#Factorio=2 +#Factorio=0 -#player or players function: (OLD) -players_function () { #./players_function input output -if [ $1 -gt 1 ]; then - echo "Players" -else - echo "Player" -fi + + + + +#Function that generates commands for creating the following text, while supporting 2 different colors: +#"GAME-NAME(parameter-name):" "COUNT(parameter-value)" "player/players" +#The necessary convert options are appended to the cmd array for later execution with convert +GameToTextCmd () { + #command for "GAME-NAME": + cmd+=(-font $fontPath -pointsize $pointSize -fill $textColor1 label:"${1}: " ) + + if [ ${!1} -gt 1 ]; then + #command for "COUNT + 'playerS'" + cmd+=(-font $fontPath -pointsize $pointSize -fill $textColor2 label:"${!1} Players ") + else + #command for "COUNT + 'player'" + cmd+=(-font $fontPath -pointsize $pointSize -fill $textColor2 label:"${!1} Player ") + fi } - -#text function (-game: number player/players) +exeptions (NEW) -game_players_function () { #./players_function input output -if [ ${!1} -gt 1 ]; then - if [ "$1" == "daystodie" ]; then - echo "-7 Days to Die: ${!1} Players" - else - echo "-$1:${!1} Players" - fi -else - if [ "$1" == "daystodie" ]; then - echo "-7 Days to Die: ${!1} Player" - else - echo "-$1: ${!1}Player" - fi -fi -} - - -#text function (-game: number player/players) +exeptions (NEW) -game_players_function_ohne_minus () { #./players_function input output -if [ ${!1} -gt 1 ]; then - if [ "$1" == "daystodie" ]; then - echo "7 Days to Die: ${!1} Players" - else - echo "$1: ${!1} Players" - fi -else - if [ "$1" == "daystodie" ]; then - echo "7 Days to Die: ${!1} Player" - else - echo "$1: ${!1} Player" - fi -fi -} - - - +######################################## +##### Commands for text generation ##### +######################################## +#Generate commands for each game and add spacer between games when necessary: firstgame=1 text="null" - -#when at least one player is online, write text to variable -echo "debug: checking if at least one player online" for game in Minecraft Teeworlds Urbanterror daystodie Factorio #list of games do #echo "$game: ${!game}" if [[ ${!game} -gt 0 ]]; then if [ $firstgame -eq 1 ]; then - text=$(game_players_function_ohne_minus $game) + GameToTextCmd $game firstgame=0 - else - text="$text | $(game_players_function_ohne_minus $game)" + else # add spacer + cmd+=(-font $fontPath -pointsize $pointSize -fill $textColor1 label:"// ") + GameToTextCmd $game fi fi done @@ -194,159 +185,28 @@ done - - - - -#convert: add text: -#inputpath="/home/raidworld/www.raidworld.eu/secretfiles/other/Raidworld_Banner_meanwhile_default.jpg" -#outputpath="/home/raidworld/www.raidworld.eu/secretfiles/other/Raidworld_Banner_meanwhile_dynamic.jpg" -inputpath="/var/www/files.raidworld.net/teamspeak/Banner_original.jpg" -outputpath="/var/www/files.raidworld.net/teamspeak/Banner_dynamic.jpg" -#outputpath="/home/raidworld/www.raidworld.net/wordpress/wp-content/uploads/ts-banner/Raidworld_Banner_final-dynamic.jpg" -posx=78 -posy=52 -textcolor="gray49" #colorlist: showrgb -undercolor="none" #"none" for no color -line=0 - - - if [ "$text" != "null" ]; then - echo "debug: generating banner" - echo "TEXT: $text" - gm convert -font /home/teamspeak/dynamic-banner/FatFrank.otf -undercolor $undercolor -pointsize 40 -fill black -draw "text $(($posx+1)), $(($posy+1)) \"$text" $inputpath "./banner-temp.jpg" - gm convert -font /home/teamspeak/dynamic-banner/FatFrank.otf -pointsize 40 -fill $textcolor -draw "text $posx, $posy \"$text" "./banner-temp.jpg" $outputpath - echo "-----------------------------" - else - echo "TEXT: $text" - echo "=>noone playing... copying default image" - cp $inputpath $outputpath - sleep 1 - echo "-----------------------------" - fi - -chmod 666 $outputpath - - - - - - - - - - - - -#/home/teamspeak/dynamic-banner/FatFrank-Free.otf - - - - -<<"COMMENT" -if false -then -###OLD (ohne schleifen) -############################################################################# - -players_function () { #./players_function input output -if [ $1 -gt 1 ]; then - echo "Players" -else - echo "Player" -fi -} - - - - - -if [ $minecraft -gt 0 ]; then - - A="-Minecraft: $minecraft $(players_function $minecraft)" - if [ $teeworlds -gt 0 ]; then - B="-Teeworlds: $teeworlds $(players_function $teeworlds)" - if [ $urbanterror -gt 0 ]; then - C="-Urbanterror: $urbanterror $(players_function $urbanterror)" - fi - elif [ $urbanterror -gt 0 ]; then - B="-Urbanterror: $urbanterror $(players_function $urbanterror)" - fi - - - -elif [ $teeworlds -gt 0 ]; then - A="-Teeworlds: $teeworlds $(players_function $teeworlds)" - if [ $urbanterror -gt 0 ]; then - B="-Urbanterror: $urbanterror $(players_function $urbanterror)" - fi - - -elif [ $urbanterror -gt 0 ]; then - A="-Urbanterror: $urbanterror $(players_function $urbanterror)" +########################### +##### Generate Banner ##### +########################### +if [ -n "$cmd" ]; then #cmd array not empty -> generating banner + echo "[info] some parameters were generated -> creating banner" + #echo -e "DEBUG: command parameters: \n"${cmd[@]}"" + + #generate image with text according to generated commands + echo -e "=> generating text image..." + convert -background none "${cmd[@]}" +append tmp/text.png + + #merge text image with background + echo -e "=> merging background image with text..." + convert $inputPath tmp/text.png -geometry +$posx+$posy -composite $outputPath + +else #no commands available + #copy default/empty image + echo "[info] no text to show (no players?) -> copying default image" + cp $inputEmpty $outputPath + sleep 1 fi - - - - -#echo "a=$A" -#echo "b=$B" -#echo "c=$C" - - -pos1="text 80,100" -pos2="text 80,150" -pos3="text 80,200" -textcolor="blue" #colorlist: showrgb -undercolor="gray70" #"none" for no color - -if [ "$A" != "null" ] && [ "$B" != "null" ] && [ "$C" != "null" ]; then - #convert -font /usr/share/fonts/OTF/Z003-MediumItalic.otf -pointsize 40 -fill blue -draw "$pos1 \"$A" banner.jpg banner1.jpg - gm convert -undercolor $undercolor -pointsize 40 -fill $textcolor -draw " $pos1 \"$A" /home/teamspeak/dynamic-banner/banner.jpg /home/teamspeak/dynamic-banner/banner1.jpg - gm convert -undercolor $undercolor -pointsize 40 -fill $textcolor -draw " $pos2 \"$B" /home/teamspeak/dynamic-banner/banner1.jpg /home/teamspeak/dynamic-banner/banner2.jpg - gm convert -undercolor $undercolor -pointsize 40 -fill $textcolor -draw " $pos3 \"$C" /home/teamspeak/dynamic-banner/banner2.jpg /home/teamspeak/dynamic-banner/banner3.jpg - #echo 123 -elif [ "$A" != "null" ] && [ "$B" != "null" ]; then - gm convert -undercolor $undercolor -pointsize 40 -fill $textcolor -draw "$pos1 \"$A" /home/teamspeak/dynamic-banner/banner.jpg /home/teamspeak/dynamic-banner/banner1.jpg - gm convert -undercolor $undercolor -pointsize 40 -fill $textcolor -draw "$pos2 \"$B" /home/teamspeak/dynamic-banner/banner1.jpg /home/teamspeak/dynamic-banner/banner3.jpg - #echo 12 -elif [ "$A" != "null" ]; then - gm convert -undercolor $undercolor -pointsize 40 -fill $textcolor -draw "$pos1 \"$A" /home/teamspeak/dynamic-banner/banner.jpg /home/teamspeak/dynamic-banner/banner3.jpg - #echo 1 -else - cp /home/teamspeak/dynamic-banner/banner.jpg /home/teamspeak/dynamic-banner/banner3.jpg -fi - -#convert -background black -fill white \ -#-font Helvetica -pointsize 14 \ -##-border 10 -bordercolor black \ -#label:@- cmd.png - -cp /home/teamspeak/dynamic-banner/banner3.jpg /home/raidworld/www.raidworld.eu/secretfiles/other/banner3.jpg -chmod o+r /home/raidworld/www.raidworld.eu/secretfiles/other/banner3.jpg - - -#convert -pointsize 40 -fill blue -draw "text 100,500 \"-Uptime: $uptime Days" banner.jpg banner1.jpg - -#convert -pointsize 40 -fill green -draw "text 100,550 \"-Minecraft: $minecraft Players" banner1.jpg banner2.jpg - -#convert -pointsize 40 -fill orange -draw "text 100,600 \"-Teeworlds: $teeworlds Players" banner2.jpg banner3.jpg - -#cp banner3.jpg /home/raidworld/www.raidworld.eu/secretfiles -#chmod 777 /home/raidworld/www.raidworld.eu/secretfiles/banner3.jpg -#sleep 1 -#convert -gravity south -fill white -pointsize 30 -annotate 0 'Teeworlds: 6 Players online' banner.jpg banner2.jpg - -#convert test.jpg -gravity south -fill white -pointsize 70 -annotate 0 '2-Gang Riemengetriebe -# ' test1.jpg - -#convert test.jpg -pointsize 100 -comment '2-Gang Getriebe' test2.jpg - -#convert test.jpg -fill white -pointsize 75 -annotate 0 -caption '2-Gang Riemengetriebe' test1.jpg - - -fi - -COMMENT - +#fix permissions for webserver to have access +chmod 666 $outputPath +echo -e "done - $(date)\n" diff --git a/integral-cf_regular.otf b/integral-cf_regular.otf new file mode 100644 index 0000000..55c219a Binary files /dev/null and b/integral-cf_regular.otf differ diff --git a/tmp/.gitignore b/tmp/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/tmp/.gitignore @@ -0,0 +1 @@ +*