From 178253be0ada30420f39720e7e0fa4ee4058bce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sat, 1 Jun 2024 23:00:49 +0200 Subject: razne stvari iz b --- skripti/365_prenesi_omejene_vsebine.sh | 19 ++++-- skripti/completion.bash | 6 ++ skripti/earhorn_m3u.sh | 23 ++++++- skripti/init_script_interpreter.sh | 115 +++++++++++++++++++++++++++++++++ skripti/service.sh | 28 ++++++++ skripti/videonadzor.sh | 10 +-- skripti/zone/axfr.py | 7 +- skripti/zone/update.py | 10 +-- 8 files changed, 199 insertions(+), 19 deletions(-) create mode 100644 skripti/completion.bash create mode 100755 skripti/init_script_interpreter.sh create mode 100755 skripti/service.sh (limited to 'skripti') diff --git a/skripti/365_prenesi_omejene_vsebine.sh b/skripti/365_prenesi_omejene_vsebine.sh index f9a8c69..510b0c1 100755 --- a/skripti/365_prenesi_omejene_vsebine.sh +++ b/skripti/365_prenesi_omejene_vsebine.sh @@ -7,13 +7,24 @@ set -euo pipefail page=`curl --fail-with-body https://365.rtvslo.si/oddaja/dnevnik/92` # outputa preveč shita za set -x set -x -for id in `find -type f -size 7931523c | sed -E 's/^.*\[([0-9]*)\].*$/\1/g'` # repair broken downloads (pravice potekle) -do - yt-dlp --no-continue http://365.rtvslo.si/arhiv/oddaja/$id +find . -size -12M -type f -name '*.mp4' | while read file +do # grep for specific audio codec ... if sample rate is 44100 and (tv broadcast is at 48000) and smaller than 12M, it's most likely the dummy/pravicepotekle video + samplerate=`ffprobe "$file" 2>&1 | grep 0x6134706D | grep -Eo '[0-9]+ Hz' | cut -d\ -f1` + id=`grep -Eo "\[[0-9]+\]\.mp" <<<"$file" | grep -o '[0-9]*'` + if [ $samplerate -eq 48000 ] + then + continue + fi + if [ $samplerate -eq 44100 ] + then + yt-dlp --no-continue http://365.rtvslo.si/arhiv/oddaja/$id # retry fu*ked up downloads + continue + fi + echo -e "Subject: unknown samplerate in 365.sh\n\nVideo file: $file\nsamplerate: $samplerate\n" | sendmail root done rm -f Error\ \[*\].mp4 dnevnik_id=`grep href=./arhiv/dnevnik <<<"$page" | cut -d\" -f2 | cut -d/ -f4 | head -n1` -client_id=`grep client-id <<<"$page" | cut -d\" -f2 | head -n1` +client_id=`grep 'client-id="' <<<"$page" | head -n1 | sed -E 's/^.*client-id="([^"]*)".*$/\1/'` if [ ! -f zadnji ] then echo $dnevnik_id > zadnji diff --git a/skripti/completion.bash b/skripti/completion.bash new file mode 100644 index 0000000..fbe834d --- /dev/null +++ b/skripti/completion.bash @@ -0,0 +1,6 @@ +# completion skript za vse stvari v /skripti/ +_service_sh_complete() { + [ $1 = $3 ] && { COMPREPLY=($(compgen -W "`service.sh list`" $2)); return; } + COMPREPLY=($(compgen -W "`service.sh $3 list`" $2)) +} +complete -F _service_sh_complete service.sh diff --git a/skripti/earhorn_m3u.sh b/skripti/earhorn_m3u.sh index 51f33c7..e89a151 100755 --- a/skripti/earhorn_m3u.sh +++ b/skripti/earhorn_m3u.sh @@ -1,6 +1,19 @@ #!/bin/bash -set -xeo pipefail +set -eo pipefail +# $1 je prefix +# $2 je prejšnji file (za caching dolžin) +# $3=1 forsira cache kljub version failu echo "#EXTM3U" +ver="#earhorn_m3u.sh različica 0" +echo $ver +cache=0 +if [ ! x$3 = x ] || [ ! x$2 = x ] && [ -f $2 ] +then + if [ x"`head -n2 $2 | tail -n1`" = x"$ver" ] + then + cache=1 + fi +fi find 2* -type f | while read file do date=`cut -d/ -f1,2,3 <<<$file | sed s,/,-,g` @@ -8,7 +21,13 @@ do h=${time:0:2} m=${time:2:2} s=${time:4:2} - echo "#EXTINF:`ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $file | cut -d. -f1`,Radijski arhiv" + dol="" + if [ $cache -eq 1 ] + then + grep -B2 ^$1$file$ $2 && continue + fi + dol=`ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $file | cut -d. -f1` + echo "#EXTINF:$dol,Radijski arhiv" echo "#EXT-X-PROGRAM-DATE-TIME:${date}T$h:$m:${s}Z" echo $1$file done diff --git a/skripti/init_script_interpreter.sh b/skripti/init_script_interpreter.sh new file mode 100755 index 0000000..fc461ce --- /dev/null +++ b/skripti/init_script_interpreter.sh @@ -0,0 +1,115 @@ +#!/bin/bash +set -eo pipefail +name=`rev <<<$1 | cut -d/ -f1 | rev` +SVCNAME=$name +pidfile=/run/user/`id -u`/$name.pid +[ -w /run/user/`id -u`/log ] && stdout_logger="logger --socket /run/user/`id -u`/log" || stdout_logger=logger # failback to logging to syslog +stderr_logger=$stdout_logger +[ -r `sed s,/init.d/,/conf.d/, <<<$1` ] && . `sed s,/init.d/,/conf.d/, <<<$1` +. $1 +type eerror > /dev/null 2> /dev/null || eerror() { + echo NAPAKA: $@ +} +type ewarn > /dev/null 2> /dev/null || ewarn() { + echo OPOZORILO: $@ +} +type einfo > /dev/null 2> /dev/null || einfo () { + echo INFO: $@ +} +type ebegin > /dev/null 2> /dev/null || ebegin() { + echo ZAČENJAM: $@ +} +type need_net > /dev/null 2> /dev/null || need_net() { + [ `ip a | grep ^[[:digit:]] | wc -l` -gt 1 ] || { eerror "Ni omrežnih vmesnikov poleg lo." && return 1; } + [ `ip route | wc -l` -gt 1 ] || { eerror "Usmerjevalna tabela je prazna." && return 1; } +} +type need_clock > /dev/null 2> /dev/null || need_clock() { + year=`date +%Y` + [ $? -eq 0 ] || { eerror "Ura ne deluje." && return 1; } + [ $year -ge 2024 ] || { eerror "Ura je narobe nastavljena." && return 1; } +} +type need_hostname > /dev/null 2> /dev/null || need_hostname() { + hn=`hostname` + [ $? -eq 0 ] || { eerror "Ni mogoče pridobiti imena gostitelja." && return 1; } + [ x$hn = x ] && { eerror "Ni imena gostitelja" && return 1; } + [ x$hn = xlocalhost ] && { eerror "Ime gostitelja je localhost." && return 1; } + return 0 +} +needs= +needs_izpolnjen=0 +type need > /dev/null 2> /dev/null || need() { + for i in $@ + do + needs="$needs $i" + need_$i || { eerror "Odvisnost $i ni izpolnjena." && needs_izpolnjen=1; } + done +} +provides= +type provide > /dev/null 2> /dev/null || provide() { + for i in $@ + do + provides="$provides $i" + done +} +type depend > /dev/null 2> /dev/null || depend() { + return +} +type check_dependencies > /dev/null 2> /dev/null || check_dependencies() { + depend + return $needs_izpolnjen +} +type needs > /dev/null 2> /dev/null || needs() { + depend + echo $needs +} +type provides > /dev/null 2> /dev/null || provides() { + depend + echo $provides +} +type checkconfig > /dev/null 2> /dev/null || checkconfig() { + return +} +type start > /dev/null 2> /dev/null || start() { + checkconfig || { eerror "Checkconfig ni uspel." && return 1; }; + check_dependencies || { eerror "Odvisnosti niso izpolnjene."; return 1; } + ebegin "Zaganjam $SVCNAME" + start-stop-daemon --start --verbose `[ x$command_background = true ] || echo --background --make-pidfile` `[ x$chdir = x ] || echo --chdir $chdir` --stdout-logger "$stdout_logger" --stderr-logger "$stderr_logger" --exec $command --pidfile $pidfile -- $command_args || { eerror "start-stop-daemon ni uspel. Koda napake: $?"; return 1; } +} +type stop > /dev/null 2> /dev/null || stop() { + ebegin "Ustavljam $SVCNAME" + start-stop-daemon --stop --pidfile $pidfile --verbose --exec $command -- $command_args || { eerror "start-stop-daemon ni uspel. Koda napake: $?"; return 1; } +} +type restart > /dev/null 2> /dev/null || restart() { + checkconfig || { eerror "Checkconfig ni uspel." && return 1; }; + stop || ewarn "Stop ni uspel. Vseeno poskušam zagnati storitev." + start || { eerror "Start ni uspel." && return 1; } +} +type reload > /dev/null 2> /dev/null || reload() { + checkconfig || { eerror "Checkconfig ni uspel." && return 1; }; + ebegin "Pošiljam SIGHUP storitvi $SVCNAME" + start-stop-daemon --signal HUP $start_stop_daemon_args +} +type status > /dev/null 2> /dev/null || status() { + if [ -r $pidfile ] + then + if [ -d /proc/`cat $pidfile` ] + then + einfo started + else + einfo crashed + return 3 + fi + else + einfo stopped + return 3 + fi +} +type list > /dev/null 2> /dev/null || list() { + echo start stop restart $extra_commands $extra_started_commands $extra_stopped_commands status reload list check_dependencies needs provides +} +if type $2 > /dev/null 2> /dev/null +then + ${@:2} +else + eerror "Ta ukaz ne obstaja!" +fi diff --git a/skripti/service.sh b/skripti/service.sh new file mode 100755 index 0000000..2617253 --- /dev/null +++ b/skripti/service.sh @@ -0,0 +1,28 @@ +#!/bin/bash +[ x$INITPATH = x ] && for i in `tr : ' ' <<<$MORE_INITPATH` `tr : ' ' <<<$XDG_CONFIG_DIRS` ~/.config ~ /etc +do + [ -d $i/init.d ] && INITPATH=$INITPATH:$i/init.d +done +if [ x$1 = xlist ] +then + for i in `tr : ' ' <<<$INITPATH` + do + if [ -w $i ] + then + ls $i + else + for j in $i/* + do + [ ! -x $j ] && continue + head -n1 $j | grep "#!.*openrc-run" > /dev/null 2> /dev/null && continue + echo `rev <<<$j | cut -f/ -d1 | rev` + done + fi + done + exit 1 +fi +[ x$1 = x ] && { echo -e "Uporaba:\n\t$0 list\n\t$0 "; exit 1; } +for i in `tr : ' ' <<<$INITPATH` +do + [ -x $i/$1 ] && exec $i/$@ +done diff --git a/skripti/videonadzor.sh b/skripti/videonadzor.sh index 3e6fa51..e097c58 100755 --- a/skripti/videonadzor.sh +++ b/skripti/videonadzor.sh @@ -22,7 +22,7 @@ do do if [ $prev = devica ] then - first=$i + first=`rev <<<"$i" | cut -d. -f2- | rev` prev=$i continue fi @@ -36,7 +36,7 @@ do prev=$i done { - ffmpeg -f concat -safe 0 -i concat.txt -fps_mode vfr file:$first.mkv + ffmpeg -f concat -safe 0 -i concat.txt -vsync vfr file:$first.mkv if [ -s $first.mkv ] then while read line @@ -44,8 +44,8 @@ do grep ^file <<<$line > /dev/null && rm `cut -d: -f2- <<<$line | cut -d\' -f1` done < concat.txt fi - oldstart=`ls --sort=time | grep mkv$ | tail -f1 | cut -d: -f1` - if [ ! $oldstart = `cut -d: -f1` <<<"$t" ] + oldstart=`ls --sort=time | grep mkv$ | tail -n1 | cut -d: -f1` + if [ ! $oldstart = `cut -d: -f1 <<<"$t"` ] then echo "ffconcat version 1.0" > concat.txt prev=devica @@ -63,7 +63,7 @@ do fi prev=$i done - ffmpeg -f concat -safe 0 -i concat.txt -fps_mode vfr file:$oldstart.mp4 + ffmpeg -f concat -safe 0 -i concat.txt -vsync vfr file:$oldstart.mp4 if [ -s $oldstart.mp4 ] then while read line diff --git a/skripti/zone/axfr.py b/skripti/zone/axfr.py index fe508f1..11eaad9 100755 --- a/skripti/zone/axfr.py +++ b/skripti/zone/axfr.py @@ -20,8 +20,8 @@ for naslov in naslovi: # opcijsko dodaj tule kakšen try catch break config = None try: - config = json.loads(b''.join(dns.resolver.resolve("_urejevalnik." + domena, "TXT")[0].strings).decode()) -except dns.resolver.NXDOMAIN: + config = json.loads(b''.join(zone["_urejevalnik"].get_rdataset(dns.rdataclass.IN, dns.rdatatype.TXT)[0].strings).decode()) +except KeyError: pass except json.decoder.JSONDecodeError: pass @@ -53,7 +53,8 @@ for r in zone.iterate_rdatas(): konec = config["i"][r[0].to_unicode()] print(r[0].to_unicode(), end=konec) if r[1] != config["t"]: - print(r[1], end="\t") + print(r[1], end="") + print("\t", end="") if r[2].rdclass != dns.rdataclass.IN: print(r[2].rdataclass.name, end="\t") print(r[2].rdtype.name, end="\t") diff --git a/skripti/zone/update.py b/skripti/zone/update.py index 34a4e39..ead2c39 100755 --- a/skripti/zone/update.py +++ b/skripti/zone/update.py @@ -24,8 +24,8 @@ for naslov in naslovi: # opcijsko dodaj tule kakšen try catch break config = None try: - config = json.loads(b''.join(dns.resolver.resolve("_urejevalnik." + domena, "TXT")[0].strings).decode()) -except dns.resolver.NXDOMAIN: + config = json.loads(b''.join(zone["_urejevalnik"].get_rdataset(dns.rdataclass.IN, dns.rdatatype.TXT)[0].strings).decode()) +except KeyError: pass except json.decoder.JSONDecodeError: pass @@ -61,7 +61,7 @@ for r in zone.iterate_rdatas(): vrednost = '"' + niz + '"' else: vrednost = r[2].to_text() - rrs.append((r[1], r[0].to_unicode(), komentar, konec, r[2].rdclass, r[2].rdtype, vrednost)) + rrs.append((r[1], r[0].to_unicode(), komentar, None, r[2].rdclass, r[2].rdtype, vrednost)) komentar = "" lineno = 1 novikomentarji = {} @@ -118,7 +118,7 @@ while True: except dns.rdatatype.UnknownRdatatype: pass if tip == None: - print(f"NAPAKA: na vrstici {lineno} ne najdem tipa zapisa. Vrstica je lahko bodisi komentar, ki se začne z ';', bodisi je v obliki IME [TTL={newconfig["t"]}] [CLASS=IN] TIP PODATKI.") + print(f"NAPAKA: na vrstici {lineno} ne najdem tipa zapisa. Vrstica je lahko bodisi komentar, ki se začne z ';', bodisi je v obliki IME [TTL={newconfig['t']}] [CLASS=IN] TIP PODATKI.") print(f"Vsebina neveljavne vrstice: " + line) sys.exit(1) while line[datastart] in [" ", "\t"]: @@ -133,7 +133,7 @@ while True: data = data.split() data[2] = str(int(data[2])+newconfig["+"]) data = " ".join(data) - tapl = (ttl, ime, komentar, konec, razred, tip, data) + tapl = (ttl, ime, komentar, None, razred, tip, data) if komentar != "": novikomentarji[ime + " " + tip.to_text(tip)] = komentar if konec != "\t": -- cgit v1.2.3