l radio: use jc instead of sed/grep

This commit is contained in:
lassulus 2022-05-22 20:51:14 +02:00
parent 5befc5a6f2
commit 3b46460fe9
2 changed files with 17 additions and 15 deletions

View File

@ -372,15 +372,13 @@ in {
locations."= /good".extraConfig = '' locations."= /good".extraConfig = ''
proxy_pass http://localhost:8001; proxy_pass http://localhost:8001;
''; '';
locations."= /radio.sh".extraConfig = '' locations."= /radio.sh".alias = pkgs.writeScript "radio.sh" ''
alias ${pkgs.writeScript "radio.sh" '' #!/bin/sh
#!/bin/sh while sleep 1; do
while sleep 1; do mpv \
mpv \ --cache-secs=0 --demuxer-readahead-secs=0 --untimed --cache-pause=no \
--cache-secs=0 --demuxer-readahead-secs=0 --untimed --cache-pause=no \ 'http://lassul.us:8000/radio.opus'
'http://lassul.us:8000/radio.opus' done
done
''};
''; '';
locations."= /controls".extraConfig = '' locations."= /controls".extraConfig = ''
default_type "text/html"; default_type "text/html";

View File

@ -7,18 +7,22 @@ let
weather_report = pkgs.writers.writeDashBin "weather_report" '' weather_report = pkgs.writers.writeDashBin "weather_report" ''
set -efu set -efu
export PATH="${lib.makeBinPath [ export PATH="${lib.makeBinPath [
pkgs.iproute2
pkgs.coreutils pkgs.coreutils
pkgs.curl pkgs.curl
pkgs.gnugrep pkgs.iproute2
pkgs.gnused pkgs.jc
pkgs.jq
]}" ]}"
curl -z /tmp/GeoLite2-City.mmdb -o /tmp/GeoLite2-City.mmdb http://c.r/GeoLite2-City.mmdb curl -z /tmp/GeoLite2-City.mmdb -o /tmp/GeoLite2-City.mmdb http://c.r/GeoLite2-City.mmdb
MAXMIND_GEOIP_DB="/tmp/GeoLite2-City.mmdb"; export MAXMIND_GEOIP_DB MAXMIND_GEOIP_DB="/tmp/GeoLite2-City.mmdb"; export MAXMIND_GEOIP_DB
OPENWEATHER_API_KEY=$(cat "$CREDENTIALS_DIRECTORY/openweather_api"); export OPENWEATHER_API_KEY OPENWEATHER_API_KEY=$(cat "$CREDENTIALS_DIRECTORY/openweather_api"); export OPENWEATHER_API_KEY
ss -Hno state established 'sport = :8000' | ss -no 'sport = :8000' |
grep '^tcp' | sed 's/.*\[.*\].*\[\(::ffff:\)\{0,1\}\(.*\)\].*/\2/' | jc --ss | jq -r '.[] |
sed '/127.0.0.1/d;/::1/d' | select(
.local_address != "[::ffff:127.0.0.1]"
and .local_address != "[::1]"
) | .peer_address | gsub("[\\[\\]]"; "")
' |
${weather_for_ips}/bin/weather_for_ips ${weather_for_ips}/bin/weather_for_ips
''; '';